alamb commented on code in PR #12839:
URL: https://github.com/apache/datafusion/pull/12839#discussion_r1796798614


##########
datafusion/sqllogictest/test_files/struct.slt:
##########
@@ -422,3 +449,83 @@ query T
 select arrow_typeof(c2) from t;
 ----
 Struct([Field { name: "r", data_type: Utf8, nullable: true, dict_id: 0, 
dict_is_ordered: false, metadata: {} }, Field { name: "b", data_type: Float32, 
nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }])
+
+statement ok
+drop table t;
+
+##################################
+## Test Coalesce with Struct
+##################################
+
+statement ok
+CREATE TABLE t (
+    s1 struct(a int, b varchar),
+    s2 struct(a float, b varchar)
+) AS VALUES
+  (row(1, 'red'), row(1.1, 'string1')),
+  (row(2, 'blue'), row(2.2, 'string2')),
+  (row(3, 'green'), row(33.2, 'string3'))
+;
+
+query ?
+select coalesce(s1) from t;
+----
+{a: 1, b: red}
+{a: 2, b: blue}
+{a: 3, b: green}
+
+# TODO: a's type should be float
+query T
+select arrow_typeof(coalesce(s1)) from t;
+----
+Struct([Field { name: "a", data_type: Int32, nullable: true, dict_id: 0, 
dict_is_ordered: false, metadata: {} }, Field { name: "b", data_type: Utf8, 
nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }])
+Struct([Field { name: "a", data_type: Int32, nullable: true, dict_id: 0, 
dict_is_ordered: false, metadata: {} }, Field { name: "b", data_type: Utf8, 
nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }])
+Struct([Field { name: "a", data_type: Int32, nullable: true, dict_id: 0, 
dict_is_ordered: false, metadata: {} }, Field { name: "b", data_type: Utf8, 
nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }])
+
+statement ok
+drop table t;
+
+statement ok
+CREATE TABLE t (
+    s1 struct(a int, b varchar),
+    s2 struct(a float, b varchar)
+) AS VALUES
+  (row(1, 'red'), row(1.1, 'string1')),
+  (null, row(2.2, 'string2')),
+  (row(3, 'green'), row(33.2, 'string3'))
+;
+
+# TODO: second column should not be null
+query ?
+select coalesce(s1) from t;
+----
+{a: 1, b: red}
+NULL
+{a: 3, b: green}
+
+statement ok
+drop table t;
+
+# row() with incorrect order
+statement error DataFusion error: Arrow error: Cast error: Cannot cast string 
'blue' to value of Float64 type
+create table t(a struct(r varchar, c int), b struct(r varchar, c float)) as 
values 
+    (row('red', 1), row(2.3, 'blue')),
+    (row('purple', 1), row('green', 2.3));
+
+# out of order struct literal
+# TODO: This query should not fail

Review Comment:
   👍 



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to