Skip to content

fix: reject floats nested in containers in approx_distinct - #26988

Open
pujitha24 wants to merge 3 commits into
apache:mainfrom
pujitha24:auto/issue-26985
Open

pujitha24 wants to merge 3 commits into
apache:mainfrom
pujitha24:auto/issue-26985

Conversation

@pujitha24

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

approx_distinct rejects floats (bare, or inside dictionary/REE) with a "not implemented" error, but silently accepted lists, structs and maps containing floats.

What changes are included in this PR?

A recursive contains_float check in is_hll_groups_type, and the nested-type accumulator arm now uses the is_supported_type guard, so nested floats get the same not-implemented error.

What is the testing strategy for this PR?

New unit test nested_float_unsupported and new sqllogictest cases in aggregate.slt (List/Struct/Map, with and without GROUP BY). Unit tests and the new slt cases pass; other pre-existing failures in the aggregate slt run also occur on the base. Full extended suite not run.

Are there any user-facing changes?

Queries over nested-float columns that previously returned a count now return the not-implemented error, consistent with bare floats.

Motivation:
approx_distinct rejects Float16/32/64 (also inside dictionary and
run-end-encoded types) with a "not implemented" error, but accepted
List/Struct/Map/Union containing floats and returned a result, because the
support check only looked at the outer type.

Approach:
Add a recursive contains_float helper (lists, list views, fixed-size lists,
maps, structs, unions, dictionaries, REE) and make is_hll_groups_type return
false for such types. The scalar accumulator arm for nested types now
uses the is_supported_type guard, so nested floats hit the same
"not implemented" error as bare floats; the groups accumulator check is
consistent through is_hll_groups_type.

Impact: queries over nested-float columns that previously returned a
count now return the not-implemented error, matching bare floats.

Validation:
- cargo test -p datafusion-functions-aggregate approx_distinct (16 passed;
  includes new nested_float_unsupported unit test)
- cargo test --profile ci -p datafusion-sqllogictest --test sqllogictests -- aggregate
  new approx_distinct cases in aggregate.slt pass. Other failures in that
  run (e.g. bit_xor, aggregate_skip_partial) also occur on the unmodified
  base and are unrelated.
- cargo fmt --all; cargo clippy -p datafusion-functions-aggregate
  --all-targets -- -D warnings: clean.
I did not run the full extended workspace test suite.

Report: apache#26985
Signed-off-by: Pujitha Paladugu <[email protected]>
Assisted-by: claude-sonnet-5-5 (via Claude Code)
@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Nov 1, 2026
@pujitha24

Copy link
Copy Markdown
Author

Both of these should already be in the branch's latest commit (3245e8b), in case you were looking at the first commit. contains_float is gone and is_hll_groups_type now calls datafusion_common::utils::has_float_leaf. nested_float_unsupported has a List<List<Float64>> case next to the list, large list, fixed-size list, struct and map ones. The approx_distinct lib tests pass locally. If I've misread what you wanted, let me know.

@mkleen mkleen left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for for working on this. Overall it does the right thing. A few things before it can go in:

  • The new helper function already exists. contains_float does the same job as datafusion_common::float_semantics::has_float_leaf, which is used in other places.
  • Test with a list inside a list would show that floats are found at any depth.

@mkleen mkleen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found one more issue.

use std::hash::BuildHasher;

#[test]
fn nested_float_unsupported() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the slt tests are sufficient. we don't need this test.

/// [`HllGroupsAccumulator`]. The fixed-domain types (booleans / small ints) and
/// `Null` fall back to the per-group [`Accumulator`] path.
fn is_hll_groups_type(data_type: &DataType) -> bool {
if has_float_leaf(data_type) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should move up to is_supported_type, this is not only group related.

|| is_hll_groups_type(value_type)
}

fn encoded_value_type(data_type: &DataType) -> &DataType {

@mkleen mkleen Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we move has_float_leaf into is_supported_type we can get rid of encoded_value_type completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

approx_distinct rejects floats, but accepts containers of them

2 participants