Skip to content

TDIGEST_GENERATE_SKETCH fails with "Duplicate field name" after TDIGEST_QUANTILE on the same input #20819

Closed

Description

@havefunatcode

Affected Version

master (checked at a311ccd). The code involved comes from #8100, so older versions are probably affected too, but I haven't tested them.

Description

Found while working on #20782.

A query that calls TDIGEST_QUANTILE and then TDIGEST_GENERATE_SKETCH on the same input fails at planning time:

SELECT TDIGEST_QUANTILE(m1, 0.5), TDIGEST_GENERATE_SKETCH(m1) FROM foo
Duplicate field name: a0:agg

From what I tried, it happens when both functions get the same input and compression and TDIGEST_QUANTILE comes first:

Query Result
TDIGEST_QUANTILE(m1, 0.5), TDIGEST_GENERATE_SKETCH(m1) fails
TDIGEST_QUANTILE(m1 * 2, 0.5), TDIGEST_GENERATE_SKETCH(m1 * 2) fails
TDIGEST_QUANTILE(m1, 0.5, 200), TDIGEST_GENERATE_SKETCH(m1, 200) fails
TDIGEST_QUANTILE(m1, 0.5), TDIGEST_GENERATE_SKETCH(m1, 200) works
TDIGEST_GENERATE_SKETCH(m1), TDIGEST_QUANTILE(m1, 0.5) works

TDigestGenerateSketchSqlAggregator looks for an existing TDigestSketchAggregatorFactory with the same input and compression, and returns it as its own aggregation. If TDIGEST_QUANTILE came first, that factory is the quantile's a0:agg, so it is added twice and Grouping rejects the duplicate name. In the reverse order TDIGEST_QUANTILE reuses the sketch through its post-aggregator, which is fine. I tried removing the reuse loop locally as an experiment, and all of the queries above planned without errors.

To reproduce, add a test with the first query to TDigestSketchSqlAggregatorTest.

I'd like to work on a fix.

Activity

  1. akasakariko commented on Nov 4, 2026

    @akasakariko
    Contributor

    I'd like to work on this

  2. FrankChen021 commented on Nov 4, 2026

    @FrankChen021
    Member

    I assigned to you. Thank you @akasakariko

  3. AlphaSudo commented on Nov 4, 2026

    @AlphaSudo

    Hi! I'm interested in investigating this issue and potentially contributing a fix, along with regression tests and benchmarks where applicable.

    Before starting, I'd like to check:

    1. Is this issue still reproducible on the latest main branch?
    2. Is anyone currently assigned to it or already working on a fix?
    3. Is there an existing PR or planned implementation that might overlap?
    4. Would you welcome an external contribution for this issue?

    I haven't started implementation yet and want to avoid duplicating work.

    Thanks!

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions