pitrou commented on code in PR #52580:
URL: https://github.com/apache/arrow/pull/52580#discussion_r4379797276


##########
cpp/src/parquet/properties.h:
##########
@@ -933,6 +949,7 @@ class PARQUET_EXPORT WriterProperties {
     int64_t max_rows_per_page_;
     ParquetVersion::type version_;
     ParquetDataPageVersion data_page_version_;
+    std::optional<double> min_space_savings_ = {};

Review Comment:
   Should this just be a `double` and default to 0.0? (which is the current 
behavior)



##########
python/pyarrow/tests/test_dataset.py:
##########
@@ -5949,6 +5949,47 @@ def test_write_dataset_content_defined_chunking(tempdir, 
cdc):
     assert ds.dataset(tempdir, format=fmt).to_table().equals(expected_table)
 
 
[email protected]
[email protected]("minimum", [None, 0.0, 0.1, 1.0])
+def test_parquet_min_space_savings(tempdir, minimum):
+    import pyarrow.parquet as pq
+
+    table = pa.table({
+        "value": pa.array([0.0] * 1000, type=pa.float32())
+    })
+    pq.write_to_dataset(
+        table,
+        tempdir,
+        compression="snappy",
+        use_dictionary=False,
+        data_page_version="2.0",
+        min_space_savings=minimum,
+    )
+
+    result = ds.dataset(tempdir, format="parquet").to_table()
+    assert result.equals(table)
+
+
[email protected]
+def test_dataset_min_space_savings_changes_size(tempdir):

Review Comment:
   Can we merge those two tests together?



##########
cpp/src/parquet/properties.h:
##########
@@ -529,6 +530,18 @@ class PARQUET_EXPORT WriterProperties {
       return this;
     }
 
+    /// Used to set minimum compression ratio threshold for V2 page data values
+    /// compression. If min_space_savings unset, keep compression if 
compressed value is
+    /// smaller.
+    Builder* min_space_savings(std::optional<double> min_space_savings) {

Review Comment:
   Naming nit: call this `min_compression_savings`? We could envision other 
encoding-related parameters...



##########
python/pyarrow/tests/parquet/test_parquet_writer.py:
##########
@@ -41,6 +43,106 @@
 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
+
+
+def _v2_column_chunk(table, **options):

Review Comment:
   This seems to be testing behavior that's already tested in the C++ unit test 
suite, is it useful to replicate the tests in Python?
   
   We should be merely testing that the plumbing is correct, and 
`test_min_space_savings` above appears sufficient for that.



-- 
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]

Reply via email to