kazuyukitanimura commented on code in PR #7149:
URL: https://github.com/apache/datafusion-comet/pull/7149#discussion_r4353865262


##########
spark/src/test/resources/sql-tests/expressions/conditional/case_when_field_names.sql:
##########
@@ -65,3 +65,68 @@ query expect_native(casewhen)
 SELECT to_json(CASE WHEN p THEN named_struct('x', i, 'X', CAST(5.5 AS DOUBLE))
   ELSE named_struct('X', 0, 'x', d) END)
 FROM test_case_field_names
+
+-- Case-distinct names repeat across positions in the opposite order. Spark 
aligns fields by
+-- position, so x stays an INT. Pairing fields by name would widen it to 
DOUBLE, and to_json would
+-- emit 7.0. Each INSERT writes its own files, and a batch never spans files, 
so the first has
+-- every row take THEN, the second every row take ELSE, and the third mixes 
them.
+-- https://github.com/apache/datafusion-comet/issues/6532
+statement
+CREATE TABLE test_case_positional(q boolean, i int, d double) USING parquet
+
+statement
+INSERT INTO test_case_positional VALUES (true, 7, 9.5), (true, NULL, NULL)
+
+statement
+INSERT INTO test_case_positional VALUES (false, 7, 9.5), (false, NULL, NULL)
+
+statement
+INSERT INTO test_case_positional VALUES (true, 7, 9.5), (false, 8, 10.5), 
(NULL, NULL, NULL), (false, 3, NULL)

Review Comment:
   Addressed



##########
spark/src/test/resources/sql-tests/expressions/conditional/case_when_field_names.sql:
##########
@@ -65,3 +65,68 @@ query expect_native(casewhen)
 SELECT to_json(CASE WHEN p THEN named_struct('x', i, 'X', CAST(5.5 AS DOUBLE))
   ELSE named_struct('X', 0, 'x', d) END)
 FROM test_case_field_names
+
+-- Case-distinct names repeat across positions in the opposite order. Spark 
aligns fields by
+-- position, so x stays an INT. Pairing fields by name would widen it to 
DOUBLE, and to_json would
+-- emit 7.0. Each INSERT writes its own files, and a batch never spans files, 
so the first has
+-- every row take THEN, the second every row take ELSE, and the third mixes 
them.
+-- https://github.com/apache/datafusion-comet/issues/6532
+statement
+CREATE TABLE test_case_positional(q boolean, i int, d double) USING parquet
+
+statement
+INSERT INTO test_case_positional VALUES (true, 7, 9.5), (true, NULL, NULL)
+
+statement
+INSERT INTO test_case_positional VALUES (false, 7, 9.5), (false, NULL, NULL)
+
+statement
+INSERT INTO test_case_positional VALUES (true, 7, 9.5), (false, 8, 10.5), 
(NULL, NULL, NULL), (false, 3, NULL)
+
+-- Both branch orders
+query expect_native(casewhen)
+SELECT
+  to_json(CASE WHEN q THEN named_struct('x', i, 'X', CAST(5.5 AS DOUBLE))
+    ELSE named_struct('X', 0, 'x', d) END),
+  to_json(CASE WHEN q THEN named_struct('X', 0, 'x', d)
+    ELSE named_struct('x', i, 'X', CAST(5.5 AS DOUBLE)) END)
+FROM test_case_positional
+
+-- Several branches, none of which has the others' names
+query expect_native(casewhen)
+SELECT
+  to_json(CASE WHEN q THEN named_struct('x', i, 'X', CAST(5.5 AS DOUBLE))
+    WHEN i > 7 THEN named_struct('X', 1, 'x', d)
+    ELSE named_struct('x', 2, 'X', d) END),
+  to_json(CASE WHEN q THEN named_struct('X', 1, 'x', d)
+    WHEN i > 7 THEN named_struct('x', i, 'X', CAST(5.5 AS DOUBLE))
+    ELSE named_struct('X', 2, 'x', d) END)
+FROM test_case_positional
+
+-- Native to_json supports structs, so extract the struct after reconciling 
the array or map.

Review Comment:
   Addressed



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