You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/04/08 21:36:42 UTC

[GitHub] [druid] jihoonson opened a new pull request #11083: Fix CAST being ignored when aggregating on strings after cast

jihoonson opened a new pull request #11083:
URL: https://github.com/apache/druid/pull/11083


   ### Description
   
   Currently, `CAST` is ignored in the query plan when you use certain aggregators on string columns after case. Taking a query, `SELECT APPROX_QUANTILE_DS(CAST(dim1 as DOUBLE), 0.01) FROM foo`, as a example, Druid creates a query plan like below.
   
   ```json
   {
     "queryType" : "timeseries",
     "dataSource" : {
       "type" : "table",
       "name" : "foo"
     },
     "intervals" : {
       "type" : "intervals",
       "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ]
     },
     "descending" : false,
     "virtualColumns" : [ ],
     "granularity" : {
       "type" : "all"
     },
     "aggregations" : [ {
       "type" : "DoublesSketchAggregatorFactory",
       "name" : "a0:agg",
       "fieldName" : "dim1",
       "k" : 128
     } ],
     "postAggregations" : [ {
       "type" : "DoublesSketchToQuantilePostAggregator",
       "name" : "a0",
       "field" : {
         "type" : "fieldAccess",
         "name" : "a0:agg",
         "fieldName" : "a0:agg"
       },
       "fraction" : 0.009999999776482582
     } ]
   }
   ```
   
   As a result, this query always returns `0.0` because strings cannot be casted to numbers implicitly. This PR fixes this issue by keeping `CAST` when it casts from string to a number. 
   
   This PR additionally fixes NPE in `ApproximateHistogramBufferAggregator` when the input column has nulls. Finally, some sqlAggregator tests are refactored to use help functions in `BaseCalciteQueryTest`.
   
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   - [x] been self-reviewed.
      - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] 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/dev/license.md)
   - [ ] 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, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [ ] added integration tests.
   - [ ] 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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] clintropolis merged pull request #11083: Fix CAST being ignored when aggregating on strings after cast

Posted by GitBox <gi...@apache.org>.
clintropolis merged pull request #11083:
URL: https://github.com/apache/druid/pull/11083


   


-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org