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

Function test_make_fragment_with_size

python/pyarrow/tests/test_dataset.py:1234–1287  ·  view source on GitHub ↗

Test passing file_size to make_fragment. Not all FS implementations make use of the file size (by implementing an OpenInputFile that takes a FileInfo), but s3 does, which is why it's used here.

(s3_example_simple)

Source from the content-addressed store, hash-verified

1232@pytest.mark.parquet
1233@pytest.mark.s3
1234def test_make_fragment_with_size(s3_example_simple):
1235 """
1236 Test passing file_size to make_fragment. Not all FS implementations make use
1237 of the file size (by implementing an OpenInputFile that takes a FileInfo), but
1238 s3 does, which is why it's used here.
1239 """
1240 table, path, fs, uri, host, port, access_key, secret_key = s3_example_simple
1241
1242 file_format = ds.ParquetFileFormat()
1243 paths = [path]
1244
1245 fragments = [file_format.make_fragment(path, fs)
1246 for path in paths]
1247 dataset = ds.FileSystemDataset(
1248 fragments, format=file_format, schema=table.schema, filesystem=fs
1249 )
1250
1251 tbl = dataset.to_table()
1252 assert tbl.equals(table)
1253
1254 # true sizes -> works
1255 sizes_true = [dataset.filesystem.get_file_info(x).size for x in dataset.files]
1256 fragments_with_size = [file_format.make_fragment(path, fs, file_size=size)
1257 for path, size in zip(paths, sizes_true)]
1258 dataset_with_size = ds.FileSystemDataset(
1259 fragments_with_size, format=file_format, schema=table.schema, filesystem=fs
1260 )
1261 tbl = dataset.to_table()
1262 assert tbl.equals(table)
1263
1264 # too small sizes -> error
1265 sizes_toosmall = [1 for path in paths]
1266 fragments_with_size = [file_format.make_fragment(path, fs, file_size=size)
1267 for path, size in zip(paths, sizes_toosmall)]
1268
1269 dataset_with_size = ds.FileSystemDataset(
1270 fragments_with_size, format=file_format, schema=table.schema, filesystem=fs
1271 )
1272
1273 with pytest.raises(pyarrow.lib.ArrowInvalid, match='Parquet file size is 1 bytes'):
1274 table = dataset_with_size.to_table()
1275
1276 # too large sizes -> error
1277 sizes_toolarge = [1000000 for path in paths]
1278 fragments_with_size = [file_format.make_fragment(path, fs, file_size=size)
1279 for path, size in zip(paths, sizes_toolarge)]
1280
1281 dataset_with_size = ds.FileSystemDataset(
1282 fragments_with_size, format=file_format, schema=table.schema, filesystem=fs
1283 )
1284
1285 # invalid range
1286 with pytest.raises(OSError, match='HTTP status 416'):
1287 table = dataset_with_size.to_table()
1288
1289
1290def test_make_csv_fragment_from_buffer(dataset_reader, pickle_module):

Callers

nothing calls this directly

Calls 4

ParquetFileFormatMethod · 0.80
equalsMethod · 0.80
to_tableMethod · 0.45
get_file_infoMethod · 0.45

Tested by

no test coverage detected