tlfua opened a new pull request, #7550:
URL: https://github.com/apache/datafusion-comet/pull/7550
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases. You can
link an issue to this PR using the GitHub syntax. For example `Closes #123`
indicates that this PR will close issue #123.
-->
Closes #7396.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in
the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your
changes and offer better suggestions for fixes.
-->
All four HLL expressions required `allowIncompatible` because "estimates may
differ slightly". That reason was written against datasketches 0.3.0. After the
upgrade to 0.6.0 (#7395), I compared Comet's code paths with the
DataSketches-Java 6.2.0 logic Spark uses ([experiment
run](https://github.com/tlfua/datafusion-comet/actions/runs/42348769378),
results in
https://github.com/apache/datafusion-comet/issues/7396#issuecomment-6703600973
and
https://github.com/apache/datafusion-comet/issues/7396#issuecomment-6703622409):
| Expression | Result vs Spark |
| --- | --- |
| `hll_sketch_estimate` | Bit-identical over 954 cases (lgK 4-21, all modes,
HLL_4/6/8 inputs) |
| `hll_sketch_agg` | Sketch bytes differ (compact vs updatable layout).
Estimate of a multi-partition merge differs by up to about 0.8% |
| `hll_union` | Sketch bytes differ. With `allowDifferentLgConfigK` and
different lgK, estimate differs by up to about 1.6% |
| `hll_union_agg` | Sketch bytes differ. Estimates match |
So `hll_sketch_estimate` can run natively by default, while the other three
still produce bytes that differ from Spark and stay `Incompatible`, now with a
reason that says exactly what differs.
Note: the experiment mirrors Spark's Java code and Comet's accumulator logic
outside a real Spark/DataFusion plan. The tests in this PR verify end to end in
CI.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is
sometimes worth providing a summary of the individual changes in this PR.
-->
- `CometHllSketchEstimate`: now `Compatible` (no `allowIncompatible` needed
on Spark 4.0+).
- `CometHllSketchAgg`, `CometHllUnion`, `CometHllUnionAgg`: still
`Incompatible`, with reasons replaced by the concrete differences above. Shared
text lives in a new `CometHllReasons`.
- The error class difference (Comet execution error vs Spark's
`HLL_INVALID_INPUT_SKETCH_BUFFER` / `HLL_UNION_DIFFERENT_LG_K`) moves from
`getIncompatibleReasons` to `getCompatibleNotes`. Both engines fail on the same
inputs. The old reason also listed the wrong SQLSTATE for
`HLL_INVALID_INPUT_SKETCH_BUFFER` (22546, not 22000).
- Docs: `expressions.md` updated, and audit entries added to
`expression-audits/agg_funcs.md` and `misc_funcs.md`.
Follow-ups filed by this audit:
- https://github.com/apache/datafusion-comet/issues/7548 Comet writes
LIST/SET mode sketches in the compact layout instead of Spark's updatable
layout.
- https://github.com/apache/datafusion-comet/issues/7549 HLL errors do not
use Spark's error classes.
## How are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are
they covered by existing tests)?
-->
- New SQL file test `expressions/misc/hll_sketch_estimate.sql` (Spark 4.0+,
Parquet dictionary on and off). Sketches are built by Spark for lgK 4/12/21 and
5 to 10000 distinct values, plus empty, NULL, and `hll_union_agg` results. The
estimate query must run natively and match Spark. An invalid-buffer case is
`query ignore(...)` and linked to #7549.
- `CometExpressionSuite`: new test checks that `hll_sketch_estimate` runs
natively with no config and that `hll_sketch_agg` falls back by default with
the compact-layout reason. Existing HLL tests no longer set
`HllSketchEstimate.allowIncompatible`.
Local checks (no Maven build locally, CI runs the suites):
- `scalafmt --config scalafmt.conf --test` (v3.6.1) on the changed Scala
files: passed.
- `npx prettier --check` on the changed Markdown files: passed.
Requesting the `run-spark-4.0-tests` / `run-all-spark-profiles` labels,
since the serdes only apply on Spark 4.x.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]