julianhyde commented on code in PR #3003:
URL: https://github.com/apache/calcite/pull/3003#discussion_r1066380796
##########
site/_docs/reference.md:
##########
@@ -2625,6 +2625,7 @@ semantics.
| m | EXTRACTVALUE(xml, xpathExpr)) | Returns the text of the
first text node which is a child of the element or elements matched by the
XPath expression.
| b o | GREATEST(expr [, expr ]*) | Returns the greatest of
the expressions
| b h s | IF(condition, value1, value2) | Returns *value1* if
*condition* is TRUE, *value2* otherwise
+| b | IFNULL(expr, null_result) | If expr evaluates
to NULL, returns null_result. Otherwise, returns expr. If expr doesn't evaluate
to NULL, null_result isn't evaluated.
Review Comment:
no trailing '.'
The following would be better:
```
| b | IFNULL(value1, value2) | Synonym for `NVL`
```
##########
babel/src/test/resources/sql/big-query.iq:
##########
@@ -2596,4 +2596,29 @@ FROM items;
!ok
+#####################################################################
+#
Review Comment:
move this section somewhere besides the end; add a column to distinguish the
examples
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -6315,6 +6315,30 @@ void assertSubFunReturns(boolean binary, String s, int
start,
f12.checkNull("nvl(CAST(NULL AS VARCHAR(6)), cast(NULL AS VARCHAR(4)))");
}
+
+ @Test void testIfNullCoalesceFunc() {
Review Comment:
method should be called `testIfnullFunc`. Add comment that IFNULL is synonym
for NVL (and related to COALESCE but requires precisely two arguments)
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -190,7 +190,10 @@ private SqlLibraryOperators() {
/** The "IFNULL(value, value)" function. */
@LibraryOperator(libraries = {BIG_QUERY})
- public static final SqlFunction IFNULL = new SqlIfNullFunction();
+ public static final SqlFunction IFNULL = SqlBasicFunction.create("IFNULL",
Review Comment:
better, `NVL.withName("IFNULL")` (you'll need to change the type of `NVL`)
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlIfNullFunction.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+package org.apache.calcite.sql.fun;
+
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.sql.type.SqlTypeTransforms;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.util.Util;
+
+import java.util.List;
+
+/**
+ * The <code>IFULL</code> function.
+ */
+public class SqlIfNullFunction extends SqlFunction {
Review Comment:
Do we need this class? IFNULL is a synonym for COALESCE. (Also for NVL,
which is in the Oracle library.)
I'd make it an alias for NVL (since NVL and IFNULL have exactly 2 args).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]