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