Skip to content

SQL: Implement ISNULL(expr1, expr2) #35793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/reference/sql/functions/conditional.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,40 @@ include-tagged::{sql-specs}/docs.csv-spec[ifNullReturnFirst]
----
include-tagged::{sql-specs}/docs.csv-spec[ifNullReturnSecond]
----


[[sql-functions-conditional-isnull]]
==== `ISNULL`

.Synopsis
[source, sql]
----
ISNULL ( expression<1>, expression<2> )
----

*Input*:

<1> 1st expression

<2> 2nd expression


*Output*: 2nd expression if 1st expression is null, otherwise 1st expression.

.Description

Variant of <<sql-functions-conditional-coalesce>> with only two arguments.
Returns the first of its arguments that is not null.
If all arguments are null, then it returns `null`.



["source","sql",subs="attributes,callouts,macros"]
----
include-tagged::{sql-specs}/docs.csv-spec[isNullReturnFirst]
----

["source","sql",subs="attributes,callouts,macros"]
----
include-tagged::{sql-specs}/docs.csv-spec[isNullReturnSecond]
----
3 changes: 2 additions & 1 deletion x-pack/plugin/sql/qa/src/main/resources/command.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ SUM_OF_SQUARES |AGGREGATE
VAR_POP |AGGREGATE
COALESCE |CONDITIONAL
IFNULL |CONDITIONAL
DAY |SCALAR
ISNULL |CONDITIONAL
DAY |SCALAR
DAYNAME |SCALAR
DAYOFMONTH |SCALAR
DAYOFWEEK |SCALAR
Expand Down
25 changes: 24 additions & 1 deletion x-pack/plugin/sql/qa/src/main/resources/docs.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ SUM_OF_SQUARES |AGGREGATE
VAR_POP |AGGREGATE
COALESCE |CONDITIONAL
IFNULL |CONDITIONAL
DAY |SCALAR
ISNULL |CONDITIONAL
DAY |SCALAR
DAYNAME |SCALAR
DAYOFMONTH |SCALAR
DAYOFWEEK |SCALAR
Expand Down Expand Up @@ -1553,3 +1554,25 @@ SELECT IFNULL(null, 'search') AS "ifnull";
search
// end::ifNullReturnSecond
;


isNullReturnFirst
// tag::isNullReturnFirst
SELECT ISNULL('elastic', null) AS "isnull";

isnull
---------------
elastic
// end::isNullReturnFirst
;


isNullReturnSecond
// tag::isNullReturnSecond
SELECT ISNULL(null, 'search') AS "isnull";

isnull
---------------
search
// end::isNullReturnSecond
;
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void defineDefaultFunctions() {
// Scalar functions
// conditional
addToMap(def(Coalesce.class, Coalesce::new));
addToMap(def(IFNull.class, IFNull::new));
addToMap(def(IFNull.class, IFNull::new, "ISNULL"));
// Date
addToMap(def(DayName.class, DayName::new, "DAYNAME"),
def(DayOfMonth.class, DayOfMonth::new, "DAYOFMONTH", "DAY", "DOM"),
Expand Down