LakshSingla opened a new pull request #12065:
URL: https://github.com/apache/druid/pull/12065
### Description
Related to #11188
The above mentioned PR allowed timeseries queries to return a default
result, when queries of type: `select count(*) from table where
dim1="_not_present_dim_"` were executed. Before the PR, it returned no row,
after the PR, it would return a row with value of `count(*)` as 0 (as expected
by SQL standards of different dbs).
In `Grouping#applyProject`, we can sometimes perform optimization of a
groupBy query to a timeseries query if possible (when the keys of the groupBy
are constants, as generated by automated tools). For example, in `select
count(*) from table where dim1="_present_dim_" group by "dummy_key"`, the
groupBy clause can be removed. However, in the case when the filter doesn't
return anything, i.e. `select count(*) from table where
dim1="_not_present_dim_" group by "dummy_key"`, the behavior of general
databases would be to return nothing, while druid (due to above change) returns
an empty row. This PR aims to fix this divergence of behavior.
Example cases:
1. `select count(*) from table where dim1="_not_present_dim_" group by
"dummy_key"`.
_CURRENT_: Returns a row with count(*) = 0
_EXPECTED_: Return no row
2. `select 'A', dim1 from foo where m1 = 123123 and dim1 =
'_not_present_again_' group by dim1`
_CURRENT_: Returns a row with ('A', 'wat')
_EXPECTED_: Return no row
<!--
In each section, please describe design decisions made, including:
- Choice of algorithms
- Behavioral aspects. What configuration values are acceptable? How are
corner cases and error conditions handled, such as when there are insufficient
resources?
- Class organization and design (how the logic is split between classes,
inheritance, composition, design patterns)
- Method organization and design (how the logic is split between methods,
parameters and return types)
- Naming (class, method, API, configuration, HTTP endpoint, names of
emitted metrics)
-->
To do this, a boolean `droppedDimensionsWhileApplyingProject` has been added
to `Grouping` which is true whenever we make changes to the original shape with
optimization. Hence if a timeseries query has a grouping with this set to true,
we set `skipEmptyBuckets=true` in the query context (i.e. donot return any row).
<hr>
##### Key changed/added classes in this PR
* `Grouping.java`
* `DruidQuery#toTimeseriesQuery`
<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)
- [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,
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.
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]