Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ object Literal {
v.isInstanceOf[InternalRow] && {
val row = v.asInstanceOf[InternalRow]
st.fields.map(_.dataType).zipWithIndex.forall {
case (fieldDataType, i) => doValidate(row.get(i, fieldDataType), fieldDataType)
case (fieldDataType, i) =>
// Do not need to validate null values.
row.isNullAt(i) || doValidate(row.get(i, fieldDataType), fieldDataType)
}
}
case _ => false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,24 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
UTF8String.fromString("Spark SQL"))
}

// A generic internal row that throws exception when accessing null values
class NullAccessForbiddenGenericInternalRow(override val values: Array[Any])
extends GenericInternalRow(values) {
override def get(ordinal: Int, dataType: DataType): AnyRef = {
if (values(ordinal) == null) {
throw new RuntimeException(s"Should not access null field at $ordinal!")
}
super.get(ordinal, dataType)
}
}

test("SPARK-46634: literal validation should not drill down to null fields") {
val exceptionInternalRow = new NullAccessForbiddenGenericInternalRow(Array(null, 1))
val schema = StructType.fromDDL("id INT, age INT")
// This should not fail because it should check whether the field is null before drilling down
Literal.validateLiteralValue(exceptionInternalRow, schema)
}

test("SPARK-46604: Literal support immutable ArraySeq") {
import org.apache.spark.util.ArrayImplicits._
val immArraySeq = Array(1.0, 4.0).toImmutableArraySeq
Expand Down