Ritesh17rb commented on code in PR #410:
URL: https://github.com/apache/datafusion-spark/pull/410#discussion_r4684796858
##########
crates/spark/src/planner.rs:
##########
@@ -72,6 +71,56 @@ impl ExprPlanner for SparkFunctionPlanner {
)))
}
+ fn plan_array_literal(
Review Comment:
Added that exact query with a note that it uses DataFusion-only syntax. The
array-planner override is also gone as part of the `named_struct` rewrite, so
the test now exercises the normal DataFusion planning path.
##########
crates/sqllogictest/test_files/struct/struct.slt:
##########
@@ -8,7 +8,135 @@
# For more information, please see:
# https://github.com/apache/datafusion/issues/15914
-## Original Query: SELECT struct(1, 2, 3);
-## PySpark 3.5.5 Result: {'struct(1, 2, 3)': Row(col1=1, col2=2, col3=3),
'typeof(struct(1, 2, 3))': 'struct<col1:int,col2:int,col3:int>', 'typeof(1)':
'int', 'typeof(2)': 'int', 'typeof(3)': 'int'}
-#query
-#SELECT struct(1::int, 2::int, 3::int);
+# Literal fields use one-based names in Spark.
+query ?
+SELECT struct(1::INT, 2::INT, 3::INT);
+----
+{col1: 1, col2: 2, col3: 3}
+
+# Column names are retained, while expressions use their argument position.
+query ?
+SELECT struct(a, a + 1, b) FROM (VALUES (1::INT, 'x')) AS t(a, b);
+----
+{a: 1, col2: 2, b: x}
+
+# Qualified columns retain the unqualified name, including names resembling
defaults.
+query ?
+SELECT struct(t.a, t.c0, t.col1, 7::INT) FROM (VALUES (1::INT, 2::INT,
3::INT)) AS t(a, c0, col1);
+----
+{a: 1, c0: 2, col1: 3, col4: 7}
+
+# Field names survive constant folding; duplicate names are allowed.
+query ?
+SELECT struct(a, a, 1 + 2) FROM (VALUES (4::INT)) AS t(a);
+----
+{a: 4, a: 4, col3: 3}
+
+# Explicit aliases, including an alias matching DataFusion's generated names.
+query ?
+SELECT struct(1::INT AS c0, 'x' AS label);
+----
+{c0: 1, label: x}
+
+# Scalar NULLs are fields of a non-NULL struct.
+query ?B
+SELECT struct(NULL, NULL::INT, ''), struct(NULL) IS NULL;
+----
+{col1: NULL, col2: NULL, col3: } false
+
+# Column and scalar arguments broadcast across multiple rows.
+query ? rowsort
+SELECT struct(a, 'fixed', b) FROM (VALUES (1::INT, 'x'), (NULL::INT, NULL),
(3::INT, 'z')) AS t(a, b);
+----
+{a: 1, col2: fixed, b: x}
+{a: 3, col2: fixed, b: z}
+{a: NULL, col2: fixed, b: NULL}
+
+# Nested struct expressions use positional names. Nested field access retains
its name.
+query ?
+SELECT struct(struct(1::INT, 'x'));
+----
+{col1: {col1: 1, col2: x}}
+
+query ?
+SELECT struct(s.a) FROM (SELECT named_struct('a', 1::INT) AS s) t;
+----
+{a: 1}
+
+# Arrays must merge child nullability before combining structs.
+query ?
+SELECT array(struct(1::INT, NULL::STRING), struct(2::INT, 'x'));
+----
+[{col1: 1, col2: NULL}, {col1: 2, col2: x}]
+
+query ?
+SELECT array(struct(1::INT, 'x'), struct(2::INT, NULL::STRING));
+----
+[{col1: 1, col2: x}, {col1: 2, col2: NULL}]
+
+query ? rowsort
+SELECT array(struct(a), struct(7::INT AS a)) FROM (VALUES (1::INT),
(NULL::INT)) AS t(a);
+----
+[{a: 1}, {a: 7}]
+[{a: NULL}, {a: 7}]
+
+# Spark accepts empty structs, but DataFusion's SQL parser rejects struct()
Review Comment:
I opened [sqlparser
#3048](https://github.com/apache/datafusion-sqlparser-rs/issues/3048) for the
empty argument list and [DataFusion
#27723](https://github.com/apache/datafusion/issues/27723) for the lost alias
provenance, and linked them from the corresponding blocks. The empty-struct
block also links #224 because parser support alone will not enable empty
`named_struct` execution.
--
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]