Mihaly Szjatinya has uploaded a new patch set (#4). ( http://gerrit.cloudera.org:8080/24889 )
Change subject: IMPALA-15106: Support missing types with theta sketches ...................................................................... IMPALA-15106: Support missing types with theta sketches ds_theta_sketch() and ds_theta_sketch_and_estimate() previously only accepted TINYINT, INT, BIGINT, FLOAT, DOUBLE, and STRING. This patch extends support to all types for which COMPUTE STATS computes NDV, in preparation for IMPALA-15004 (writing theta sketch NDV stats to Puffin files from COMPUTE STATS). Gap analysis (before this patch): Type | C++ impl | FE symbol| Notes ----------+----------+----------+------------------------------------ BOOLEAN | yes | no | needs FE wiring only TINYINT | yes | yes | already done SMALLINT | yes | no | needs FE wiring only INT | yes | yes | already done BIGINT | yes | yes | already done FLOAT | yes | yes | already done DOUBLE | yes | yes | already done STRING | yes | yes | already done DATE | yes | no | needs FE wiring only TIMESTAMP | no | no | needs C++ impl (8-byte LE micros) DECIMAL | no | no | needs C++ impl (BE two's-complement) Note on how values are hashed: the integer and floating point types are fed to the DataSketches typed update() overloads, which widen them before hashing - TINYINT/SMALLINT/INT become an 8-byte int64 and FLOAT becomes an 8-byte double. This differs from what Iceberg prescribes in Appendix D (int and float are 4 bytes, boolean is 1 byte). Widening is the better behaviour for a general purpose SQL function, as it makes the value 1 hash identically whether it is a TINYINT or a BIGINT. The TIMESTAMP and DECIMAL specialisations added here happen to match Appendix D. IMPALA-15459 adds a separate, internal flavour that encodes every type exactly as Iceberg prescribes, for writing Puffin NDV blobs. Changes: - BOOLEAN, SMALLINT, DATE: C++ template instantiations already existed; added the corresponding entries to DS_THETA_UPDATE_SYMBOL in BuiltinsDb.java so the FE registers these overloads. - TIMESTAMP: Added DsThetaUpdate<TimestampVal> specialisation that converts the value to microseconds since epoch via TimestampValue::FloorUtcToUnixTimeMicros(), matching the Iceberg single-value serialization encoding (Appendix D). This is the only conversion here that is lossy: two timestamps that differ only in their nanosecond part are floored to the same microsecond value and therefore counted as a single distinct value. This does not affect Iceberg, whose timestamp type only has microsecond precision. - DECIMAL: Added DsThetaUpdate<DecimalVal> specialisation that encodes the unscaled integer as big-endian two's-complement minimum bytes, matching the Iceberg single-value serialization encoding (Appendix D). Handles all three backing types (val4/val8/val16) based on precision from the FunctionContext arg type. NOTE: TINYINT and SMALLINT have no Iceberg equivalent (Iceberg's narrowest integer is int); but we still want to support it for plain ds_data_sketches(). Tests: - datasketches-theta.test: removed 8 AnalysisException CATCH blocks for the newly supported types; expanded the main positive queries to include BOOLEAN, SMALLINT, and TIMESTAMP; added separate DATE tests against functional_parquet.date_tbl and DECIMAL tests against functional_parquet.decimal_tbl covering all three decimal backing types (decimal4, decimal8 and decimal16, including the maximum precision and scale). - aggregate-functions-test.cc: added DsThetaSketch.DataToSketchTimestamp unit test covering empty input, distinct values, duplicates, NULLs, timestamps before the epoch, and sub-microsecond values that are floored to the same microsecond (both before and after the epoch). Assisted-by: Claude Opus 4.8 (GitHub Copilot) Change-Id: I549a51ba96d0b9be2052a9350efe2096c1755816 --- 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/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 6 files changed, 218 insertions(+), 53 deletions(-) git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/89/24889/4 -- To view, visit http://gerrit.cloudera.org:8080/24889 To unsubscribe, visit http://gerrit.cloudera.org:8080/settings Gerrit-Project: Impala-ASF Gerrit-Branch: master Gerrit-MessageType: newpatchset Gerrit-Change-Id: I549a51ba96d0b9be2052a9350efe2096c1755816 Gerrit-Change-Number: 24889 Gerrit-PatchSet: 4 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]>
