Skip to content

Commit f755cb4

Browse files
authored
feat: Support BinaryView type in approx_distinct (#23333)
## Which issue does this PR close? - Relates to #22989 but does not close it. More types are coming. ## Rationale for this change - Support the `BinaryView` type for `approx_distinct` - The Arrow type `BinaryView` can be directly supported for `HLLAccumulator` and `HllGroupsAccumulator` ## What changes are included in this PR? - Enable `HLLAccumulator` and `HllGroupsAccumulator` to support `BinaryView` - Tests for the non-grouped and grouped path as part of `aggregate.slt` ## Are these changes tested? Yes ## Are there any user-facing changes? Yes, `approx_distinct` supports now `BinaryView` but no breaking changes.
1 parent 0365d3c commit f755cb4

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

datafusion/functions-aggregate/src/approx_distinct.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ impl AggregateUDFImpl for ApproxDistinct {
798798
| DataType::LargeUtf8
799799
| DataType::Utf8View
800800
| DataType::Binary
801+
| DataType::BinaryView
801802
| DataType::LargeBinary => Box::new(HLLAccumulator::new()),
802803
DataType::Null => {
803804
Box::new(NoopAccumulator::new(ScalarValue::UInt64(Some(0))))
@@ -866,6 +867,7 @@ fn is_hll_groups_type(data_type: &DataType) -> bool {
866867
| DataType::LargeUtf8
867868
| DataType::Utf8View
868869
| DataType::Binary
870+
| DataType::BinaryView
869871
| DataType::LargeBinary
870872
)
871873
}

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,23 @@ SELECT g, approx_distinct(arrow_cast(s, 'Utf8View')) FROM approx_distinct_group_
19361936
3 0
19371937
4 1
19381938

1939+
# BinaryView non-grouped
1940+
query I
1941+
SELECT approx_distinct(arrow_cast(arrow_cast(s, 'Binary'), 'BinaryView')) FROM approx_distinct_group_test WHERE g = 2;
1942+
----
1943+
2
1944+
1945+
1946+
# BinaryView grouped
1947+
query II
1948+
SELECT g, approx_distinct(arrow_cast(arrow_cast(s, 'Binary'), 'BinaryView')) FROM approx_distinct_group_test GROUP BY g ORDER BY g;
1949+
----
1950+
1 2
1951+
2 2
1952+
3 0
1953+
4 1
1954+
1955+
19391956
# Integers (Int32): group 1 -> {10,20}=2, group 2 -> {30,40}=2, group 3 -> 0, group 4 -> {50}=1
19401957
query II
19411958
SELECT g, approx_distinct(i) FROM approx_distinct_group_test GROUP BY g ORDER BY g;

0 commit comments

Comments
 (0)