rok commented on code in PR #52580: URL: https://github.com/apache/arrow/pull/52580#discussion_r4359344813
########## python/pyarrow/tests/parquet/test_parquet_writer.py: ########## @@ -41,6 +41,82 @@ pytestmark = pytest.mark.parquet [email protected]("page_version, minimum", [ + ("1.0", None), + ("2.0", None), + ("2.0", 0.0), + ("2.0", 0.1), + ("2.0", 1.0), +]) [email protected]("compression", ["none", "snappy"]) [email protected]("use_writer", [False, True]) +def test_min_space_savings( + minimum, page_version, compression, use_writer): + table = pa.table({ + "value": pa.array([0.0] * 1000, type=pa.float32()) + }) + sink = pa.BufferOutputStream() + options = dict( + compression=compression, + use_dictionary=False, + data_page_version=page_version, + min_space_savings=minimum, + ) + + if use_writer: + with pq.ParquetWriter(sink, table.schema, **options) as writer: + writer.write_table(table) + else: + pq.write_table(table, sink, **options) + + buf = sink.getvalue() + assert pq.read_table(buf).equals(table) + + column = pq.ParquetFile(buf).metadata.row_group(0).column(0) + expect_uncompressed = ( + compression == "none" + or (page_version == "2.0" and minimum == 1.0) + ) + if expect_uncompressed: + assert column.total_compressed_size == column.total_uncompressed_size + else: + assert column.total_compressed_size < column.total_uncompressed_size + + Review Comment: How about a threshold test too? Note this requires adding a random import. ```suggestion def _v2_column_chunk(table, **options): sink = pa.BufferOutputStream() pq.write_table(table, sink, compression="snappy", use_dictionary=False, data_page_version="2.0", **options) return pq.ParquetFile(sink.getvalue()).metadata.row_group(0).column(0) def test_min_space_savings_threshold(): rng = random.Random(42) values = [rng.randrange(16) for _ in range(1000)] table = pa.table({"v": pa.array(values, pa.int32())}) base = _v2_column_chunk(table) savings = 1 - base.total_compressed_size / base.total_uncompressed_size assert 0.1 < savings < 0.9 kept = _v2_column_chunk(table, min_space_savings=savings - 0.05) assert kept.total_compressed_size == base.total_compressed_size dropped = _v2_column_chunk(table, min_space_savings=savings + 0.05) assert dropped.total_compressed_size == dropped.total_uncompressed_size assert dropped.compression == "SNAPPY" ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
