[
https://issues.apache.org/jira/browse/IMPALA-9821?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18118985#comment-18118985
]
ASF subversion and git services commented on IMPALA-9821:
---------------------------------------------------------
Commit 6a8a5a52ba77b644e4b8a25f38c4c0a30217431b in impala's branch
refs/heads/master from Mihaly Szjatinya
[ https://gitbox.apache.org/repos/asf?p=impala.git;h=6a8a5a52b ]
IMPALA-9821: Change DataSketches functions to return BINARY
DataSketches functions were added before BINARY type support
(IMPALA-9482), leading to the current STRING based solution, which is
incompatible with other systems (like Hive). After adding BINARY, the
changing of signatures (IMPALA-9821) was delayed, waiting for a major
version, because it is not a backward compatible. Now it is added in
preparation for Impala 5.0.
When Hive writes DataSketches to ORC tables, it correctly stores them as
BINARY. Impala's ds_*_sketch() functions, however, historically returned
STRING when reading Hive-created ORC tables, thus causing a type
mismatch error — the original issue in the Jira description, which was
solved by IMPALA-9482 without adding an explicit test for that exact
scenario. 'datasketches-hll-hive-orc.test' adds a regression test for
that.
After IMPALA-9482 fixed the ORC scanner to accept BINARY columns,
a frontend analysis error remained (if using sketches with consumer
functions):
AnalysisException: No matching function with signature:
ds_hll_estimate(BINARY)
This patch completes the fix by:
1. Changed return types to BINARY:
- ds_hll_sketch(), ds_cpc_sketch(), ds_theta_sketch(),
ds_kll_sketch()
2. Changed parameter types to BINARY for all consumer functions:
- HLL: ds_hll_estimate, ds_hll_estimate_bounds_as_string,
ds_hll_union_f, ds_hll_stringify, ds_hll_union (UDAF)
- CPC: ds_cpc_estimate, ds_cpc_stringify, ds_cpc_union_f,
ds_cpc_union (UDAF)
- Theta: ds_theta_estimate, ds_theta_exclude,
ds_theta_union_f, ds_theta_intersect_f, ds_theta_union
(UDAF), ds_theta_intersect (UDAF)
- KLL: ds_kll_quantile, ds_kll_n, ds_kll_rank,
ds_kll_quantiles_as_string, ds_kll_pmf_as_string,
ds_kll_cdf_as_string, ds_kll_stringify, ds_kll_union
(UDAF)
Thanks to IMPALA-9482 (BINARY type support), this only requires
FE changes — no backend modifications needed. The C++ UDFs already
treat StringVal as raw bytes.
Backward compatibility: All STRING sketch columns require migration.
Existing queries passing STRING sketches to consumer functions will
fail at analysis time with a type mismatch. Migrate by retyping the
sketch column in place with ALTER TABLE ... CHANGE COLUMN from STRING
to BINARY; the on-disk bytes are unchanged. Alternatively, store
sketches in BINARY columns or wrap them with CAST(col AS BINARY) at
the call site. Queries that only call ds_*_sketch() to create sketches
are unaffected — the return type changes silently from STRING to
BINARY, which only matters when INSERTing into a typed column.
Interop caveat: This fix enables reading Hive-written ORC sketch
columns. A separate interop hazard remains (IMPALA-9939): when the
*source column* being sketched is of STRING type, Impala hashes
the values as UTF-8 bytes while Hive uses UTF-16 chars. The
resulting sketches are not mergeable across engines regardless of
how they are stored (BINARY or STRING). To sketch string data
compatibly, cast the source to BINARY in Hive:
ds_hll_sketch(CAST(col AS BINARY))
Testing:
- Added testdata/workloads/functional-query/queries/QueryTest/
datasketches-hll-hive-orc.test demonstrating the ORC interop fix
- Updated the four existing sketch test files for BINARY return
types for tests/query_test/test_datasketches.py
Change-Id: Id4a6b54089dd356e37257bc24adeb1eb98e82c25
Assisted-by: Claude Sonnet 4.6 (GitHub Copilot)
Reviewed-on: http://gerrit.cloudera.org:8080/24590
Reviewed-by: Impala Public Jenkins <[email protected]>
Tested-by: Impala Public Jenkins <[email protected]>
> Rewrite ds_hll_sketch() and ds_hll_union() and other datasketch generating
> functions to return Binary
> -----------------------------------------------------------------------------------------------------
>
> Key: IMPALA-9821
> URL: https://issues.apache.org/jira/browse/IMPALA-9821
> Project: IMPALA
> Issue Type: New Feature
> Components: Backend
> Reporter: Gabor Kaszab
> Assignee: Mihaly Szjatinya
> Priority: Blocker
>
> Until Binary implementation is ongoing ds_hll_sketch() and ds_hll_union()
> functions return serialized sketches in String format. Once Binary is
> available in Impala these can return the serialized sketches in Binary format.
> Currently when sketches are written by Hive as BINARY to ORC table and this
> table is loaded to Impala where the sketch columns are STRINGs then we get an
> error
> {code:java}
> ERROR: Type mismatch: table column STRING is map to column binary in ORC file
> {code}
> Interestingly the works with Parquet format.
> Once we have binary support make sure to add coverage for ORC table where the
> table is created and populated by Hive and read for estimating by Impala.
> UPDATE: since BINARY type support was added in IMPALA-9482, the error above
> is not reproducable.
> Currently (2026 September) what remains is the incompatibility between
> datasketches function signatures, as Impala uses STRING in places where Hive
> used BINARY.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]