Skip to content

Commit 4101f81

Browse files
committed
test: cover recursive IF branch type reconciliation
1 parent fe4c183 commit 4101f81

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎spark/src/test/resources/sql-tests/expressions/conditional/if_nested_nullability.sql‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ SELECT IF(q, named_struct('x', i), named_struct('x', 0)) FROM test_if_nested
5454
query
5555
SELECT IF(q, named_struct('x', 0), named_struct('x', i)) FROM test_if_nested
5656

57+
-- Different fields are nullable in each branch, so both branches need a cast to the common type.
58+
query expect_native(if)
59+
SELECT IF(q, named_struct('x', i, 'y', 0), named_struct('x', 0, 'y', i)) FROM test_if_nested
60+
61+
-- Reconcile nested struct fields through an array, in both branch orders.
62+
query expect_native(if)
63+
SELECT IF(q, array(named_struct('x', i)), array(named_struct('x', 0))), IF(q, array(named_struct('x', 0)), array(named_struct('x', i))) FROM test_if_nested
64+
65+
-- Recurse through a struct into map values and array elements, in both branch orders.
66+
query expect_native(if)
67+
SELECT IF(q, named_struct('m', map('k', i), 'a', array(i)), named_struct('m', map('k', 0), 'a', array(0))), IF(q, named_struct('m', map('k', 0), 'a', array(0)), named_struct('m', map('k', i), 'a', array(i))) FROM test_if_nested
68+
5769
-- map constructors: the value can be NULL in one branch only
5870
query
5971
SELECT IF(q, map('k', i), map('k', 0)) FROM test_if_nested

0 commit comments

Comments
 (0)