[NO ISSUE][FUN] Add coalesce() function
- user model changes: yes
- storage format changes: no
- interface changes: no
Details:
- Add coalesce() function which is an alias to if_missing_or_null()
Change-Id: Ic462bc08173f2f2349cc208c687d432a219d62b9
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2923
Reviewed-by: Till Westmann <tillw@apache.org>
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/coalesce/coalesce.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/coalesce/coalesce.1.query.sqlpp
new file mode 100644
index 0000000..18a73e3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/coalesce/coalesce.1.query.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* coalesce() is equivalent to ifmissingornull() */
+
+{
+ "a": isnull(coalesce()),
+ "b": isnull(coalesce(missing)),
+ "c": isnull(coalesce(null)),
+ "d": isnull(coalesce(null, missing)),
+ "e": coalesce(null, true, 1),
+ "f": coalesce(missing, true, 1),
+ "g": coalesce(null, missing, true, 1),
+ "h": coalesce(null, missing, true, 1),
+ "i": coalesce(
+ missing,
+ null,
+ case when get_year(current_datetime()) > 0 then missing else false end,
+ case when get_year(current_datetime()) > 0 then null else false end,
+ case when get_year(current_datetime()) > 0 then true else missing end
+ )
+};
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 67bfb09..4df7cae 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -4933,6 +4933,11 @@
</compilation-unit>
</test-case>
<test-case FilePath="null-missing">
+ <compilation-unit name="coalesce">
+ <output-dir compare="Text">ifmissingornull</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="null-missing">
<compilation-unit name="query-ASTERIXDB-1689">
<output-dir compare="Text">query-ASTERIXDB-1689</output-dir>
</compilation-unit>
diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/13_conditional.md b/asterixdb/asterix-doc/src/main/markdown/builtins/13_conditional.md
index f0e98fd..8c2dce7 100644
--- a/asterixdb/asterix-doc/src/main/markdown/builtins/13_conditional.md
+++ b/asterixdb/asterix-doc/src/main/markdown/builtins/13_conditional.md
@@ -75,7 +75,7 @@
The function has an alias `ifmissing`.
-### if_missing_or_null (ifmissingornull) ###
+### if_missing_or_null (ifmissingornull, coalesce) ###
* Syntax:
@@ -100,7 +100,7 @@
{ "a": null, "b": null, "c": "asterixdb" }
- The function has an alias `ifmissingornull`.
+ The function has two aliases: `ifmissingornull` and `coalesce`.
### if_inf (ifinf) ###
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java
index 372acab..631bb7b 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java
@@ -73,6 +73,7 @@
addFunctionMapping("ifinf", "if-inf"); // ifinf, internal: if-inf
addFunctionMapping("ifnan", "if-nan"); // ifnan, internal: if-nan
addFunctionMapping("ifnanorinf", "if-nan-or-inf"); // ifnanorinf, internal: if-nan-or-inf
+ addFunctionMapping("coalesce", "if-missing-or-null"); // coalesce, internal: if-missing-or-null
addFunctionMapping("missingif", "missing-if"); // missingif, internal: missing-if
addFunctionMapping("nanif", "nan-if"); // nanif, internal: nan-if
addFunctionMapping("neginfif", "neginf-if"); // neginfif, internal: neginf-if