slinkydeveloper commented on a change in pull request #17256:
URL: https://github.com/apache/flink/pull/17256#discussion_r708001411



##########
File path: 
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CoalesceFunctionITCase.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.flink.table.planner.functions;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.table.api.DataTypes.BIGINT;
+import static org.apache.flink.table.api.DataTypes.INT;
+import static org.apache.flink.table.api.DataTypes.STRING;
+import static org.apache.flink.table.api.Expressions.$;
+import static org.apache.flink.table.api.Expressions.call;
+import static org.apache.flink.table.api.Expressions.coalesce;
+
+/** Test COALESCE and its return type. * */
+public class CoalesceFunctionITCase extends BuiltInFunctionTestBase {
+
+    @Parameterized.Parameters(name = "{index}: {0}")
+    public static List<TestSpec> testData() {
+        return Arrays.asList(
+                TestSpec.forFunction(BuiltInFunctionDefinitions.COALESCE)
+                        .onFieldsWithData(null, null, 1)
+                        .andDataTypes(BIGINT().nullable(), INT().nullable(), 
INT().notNull())
+                        .testResult(
+                                coalesce($("f0"), $("f1")),
+                                "COALESCE(f0, f1)",
+                                null,
+                                DataTypes.BIGINT().nullable())
+                        .testResult(
+                                coalesce($("f0"), $("f2")),
+                                "COALESCE(f0, f2)",
+                                1L,
+                                DataTypes.BIGINT().notNull())
+                        .testResult(
+                                coalesce($("f1"), $("f2")),
+                                "COALESCE(f1, f2)",
+                                1,
+                                DataTypes.INT().notNull())
+                        .testResult(
+                                coalesce($("f0"), 1),
+                                "COALESCE(f0, 1)",
+                                1L,
+                                // In this case, the return type is not null 
because we have a
+                                // constant in the function invocation
+                                DataTypes.BIGINT().notNull())
+                        .testResult(

Review comment:
       > From PostgreSQL behaviour, COALESCE should have at least one arg.
   
   @matriv About this one, I think it makes sense as restriction, and I can 
give you a practical reason: What should be the type if there are no args?
   
   > There should be validation that the args are compatible, and the way it 
works for PostgreSQL is left to right, so the 1st non-null arg is the reference 
one and everything else should be "castable" to that one:
   
   About this one, as @Airblader sad, it might break existing users of 
COALESCE, which now are under the "least common type" semantics. But it would 
be nice to check what the sql standard has to say about it




-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to