uros-b commented on code in PR #60074:
URL: https://github.com/apache/spark/pull/60074#discussion_r4469036280
##########
sql/core/src/test/resources/sql-tests/inputs/cte-recursion-nested-nullability.sql:
##########
@@ -0,0 +1,76 @@
+--SET spark.sql.caseSensitive=false
+--CONFIG_DIM1 spark.sql.ansi.enabled=true
+--CONFIG_DIM1 spark.sql.ansi.enabled=false
+
Review Comment:
The tests can't catch a nested-nullability regression. Every golden uses
one-row literal anchors, so only the LocalRelation branch runs, and golden
output doesn't print nullability. We need a ResolveRecursiveCTESuite case that
asserts the output data types.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionBase.scala:
##########
@@ -240,17 +240,20 @@ abstract class TypeCoercionBase extends
TypeCoercionHelper {
// On the other hand, we cannot cast the anchor type into a wider
recursion type, as at
// this point the UnionLoopRefs inside the recursion are already
resolved with the
// narrower anchor type.
+ // Nested nullability may widen because UnionLoopRefs already allow
nested nulls.
val projectList =
s.recursion.output.zip(s.anchor.output.map(_.dataType)).map {
case (attr, dt) =>
- val widerType = findWiderTypeForTwo(attr.dataType, dt)
- if (widerType.isDefined && widerType.get == dt) {
- if (attr.dataType != dt) {
- Alias(Cast(attr, dt), attr.name)()
- } else {
- attr
- }
- } else {
- throw cannotMergeIncompatibleDataTypesError(dt, attr.dataType)
+ // Preserve the anchor's field names when merging structs
case-insensitively.
+ val widerType = findWiderTypeForTwo(dt, attr.dataType)
+ widerType match {
+ case Some(targetType) if
DataType.equalsIgnoreNullability(targetType, dt) =>
Review Comment:
Recursions with more than 100 rows per iteration lose stats and constraints.
On the LogicalRDD branch, rewriteStatsAndConstraints's exact type-equality
check now fails, and a WARN fires on every iteration. Fix: relax it to
equalsIgnoreCompatibleNullability.
--
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]