Skip to content

Support more types for approx_distinct function #22989

Description

@2010YOUY01

Is your feature request related to a problem or challenge?

#22921 has refactored approx_distinct into a more generic implementation over different input types, now it's easy to support additional arg types. (Thanks to @Jefffrey for pointing it out in the review)

Describe the solution you'd like

  1. Identify the unsupported types
  2. Plan them into the generic implementation of Accumulator and GroupsAccumulator (see refactor: Simplify approx_distinct (-200 LoC) #22921 for details)
  3. Add sqllogictests

Note we don't have to support all applicable types at once, some complex type might get tricky to test, so I prefer to do this incrementally

Describe alternatives you've considered

No response

Additional context

No response

Activity

  1. mkleen commented on Jun 17, 2026

    @mkleen
    Contributor

    take

  2. alamb commented on Jun 23, 2026

    @alamb
    Contributor

    FWIW some types, such as floats, likely don't make sense to implement DISTINCT for (as we found in #23084).

    It would probably be good to review what other database implementations do before implementing it for datafusion

  3. mkleen commented on Jun 24, 2026

    @mkleen
    Contributor

    I had a look at DuckDB. DuckDB doesn't declare the supported types in their docs for approx_count_distinct https://duckdb.org/docs/lts/sql/functions/aggregates.

    I did some manual testing and it seems it supports each of its data type:

    Category Types
    Signed int TINYINT, SMALLINT, INTEGER, BIGINT, HUGEINT
    Unsigned int UTINYINT, USMALLINT, UINTEGER, UBIGINT
    Float FLOAT, DOUBLE, DECIMAL
    String/binary VARCHAR, BLOB, BIT, UUID
    Temporal DATE, TIME, TIMESTAMP, TIMESTAMPTZ, INTERVAL
    Other BOOLEAN, JSON
    Nested LIST, STRUCT, MAP
  4. mkleen commented on Jun 24, 2026

    @mkleen
    Contributor

    The arrow-types which are currently unsupported in approx_distinct in datafusion are:

    Arrow Type Implemented in approx_distinct
    Float16 not planned
    Float32 not planned
    Float64 not planned
    Decimal32 #23190
    Decimal64 #23190
    Decimal128 #23190
    Decimal256 #23190
    Duration #23291
    Interval #23234
    BinaryView #23333
    FixedSizeBinary #23417
    List #23443
    LargeList #23443
    ListView #23443
    LargeListView #23443
    FixedSizeList #23443
    Struct #23663
    Map #23526
    Union #23714
    Dictionary #24646
    RunEndEncoded #25951

    It most likely doesn't make sense to support all types. But this is probably a good start.

  5. mkleen commented on Jul 18, 2026

    @mkleen
    Contributor

    We won't support Float types. What about RunEndEncoded, Union and Dictionary ? They are no SQL types mapped to them. Does it make sense to support them?

  6. Jefffrey commented on Jul 19, 2026

    @Jefffrey
    Contributor

    the way i see it, if regular distinct supports the data type, approx distinct should also support it; given it seems regular distinct supports all types we should follow suit

  7. mkleen commented on Jul 19, 2026

    @mkleen
    Contributor

    Ok, thanks for the feedback!

  8. added a commit that references this issue on Oct 3, 2026
    a93c9b8
  9. added a commit that references this issue on Oct 11, 2026
    cdc5fd7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions