maytasm opened a new pull request #9986: URL: https://github.com/apache/druid/pull/9986
Fix groupBy with literal in subquery grouping ### Description I believe this is a regression/bug caused by https://github.com/apache/druid/pull/9122 When we have a query such as: ``` SELECT t1, t2 FROM ( SELECT 'm' as t1, CASE WHEN cityName = 'Egypt' THEN cityName ELSE NULL END AS t2 FROM wikipedia GROUP BY cityName ) GROUP BY t1,t2 ``` Calcite will creates a Rel `2020-06-04T08:59:34,977 TRACE [sql[0840a1a8-ff59-4986-ad69-be2ce27a5e68]] org.apache.calcite.plan.RelOptPlanner - Register rel#5424:DruidQueryRel.NONE.[](query={"queryType":"groupBy","dataSource":{"type":"table","name":"wikipedia"},"intervals":{"type":"intervals","intervals":["-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z"]},"virtualColumns":[],"filter":null,"granularity":{"type":"all"},"dimensions":[{"type":"default","dimension":"cityName","outputName":"d0","outputType":"STRING"}],"aggregations":[],"postAggregations":[],"having":null,"limitSpec":{"type":"NoopLimitSpec"},"context":{"populateCache":false,"sqlQueryId":"0840a1a8-ff59-4986-ad69-be2ce27a5e68","useCache":false},"descending":false},signature={d0:STRING}) in rel#5415:Subset#2.NONE.[]` for part of the subquery. This Rel signature is only a single field. The other field which is a literal is not part of the groupBy and is part of the projection on top of this. Now the problem is when we try to build new Rel, in computeSubtotals with the above Rel as the sourceRel and a partialQuery with aggregate looking like `aggregate=rel#5418:LogicalAggregate.NONE.[](input=RelSubset#5417,group={0, 1}), havingFilter=null, aggregateProject=null, sort=null, sortProject=null}`. This aggregate has two bits in the groupSet. This fails without taking into account the projection mentioned above. Hence, we should skip and not build this new Rel and handle this case with CannotBuildQueryException so that we can move on to other Rels. This PR has: - [x] been self-reviewed. - [ ] added documentation for new or modified features or behaviors. - [x] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links. - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/licenses.yaml) - [x] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader. - [x] added unit tests or modified existing tests to cover new code paths. - [ ] added integration tests. - [x] been tested in a test Druid cluster. ---------------------------------------------------------------- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
