jayzhan211 commented on code in PR #10268:
URL: https://github.com/apache/datafusion/pull/10268#discussion_r1581974222


##########
datafusion/sqllogictest/test_files/functions.slt:
##########
@@ -1159,3 +1159,247 @@ drop table uuid_table
 statement ok
 drop table t
 
+
+# Test coalesce function
+query I
+select coalesce(1, 2, 3);
+----
+1
+
+# test with first null
+query I
+select coalesce(null, 3, 2, 1);
+----
+3
+
+# test with null values
+query ?
+select coalesce(null, null);
+----
+NULL
+
+# test with different types
+query error
+select coalesce(arrow_cast(1, 'Int32'), arrow_cast(1, 'Int64'));
+----
+DataFusion error: Error during planning: No function matches the given name 
and argument types 'coalesce(Int32, Int64)'. You might need to add explicit 
type casts.
+       Candidate functions:
+       coalesce(T or Null, .., T or Null)
+
+
+statement ok
+create table t1 (a bigint, b int, c int) as values (null, null, 1), (null, 2, 
null);
+
+# first non-null value is int32, but there are mixed types (i64, i32, i32), so 
error is expected
+# This test also validate `skip_coercion` works, without skipping, i32 is 
coerced to i64 and signature error is not thrown
+query error
+select coalesce(a, b, c) from t1;
+----
+DataFusion error: Error during planning: No function matches the given name 
and argument types 'coalesce(Int64, Int32, Int32)'. You might need to add 
explicit type casts.
+       Candidate functions:
+       coalesce(T or Null, .., T or Null)
+
+
+query I
+select coalesce(b, c) from t1;
+----
+1
+2
+
+
+statement ok
+drop table t1;
+
+# test multi rows
+statement ok
+CREATE TABLE t1(
+  c1 int,
+  c2 int
+) as VALUES
+(1, 2),
+(NULL, 2),
+(1, NULL),
+(NULL, NULL);
+
+query I
+SELECT COALESCE(c1, c2) FROM t1
+----
+1
+2
+1
+NULL
+
+statement ok
+drop table t1;
+
+
+# coalesce static empty value

Review Comment:
   The test cases below are moved from `scalar.slt`.



-- 
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: github-unsubscr...@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to