Skip to content

Commit

Permalink
fix(spark): nullability of output columns of expand relation (#310)
Browse files Browse the repository at this point in the history
Fix the logic for deriving whether each output column of the
expand relation is nullable or not.
If one or more of the projections can assign null to the column,
then it must be defined as nullable.

Signed-off-by: Andrew Coleman <andrew_coleman@uk.ibm.com>
  • Loading branch information
andrew-coleman authored Oct 25, 2024
1 parent 3f2cc1e commit 6413e55
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,12 @@ class ToLogicalPlan(spark: SparkSession) extends DefaultRelVisitor[LogicalPlan]
throw new UnsupportedOperationException("ConsistentField not currently supported")
}

val output = projections.head
// An output column is nullable if any of the projections can assign null to it
val types = projections.transpose.map(p => (p.head.dataType, p.exists(_.nullable)))

val output = types
.zip(names)
.map { case (t, name) => StructField(name, t.dataType, t.nullable) }
.map { case (t, name) => StructField(name, t._1, t._2) }
.map(f => AttributeReference(f.name, f.dataType, f.nullable, f.metadata)())

Expand(projections, output, child)
Expand Down
2 changes: 1 addition & 1 deletion spark/src/test/scala/io/substrait/spark/TPCDSPlan.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TPCDSPlan extends TPCDSBase with SubstraitPlanTestBase {

// spotless:off
val successfulSQL: Set[String] = Set("q1", "q3", "q4", "q7",
"q11", "q13", "q14b", "q15", "q16", "q18", "q19",
"q11", "q13", "q14a", "q14b", "q15", "q16", "q18", "q19",
"q21", "q22", "q23a", "q23b", "q24a", "q24b", "q25", "q26", "q28", "q29",
"q30", "q31", "q32", "q33", "q37", "q38",
"q40", "q41", "q42", "q43", "q46", "q48",
Expand Down

0 comments on commit 6413e55

Please # to comment.