havefunatcode opened a new issue, #20819:
URL: https://github.com/apache/druid/issues/20819

   ### Affected Version
   
   master (checked at a311ccd1c4). 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:
   
   ```sql
   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.
   


-- 
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]

Reply via email to