Skip to content

Commit abfecc7

Browse files
authored
ESQL: Docs: COUNT: add an explanation to the use of the 3VL (#116684) (#117005)
Add an explanation of why `... OR NULL` is needed with `COUNT(...)`. Fixes: #99954
1 parent f663886 commit abfecc7

File tree

2 files changed

+4
-2
lines changed
  • docs/reference/esql/functions/examples
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate

2 files changed

+4
-2
lines changed

docs/reference/esql/functions/examples/count.asciidoc

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Count.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public class Count extends AggregateFunction implements ToAggregator, SurrogateE
5858
),
5959
@Example(
6060
description = "To count the same stream of data based on two different expressions "
61-
+ "use the pattern `COUNT(<expression> OR NULL)`",
61+
+ "use the pattern `COUNT(<expression> OR NULL)`. This builds on the three-valued logic "
62+
+ "({wikipedia}/Three-valued_logic[3VL]) of the language: `TRUE OR NULL` is `TRUE`, but `FALSE OR NULL` is `NULL`, "
63+
+ "plus the way COUNT handles `NULL`s: `COUNT(TRUE)` and `COUNT(FALSE)` are both 1, but `COUNT(NULL)` is 0.",
6264
file = "stats",
6365
tag = "count-or-null"
6466
) }

0 commit comments

Comments
 (0)