()
| 83 | |
| 84 | @require_pyarrow |
| 85 | def 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 | |
| 116 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected