Skip to content

Commit

Permalink
[SPARK-38030][SQL] Canonicalization should not remove nullability of …
Browse files Browse the repository at this point in the history
…AttributeReference dataType
  • Loading branch information
shardulm94 committed Jan 28, 2022
1 parent 18f9e7e commit 6b77f66
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ case class AttributeReference(
}

override lazy val preCanonicalized: Expression = {
AttributeReference("none", dataType.asNullable)(exprId)
AttributeReference("none", dataType)(exprId)
}

override def newInstance(): AttributeReference =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.catalyst.dsl.plans._
import org.apache.spark.sql.catalyst.plans.logical.Range
import org.apache.spark.sql.types.{IntegerType, LongType, StructField, StructType}
import org.apache.spark.sql.types.{IntegerType, LongType, StringType, StructField, StructType}

class CanonicalizeSuite extends SparkFunSuite {

Expand Down Expand Up @@ -177,4 +177,17 @@ class CanonicalizeSuite extends SparkFunSuite {
assert(expr.semanticEquals(attr))
assert(attr.semanticEquals(expr))
}

test("SPARK-38030: Canonicalization should not remove nullability of AttributeReference" +
" dataType") {
val structType = StructType(Seq(StructField("name", StringType, nullable = false)))
val attr = AttributeReference("col", structType)()
// AttributeReference dataType should not be converted to nullable
assert(attr.canonicalized.dataType === structType)

val cast = Cast(attr, structType)
assert(cast.resolved)
// canonicalization should not converted resolved cast to unresolved
assert(cast.canonicalized.resolved)
}
}

0 comments on commit 6b77f66

Please sign in to comment.