Hello Peter Rozsa, Csaba Ringhofer, Impala Public Jenkins,

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/24982

to look at the new patch set (#5).

Change subject: IMPALA-15459: Add Iceberg-encoded theta sketch flavor for 
Puffin NDV stats
......................................................................

IMPALA-15459: Add Iceberg-encoded theta sketch flavor for Puffin NDV stats

COMPUTE STATS will write column NDV statistics as Iceberg Puffin
apache-datasketches-theta-v1 blobs (IMPALA-15004). For cross-engine
interop (Trino, Spark) each value must be hashed into the sketch using
Iceberg Appendix D single-value serialization.

Impala's ds_theta_sketch() hashes values via the DataSketches typed
update() overloads, which widen INT to an 8-byte integer and FLOAT to a
double. This matches Hive's datasketches UDF but not the Iceberg Puffin
spec. ds_theta_sketch() also does not support BOOLEAN, DATE, TIMESTAMP
and DECIMAL, so it cannot be used for those column types at all.

This patch adds an undocumented aggregate flavor,
ds_theta_sketch_iceberg(), that hashes every Iceberg column type
Impala computes NDV for with the Appendix D encoding. COMPUTE STATS
(IMPALA-15004) uses it when writing Puffin NDV blobs. The user-facing
ds_theta_sketch() is unchanged.

  Type      | ds_theta_sketch()     | ds_theta_sketch_iceberg()
  ----------+-----------------------+---------------------------
  BOOLEAN   | not supported         | 1 byte
  INT       | widened to 8 bytes    | 4-byte LE
  BIGINT    | 8-byte LE             | 8-byte LE (same symbol)
  FLOAT     | widened to double     | 4-byte LE
  DOUBLE    | 8-byte LE             | 8-byte LE (same symbol)
  STRING    | raw bytes             | raw bytes (same symbol)
  DATE      | not supported         | 4-byte LE day count
  TIMESTAMP | not supported         | 8-byte LE micros since epoch
  DECIMAL   | not supported         | unscaled, BE two's-complement,
            |                       | minimum bytes

TINYINT and SMALLINT are not registered for ds_theta_sketch_iceberg(),
as Iceberg has no such column types; such values are implicitly cast to
INT and get its encoding.

TIMESTAMP is the only lossy conversion: Impala timestamps have
nanosecond precision and are floored to microseconds, so two timestamps
that differ only below the microsecond are counted as one value. This
does not affect Iceberg, whose timestamp type has microsecond precision.

Changes:
- BE: added AggregateFunctions::DsThetaUpdateIceberg<T> with Appendix D
  specialisations for BOOLEAN, INT, FLOAT, DATE, TIMESTAMP and DECIMAL,
  sharing a DsThetaUpdateRaw() helper. DECIMAL handles all three backing
  types (val4/val8/val16) based on the precision of the argument type.
- BE: extracted the minimal two's-complement trimming from
  ColumnStats<DecimalValue>::SerializeIcebergSingleValue (Parquet
  Iceberg stats) into BitUtil::TrimSignExtension() and reused it for
  DECIMAL.
- FE: registered ds_theta_sketch_iceberg() in BuiltinsDb.java via a
  new DS_THETA_ICEBERG_UPDATE_SYMBOL map; BIGINT, DOUBLE and STRING
  reuse the ds_theta_sketch() update symbols.

Testing:
- datasketches-theta.test: distinct counts and exact-byte checks
  against the expected Appendix D encoding for every supported type,
  and a comparison with ds_theta_sketch().
- aggregate-functions-test.cc:
  DsThetaSketch.IcebergDataToSketchTimestamp for the TIMESTAMP
  conversion, including pre-epoch and sub-microsecond values.

Regression:
- test_datasketches.py::TestDatasketches::test_theta: existing
  ds_theta_sketch() behaviour, including Hive-written sketches.
- aggregate-functions-test.cc DsThetaSketch.*: theta UDA lifecycle.
- serialize-single-value-test.cc: Parquet Iceberg single-value
  serialization, refactored to use BitUtil::TrimSignExtension().
- bit-util-test.cc: BitUtil helpers.

Assisted-by: Claude Opus 4.8 (GitHub Copilot)
Change-Id: I78c76c38dffa9807eb13ad465afab0b80f31984a
---
M be/src/exec/parquet/parquet-column-stats.inline.h
M be/src/exprs/aggregate-functions-ir.cc
M be/src/exprs/aggregate-functions-test.cc
M be/src/exprs/aggregate-functions.h
M be/src/util/bit-util.h
M fe/src/main/java/org/apache/impala/catalog/BuiltinsDb.java
M testdata/workloads/functional-query/queries/QueryTest/datasketches-theta.test
7 files changed, 405 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/82/24982/5
--
To view, visit http://gerrit.cloudera.org:8080/24982
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I78c76c38dffa9807eb13ad465afab0b80f31984a
Gerrit-Change-Number: 24982
Gerrit-PatchSet: 5
Gerrit-Owner: Mihaly Szjatinya <[email protected]>
Gerrit-Reviewer: Csaba Ringhofer <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Mihaly Szjatinya <[email protected]>
Gerrit-Reviewer: Peter Rozsa <[email protected]>

Reply via email to