You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "Vamsi-klu (via GitHub)" <gi...@apache.org> on 2026/08/17 04:05:22 UTC

[PR] [SPARK-47397][SQL][DOCS] Document that COUNT(DISTINCT) skips nulls [spark]

Vamsi-klu opened a new pull request, #58038:
URL: https://github.com/apache/spark/pull/58038

   ### What changes were proposed in this pull request?
   Spell out that `COUNT(DISTINCT)` / `count_distinct` skips nulls, in `docs/sql-ref-null-semantics.md`.
   
   - Add a `count(DISTINCT age)` example next to the existing `count(*)` / `count(age)` block. On the `person` table the result is 3 (ages 30, 18, 50).
   - Add a one-liner in the GROUP BY / DISTINCT section: `COUNT(DISTINCT expr)` still follows the aggregate rule and does not count null.
   
   No code change. `Count.scala`, `count.sql.out`, and `DataFrameAggregateSuite` already treat distinct count as unique non-null values. GROUP BY / SELECT DISTINCT still bucket nulls. Those are different rules.
   
   ### Why are the changes needed?
   The page already states both rules, and it is easy to mix them up for `COUNT(DISTINCT)`. The ticket reporter hit that. Philipp pointed at the SQL standard. Nicholas asked to document it on this page. The implementation is already correct.
   
   ### Does this PR introduce _any_ user-facing change?
   No.
   
   ### How was this patch tested?
   Docs only. Mentally executed on the `person` table on that page: distinct non-null ages are 30, 18, 50, so the result is 3. I did not run the Jekyll build here because Bundler was not available.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   Generated-by: Cursor Grok 4.6
   
   Made with [Cursor](https://cursor.com)


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47397][SQL][DOCS] Document that COUNT(DISTINCT) skips nulls [spark]

Posted by "Vamsi-klu (via GitHub)" <gi...@apache.org>.
Vamsi-klu commented on code in PR #58038:
URL: https://github.com/apache/spark/pull/58038#discussion_r3797386312


##########
docs/sql-ref-null-semantics.md:
##########
@@ -385,6 +394,8 @@ two `NULL` values are not equal. However, for the purpose of grouping and distin
 values with `NULL data`are grouped together into the same bucket. This behaviour is conformant with SQL
 standard and with other enterprise database management systems.
 
+`COUNT(DISTINCT expr)` still follows the aggregate rule above and does not count null.

Review Comment:
   Agreed, “the aggregate rule above” was too vague. I restated it here so it is clear that COUNT(DISTINCT) ignores NULL values, instead of pointing back to the earlier section.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47397][SQL][DOCS] Document that COUNT(DISTINCT) skips nulls [spark]

Posted by "Vamsi-klu (via GitHub)" <gi...@apache.org>.
Vamsi-klu commented on PR #58038:
URL: https://github.com/apache/spark/pull/58038#issuecomment-5311680883

   cc @nchammas @martinitus @HyukjinKwon


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47397][SQL][DOCS] Document that COUNT(DISTINCT) skips nulls [spark]

Posted by "nchammas (via GitHub)" <gi...@apache.org>.
nchammas commented on code in PR #58038:
URL: https://github.com/apache/spark/pull/58038#discussion_r3796840219


##########
docs/sql-ref-null-semantics.md:
##########
@@ -273,6 +273,15 @@ SELECT count(age) FROM person;
 |         5|
 +----------+
 
+-- `count(DISTINCT age)` also skips `NULL`. A null group is not a distinct counted value.
+-- This is different from GROUP BY / SELECT DISTINCT, which put all nulls in one bucket.

Review Comment:
   Nit: I think we don't need the second sentence.
   
   ```suggestion
   -- `count(DISTINCT age)` also skips `NULL`. This is different from GROUP BY / SELECT DISTINCT,
   -- which put all nulls in one bucket.
   ```



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47397][SQL][DOCS] Document that COUNT(DISTINCT) skips nulls [spark]

Posted by "uros-b (via GitHub)" <gi...@apache.org>.
uros-b commented on PR #58038:
URL: https://github.com/apache/spark/pull/58038#issuecomment-5313809590

   LGTM


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47397][SQL][DOCS] Document that COUNT(DISTINCT) skips nulls [spark]

Posted by "Vamsi-klu (via GitHub)" <gi...@apache.org>.
Vamsi-klu commented on code in PR #58038:
URL: https://github.com/apache/spark/pull/58038#discussion_r3797384496


##########
docs/sql-ref-null-semantics.md:
##########
@@ -273,6 +273,15 @@ SELECT count(age) FROM person;
 |         5|
 +----------+
 
+-- `count(DISTINCT age)` also skips `NULL`. A null group is not a distinct counted value.
+-- This is different from GROUP BY / SELECT DISTINCT, which put all nulls in one bucket.

Review Comment:
   Good call. I dropped that extra sentence and used your wording.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47397][SQL][DOCS] Document that COUNT(DISTINCT) skips nulls [spark]

Posted by "Vamsi-klu (via GitHub)" <gi...@apache.org>.
Vamsi-klu commented on PR #58038:
URL: https://github.com/apache/spark/pull/58038#issuecomment-5317986183

   Thanks for the review, @nchammas. Both nits are in the latest commit. I used your wording on the count(DISTINCT age) example, and I restated the GROUP BY note so it says COUNT(DISTINCT) ignores NULL values instead of pointing at a vague earlier rule.


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47397][SQL][DOCS] Document that COUNT(DISTINCT) skips nulls [spark]

Posted by "uros-b (via GitHub)" <gi...@apache.org>.
uros-b closed pull request #58038: [SPARK-47397][SQL][DOCS] Document that COUNT(DISTINCT) skips nulls
URL: https://github.com/apache/spark/pull/58038


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47397][SQL][DOCS] Document that COUNT(DISTINCT) skips nulls [spark]

Posted by "nchammas (via GitHub)" <gi...@apache.org>.
nchammas commented on code in PR #58038:
URL: https://github.com/apache/spark/pull/58038#discussion_r3796876997


##########
docs/sql-ref-null-semantics.md:
##########
@@ -385,6 +394,8 @@ two `NULL` values are not equal. However, for the purpose of grouping and distin
 values with `NULL data`are grouped together into the same bucket. This behaviour is conformant with SQL
 standard and with other enterprise database management systems.
 
+`COUNT(DISTINCT expr)` still follows the aggregate rule above and does not count null.

Review Comment:
   Nit: It's not clear which aggregate rule this line is referring to. Is it this?
   
   https://github.com/apache/spark/blob/653ddad6233a8dc7b574f4f030ff9693c2502908/docs/sql-ref-null-semantics.md#L245-L246
   
   I would just restate the rule since linking directly to it is not straightforward. Or, we could just remove this line since the previous section already covers `COUNT` and `COUNT DISTINCT`.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-47397][SQL][DOCS] Document that COUNT(DISTINCT) skips nulls [spark]

Posted by "uros-b (via GitHub)" <gi...@apache.org>.
uros-b commented on PR #58038:
URL: https://github.com/apache/spark/pull/58038#issuecomment-5492845840

   **Merge Summary:**
   - merged into master https://github.com/apache/spark/commit/f759028b8609d221ca6c52c2cf449dee31dae79c
   - merged into branch-4.x https://github.com/apache/spark/commit/7a147724aa0f0d981186fa5c4a5c7afd1cf5990b
   
   *Posted by `merge_spark_pr.py`*


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org