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 @@ -452,13 +452,17 @@ case class Inline(child: Expression) extends UnaryExpression with CollectionGene

private lazy val numFields = elementSchema.fields.length

private lazy val generatorNullRow = new GenericInternalRow(elementSchema.length)

override def eval(input: InternalRow): TraversableOnce[InternalRow] = {
val inputArray = child.eval(input).asInstanceOf[ArrayData]
if (inputArray == null) {
Nil
} else {
for (i <- 0 until inputArray.numElements())
yield inputArray.getStruct(i, numFields)
for (i <- 0 until inputArray.numElements()) yield {
val s = inputArray.getStruct(i, numFields)
if (s == null) generatorNullRow else s
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, ExprCo
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
import org.apache.spark.sql.catalyst.trees.LeafLike
import org.apache.spark.sql.functions._
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.test.SharedSparkSession
import org.apache.spark.sql.types.{IntegerType, StructType}

Expand Down Expand Up @@ -390,7 +391,7 @@ class GeneratorFunctionSuite extends QueryTest with SharedSparkSession {
}
}

test("SPARK-39061: inline should handle null struct") {
def testNullStruct(): Unit = {
val df = sql(
"""select * from values
|(
Expand All @@ -414,6 +415,16 @@ class GeneratorFunctionSuite extends QueryTest with SharedSparkSession {
sql("select a, inline(b) from t1"),
Row(1, 0, 1) :: Row(1, null, null) :: Row(1, 2, 3) :: Row(1, null, null) :: Nil)
}

test("SPARK-39061: inline should handle null struct") {
testNullStruct
}

test("SPARK-39496: inline eval path should handle null struct") {
withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> "false") {
testNullStruct
}
}
}

case class EmptyGenerator() extends Generator with LeafLike[Expression] {
Expand Down