-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a `COALESCE` function that returns the first non-null value.
- Loading branch information
Showing
14 changed files
with
532 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[[esql-coalesce]] | ||
=== `COALESCE` | ||
|
||
Returns the first non-null value. | ||
|
||
[source.merge.styled,esql] | ||
---- | ||
include::{esql-specs}/null.csv-spec[tag=coalesce] | ||
---- | ||
[%header.monospaced.styled,format=dsv,separator=|] | ||
|=== | ||
include::{esql-specs}/null.csv-spec[tag=coalesce-result] | ||
|=== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
x-pack/plugin/esql/qa/testFixtures/src/main/resources/null.csv-spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
isNull | ||
from employees | ||
| where gender is null | ||
| sort first_name | ||
| keep first_name, gender | ||
| limit 3; | ||
|
||
first_name:keyword|gender:keyword | ||
Berni |null | ||
Cristinel |null | ||
Duangkaew |null | ||
; | ||
|
||
notIsNull | ||
from employees | ||
| where gender is not null | ||
| sort first_name | ||
| keep first_name, gender | ||
| limit 3; | ||
|
||
first_name:keyword|gender:keyword | ||
Alejandro |F | ||
Amabile |M | ||
Anneke |F | ||
; | ||
|
||
isNullForDocs | ||
// tag::is-null[] | ||
FROM employees | ||
| WHERE birth_date IS NULL | ||
| KEEP first_name, last_name | ||
| SORT first_name | ||
| LIMIT 3 | ||
// end::is-null[] | ||
; | ||
|
||
// tag::is-null-result[] | ||
first_name:keyword|last_name:keyword | ||
Basil |Tramer | ||
Florian |Syrotiuk | ||
Lucien |Rosenbaum | ||
// end::is-null-result[] | ||
; | ||
|
||
isNotNullForDocs | ||
// tag::is-not-null[] | ||
FROM employees | ||
| WHERE is_rehired IS NOT NULL | ||
| STATS count(emp_no) | ||
// end::is-not-null[] | ||
; | ||
|
||
// tag::is-not-null-result[] | ||
count(emp_no):long | ||
84 | ||
// end::is-not-null-result[] | ||
; | ||
|
||
coalesceSimple | ||
// tag::coalesce[] | ||
ROW a=null, b="b" | ||
| EVAL COALESCE(a, b) | ||
// end::coalesce[] | ||
; | ||
|
||
// tag::coalesce-result[] | ||
a:null | b:keyword | COALESCE(a,b):keyword | ||
null | b | b | ||
// end::coalesce-result[] | ||
; | ||
|
||
coalesce | ||
FROM employees | ||
| EVAL first_name = COALESCE(first_name, "X") | ||
| SORT first_name DESC, emp_no ASC | ||
| KEEP emp_no, first_name | ||
| limit 10; | ||
|
||
emp_no:integer | first_name:keyword | ||
10047 | Zvonko | ||
10081 | Zhongwei | ||
10026 | Yongqiao | ||
10043 | Yishay | ||
10050 | Yinghua | ||
10087 | Xinglin | ||
10030 | X | ||
10031 | X | ||
10032 | X | ||
10033 | X | ||
; | ||
|
||
coalesceBackwards | ||
FROM employees | ||
| EVAL first_name = COALESCE("X", first_name) | ||
| SORT first_name DESC, emp_no ASC | ||
| KEEP emp_no, first_name | ||
| limit 10; | ||
|
||
emp_no:integer | first_name:keyword | ||
10001 | X | ||
10002 | X | ||
10003 | X | ||
10004 | X | ||
10005 | X | ||
10006 | X | ||
10007 | X | ||
10008 | X | ||
10009 | X | ||
10010 | X | ||
; | ||
|
||
coalesceEndsInNull | ||
# ending in null is sill because it'll noop but it shouldn't break things. | ||
FROM employees | ||
| EVAL first_name = COALESCE(first_name, last_name, null) | ||
| SORT first_name DESC, emp_no ASC | ||
| KEEP emp_no, first_name | ||
| limit 3; | ||
|
||
emp_no:integer | first_name:keyword | ||
10047 | Zvonko | ||
10081 | Zhongwei | ||
10026 | Yongqiao | ||
; | ||
|
||
coalesceFolding | ||
FROM employees | ||
| EVAL foo=COALESCE(true, false, null) | ||
| SORT emp_no ASC | ||
| KEEP emp_no, first_name, foo | ||
| limit 3; | ||
|
||
emp_no:integer | first_name:keyword | foo:boolean | ||
10001 | Georgi | true | ||
10002 | Bezalel | true | ||
10003 | Parto | true | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.