Skip to content
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

SQL: [docs] Add documentation for COALESCE #35740

Merged
merged 2 commits 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
46 changes: 46 additions & 0 deletions docs/reference/sql/functions/conditional.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[role="xpack"]
[testenv="basic"]
[[sql-functions-conditional]]
=== Conditional Functions

Functions that return one of their arguments by evaluating in an if-else manner.

[[sql-functions-conditional-coalesce]]
==== `COALESCE`

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enumerating the parameters should happen in a section called Input. Also, there has to be an Output section. Something like:

==== `COALESCE`

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

*Input*:

<1> 1st expression
<2> 2nd expression
....

*Output*: one expression or `null`

.Description:

Returns the first of its arguments that is not null.
If all arguments are null, then it returns `null`.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I would add in the description (to enforce the ... in the parameters list), that the function can take an arbitrary number of arguments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The statement about arbitrary number of arguments is there. Please, ignore my comment.

*Input*:

<1> 1st expression

<2> 2nd expression

...

**N**th expression

COALESCE can take an arbitrary number of arguments.

*Output*: one of the expressions or `null`

.Description

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[coalesceReturnNonNull]
----

["source","sql",subs="attributes,callouts,macros"]
----
include-tagged::{sql-specs}/docs.csv-spec[coalesceReturnNull]
----
2 changes: 2 additions & 0 deletions docs/reference/sql/functions/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* <<sql-functions-math, Mathematical>>
* <<sql-functions-string, String>>
* <<sql-functions-type-conversion,Type Conversion>>
* <<sql-functions-conditional, Conditional>>

include::operators.asciidoc[]
include::aggs.asciidoc[]
Expand All @@ -20,3 +21,4 @@ include::search.asciidoc[]
include::math.asciidoc[]
include::string.asciidoc[]
include::type-conversion.asciidoc[]
include::conditional.asciidoc[]
21 changes: 21 additions & 0 deletions x-pack/plugin/sql/qa/src/main/resources/docs.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -1510,3 +1510,24 @@ SELECT TRUNCATE(-345.153, 1) AS trimmed;
// end::mathTruncateWithPositiveParameter
;


coalesceReturnNonNull
// tag::coalesceReturnNonNull
SELECT COALESCE(null, 'elastic', 'search') AS "coalesce";

coalesce
---------------
elastic
// end::coalesceReturnNonNull
;


coalesceReturnNull
// tag::coalesceReturnNull
SELECT COALESCE(null, null, null, null) AS "coalesce";

coalesce
---------------
null
// end::coalesceReturnNull
;