MCPcopy Create free account
hub / github.com/apache/arrow / test_make_parquet_fragment_from_buffer

Function test_make_parquet_fragment_from_buffer

python/pyarrow/tests/test_dataset.py:1344–1386  ·  view source on GitHub ↗
(dataset_reader, pickle_module)

Source from the content-addressed store, hash-verified

1342
1343@pytest.mark.parquet
1344def test_make_parquet_fragment_from_buffer(dataset_reader, pickle_module):
1345 arrays = [
1346 pa.array(['a', 'b', 'c']),
1347 pa.array([12, 11, 10]),
1348 pa.array(['dog', 'cat', 'rabbit'])
1349 ]
1350 dictionary_arrays = [
1351 arrays[0].dictionary_encode(),
1352 arrays[1],
1353 arrays[2].dictionary_encode()
1354 ]
1355 dictionary_format = ds.ParquetFileFormat(
1356 read_options=ds.ParquetReadOptions(
1357 dictionary_columns=['alpha', 'animal']
1358 ),
1359 use_buffered_stream=True,
1360 buffer_size=4096,
1361 )
1362
1363 cases = [
1364 (arrays, ds.ParquetFileFormat()),
1365 (dictionary_arrays, dictionary_format)
1366 ]
1367 for arrays, format_ in cases:
1368 table = pa.table(arrays, names=['alpha', 'num', 'animal'])
1369
1370 out = pa.BufferOutputStream()
1371 pq.write_table(table, out)
1372 buffer = out.getvalue()
1373
1374 fragment = format_.make_fragment(buffer)
1375 assert dataset_reader.to_table(fragment).equals(table)
1376
1377 pickled = pickle_module.loads(pickle_module.dumps(fragment))
1378 assert dataset_reader.to_table(pickled).equals(table)
1379
1380 # GH-47301: Ensure fragment.open() works for file-like objects.
1381 file_like = pa.BufferReader(buffer)
1382 fragment = format_.make_fragment(file_like)
1383 opened_file = fragment.open()
1384 assert isinstance(opened_file, pa.NativeFile)
1385 assert opened_file.readable
1386 assert pq.ParquetFile(fragment.open()).read().equals(table)
1387
1388
1389@pytest.mark.parquet

Callers

nothing calls this directly

Calls 11

ParquetFileFormatMethod · 0.80
BufferOutputStreamMethod · 0.80
equalsMethod · 0.80
loadsMethod · 0.80
dumpsMethod · 0.80
BufferReaderMethod · 0.80
arrayMethod · 0.45
write_tableMethod · 0.45
to_tableMethod · 0.45
openMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected