Hello Peter Rozsa, Csaba Ringhofer, Impala Public Jenkins,

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

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

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

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() only accept
TINYINT, INT, BIGINT, FLOAT, DOUBLE and STRING. This patch extends them
to BOOLEAN, SMALLINT, DATE, TIMESTAMP and DECIMAL, i.e. to all types
for which COMPUTE STATS computes NDV.

This came up while adding the internal ds_theta_sketch_iceberg()
flavor for Puffin NDV stats (IMPALA-15459), which already supports
every Iceberg column type. It is not needed for Puffin stats, and is
implemented in case the user-facing functions need these types later.

Compatibility caveats - the reasons this is not merged together with
IMPALA-15459:
- None of the new types is supported by Hive's ds_theta_sketch(), so
  there are no Hive sketches to be byte-compatible with. Hive does not
  use theta sketches for statistics (its column stats are HLL), and its
  theta UDF is a standalone utility. If Hive adds these types later, it
  may encode them differently.
- BOOLEAN and DATE are encoded differently than in the Iceberg flavor:
  see below.
- TIMESTAMP is lossy: values are floored to microseconds, so two
  timestamps that differ only below the microsecond are counted as one.
- All of these can be emulated with casts to already supported types.

How values are hashed: the integer and floating point types are fed to
the DataSketches typed update() overloads, which widen them before
hashing - BOOLEAN/TINYINT/SMALLINT/INT/DATE become an 8-byte int64 and
FLOAT becomes an 8-byte double. This differs from Iceberg Appendix D
(int, date and float are 4 bytes, boolean is 1 byte), but it 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. TIMESTAMP
and DECIMAL have no such widened encoding, so they reuse the Appendix D
encoding of ds_theta_sketch_iceberg().

  Type      | ds_theta_sketch()       | ds_theta_sketch_iceberg()
  ----------+-------------------------+--------------------------
  BOOLEAN   | widened to 8 bytes (new)| 1 byte
  SMALLINT  | widened to 8 bytes (new)| n/a (cast to INT)
  DATE      | widened to 8 bytes (new)| 4-byte LE day count
  TIMESTAMP | 8-byte LE micros (new)  | same
  DECIMAL   | BE minimum bytes (new)  | same

Changes:
- FE: added BOOLEAN, SMALLINT and DATE to DS_THETA_UPDATE_SYMBOL in
  BuiltinsDb.java using the existing DsThetaUpdate template
  instantiations, and TIMESTAMP and DECIMAL using the
  DsThetaUpdateIceberg specialisations. No BE changes are needed.

Testing:
- datasketches-theta.test: replaced the unsupported-type errors with
  distinct counts for the new types, and compared them with
  ds_theta_sketch_iceberg().

Regression:
- test_datasketches.py::TestDatasketches::test_theta: existing
  ds_theta_sketch() types and Hive-written sketches.
- aggregate-functions-test.cc DsThetaSketch.*: theta UDA lifecycle,
  including the shared TIMESTAMP conversion.

Assisted-by: Claude Opus 4.8 (GitHub Copilot)
Change-Id: I549a51ba96d0b9be2052a9350efe2096c1755816
---
M be/src/exprs/aggregate-functions.h
M fe/src/main/java/org/apache/impala/catalog/BuiltinsDb.java
M testdata/workloads/functional-query/queries/QueryTest/datasketches-theta.test
3 files changed, 105 insertions(+), 44 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/89/24889/6
--
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: 6
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