MCPcopy Create free account
hub / github.com/apache/fory / test_vectorized_map

Function test_vectorized_map

python/pyfory/format/tests/test_vectorized.py:85–113  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

83
84@require_pyarrow
85def test_vectorized_map():
86 cls = fory.record_class_factory("TEST_VECTORIZED_MAP", ["f0"])
87 # Create Fory schema for the encoder
88 fory_schema = schema(
89 [
90 field("f0", map_(utf8(), int32())),
91 ]
92 )
93 # Convert to Arrow schema for ArrowWriter
94 arrow_schema = to_arrow_schema(fory_schema)
95 # Add metadata for class resolution
96 arrow_schema = arrow_schema.with_metadata({"cls": fory.get_qualified_classname(cls)})
97 print(arrow_schema)
98
99 writer = fory.format.ArrowWriter(arrow_schema)
100 encoder = fory.create_row_encoder(fory_schema)
101 num_rows = 5
102 data = []
103 for i in range(num_rows):
104 map_data = {"k1": 1, "k2": 2}
105 data.append(list(map_data.items()))
106 obj = cls(f0=map_data)
107 row = encoder.to_row(obj)
108 writer.write(row)
109 record_batch = writer.finish()
110 print(f"record_batch {record_batch}")
111 data = [pa.array(data, type=arrow_schema[0].type)]
112 batch1 = pa.RecordBatch.from_arrays(data, ["f0"])
113 assert batch1 == record_batch
114
115
116if __name__ == "__main__":

Callers

nothing calls this directly

Calls 13

writeMethod · 0.95
finishMethod · 0.95
to_arrow_schemaFunction · 0.90
schemaFunction · 0.85
utf8Function · 0.85
ArrowWriterMethod · 0.80
itemsMethod · 0.80
fieldFunction · 0.50
int32Function · 0.50
listFunction · 0.50
appendMethod · 0.45
to_rowMethod · 0.45

Tested by

no test coverage detected