You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "gianm (via GitHub)" <gi...@apache.org> on 2023/04/14 05:42:08 UTC
[GitHub] [druid] gianm commented on a diff in pull request #13014: Add support for using multiple columns in a distinct count sql aggregation
gianm commented on code in PR #13014:
URL: https://github.com/apache/druid/pull/13014#discussion_r1166297407
##########
docs/querying/sql-aggregations.md:
##########
@@ -66,7 +66,7 @@ In the aggregation functions supported by Druid, only `COUNT`, `ARRAY_AGG`, and
|Function|Notes|Default|
|--------|-----|-------|
|`COUNT(*)`|Counts the number of rows.|`0`|
-|`COUNT(DISTINCT expr)`|Counts distinct values of `expr`.<br /><br />When `useApproximateCountDistinct` is set to "true" (the default), this is an alias for `APPROX_COUNT_DISTINCT`. The specific algorithm depends on the value of [`druid.sql.approxCountDistinct.function`](../configuration/index.md#sql). In this mode, you can use strings, numbers, or prebuilt sketches. If counting prebuilt sketches, the prebuilt sketch type must match the selected algorithm.<br /><br />When `useApproximateCountDistinct` is set to "false", the computation will be exact. In this case, `expr` must be string or numeric, since exact counts are not possible using prebuilt sketches. In exact mode, only one distinct count per query is permitted unless `useGroupingSetForExactDistinct` is enabled.<br /><br />Counts each distinct value in a [`multi-value`](../querying/multi-value-dimensions.md)-row separately.|`0`|
+|`COUNT(DISTINCT expr, expr...)`|Counts distinct values of all `expr`.<br><br>When `useApproximateCountDistinct` is set to "true" (the default), this is an alias for `APPROX_COUNT_DISTINCT`. The specific algorithm depends on the value of [`druid.sql.approxCountDistinct.function`](../configuration/index.md#sql). In this mode, you can use strings, numbers, or prebuilt sketches. If counting prebuilt sketches, the prebuilt sketch type must match the selected algorithm.<br><br>When `useApproximateCountDistinct` is set to "false", the computation will be exact. In this case, each `expr` must be string or numeric, since exact counts are not possible using prebuilt sketches. In exact mode, only one distinct count per query is permitted unless `useGroupingSetForExactDistinct` is enabled.<br /><br />Counts each distinct value in a [`multi-value`](../querying/multi-value-dimensions.md)-row separately.|`0`|
Review Comment:
IMO docs are not clear: does "all expr" mean "all distinct tuples of exprs" or "all distinct values of exprs considered as one big set"? Some examples would help.
Like, if you do `COUNT(DISTINCT a, b)` and the rows are `(1, 2)` and `(1, 1)` and `(2, 2)`, is the result going to be 3 (distinct tuples) or 2 (one big set)?
##########
sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/CountSqlAggregator.java:
##########
@@ -72,29 +75,41 @@ static AggregatorFactory createCountAggregatorFactory(
final Project project
)
{
- final RexNode rexNode = Expressions.fromFieldAccess(
Review Comment:
Why are changes to non-distinct `COUNT` needed?
If we are making these changes— should we have doc updates for them too?
--
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: commits-unsubscribe@druid.apache.org
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