clintropolis opened a new pull request #9429: fix issue when distinct grouping 
dimensions are optimized into the same virtual column expression
URL: https://github.com/apache/druid/pull/9429
 
 
   
   Fixes issue uncovered in #9412.
   
   ### Description
   As an optimization added in #6902, Druid SQL re-uses the same expression 
virtual column whenever possible when constructing a native query, to take 
advantage of things like the caching selectors, etc.
   
   These virtual columns are translated into `DimensionExpression` when taking 
part in a grouping, using the virtual column name as the output name and the 
input dimension on the resulting `DimensionSpec`. However, if 2 dimensions 
taking part in a grouping were using the same expression, the output signature 
would incorrectly duplicate the expression causing an error of the form:
   
   ```
   ...
   Caused by: org.apache.druid.java.util.common.ISE: Duplicate field name: v0
        at org.apache.druid.sql.calcite.rel.Grouping.<init>(Grouping.java:71)
        at org.apache.druid.sql.calcite.rel.Grouping.create(Grouping.java:100)
        at 
org.apache.druid.sql.calcite.rel.DruidQuery.computeGrouping(DruidQuery.java:346)
        at 
org.apache.druid.sql.calcite.rel.DruidQuery.fromPartialQuery(DruidQuery.java:193)
        at 
org.apache.druid.sql.calcite.rel.PartialDruidQuery.build(PartialDruidQuery.java:306)
   ...
   ```
   
   This PR fixes this issue by checking for repeated usage of virtual columns 
in dimensions, and uses normal dimension output names rather than the virtual 
column name in case a duplicate is encountered. The added test and modified 
existing tests illustrate the effects of the new behavior.
   
   <hr>
   
   This PR has:
   - [x] been self-reviewed.
   - [x] added unit tests or modified existing tests to cover new code paths.
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * `DruidQuery`
    * `DimensionExpression`

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to