You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "schenksj (via GitHub)" <gi...@apache.org> on 2026/05/30 00:12:57 UTC
[PR] fix: propagate parent struct null mask in GetStructField [datafusion-comet]
schenksj opened a new pull request, #4523:
URL: https://github.com/apache/datafusion-comet/pull/4523
## Which issue does this PR close?
Closes #4432.
## Rationale for this change
A field of a NULL struct must be NULL (Spark semantics). Arrow stores a `StructArray`'s child arrays with their own validity, **independent** of the parent struct's null buffer — so the raw child value at a row where the struct itself is null can be non-null (e.g. parquet files where a logically-null struct column still carries a populated child buffer). `GetStructField::evaluate` returned the child column verbatim, so `isnotnull(struct.field)` wrongly evaluated TRUE for a null struct.
## What changes are included in this PR?
`GetStructField` now unions the parent struct's null mask into the extracted child (null where the struct is null OR the child is null), via a `project_field` helper used by both the array and scalar-struct evaluation paths.
## How are these changes tested?
Added a standalone unit test `field_of_null_struct_is_null` that builds a `StructArray` whose child buffer is non-null at every row while the struct is null at some rows. The test **fails without the fix** (the field comes back non-null for the null-struct rows) and **passes with it**.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: correct GetStructField null handling for null parent structs (value + nullability) [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove merged PR #4523:
URL: https://github.com/apache/datafusion-comet/pull/4523
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: correct GetStructField null handling for null parent structs (value + nullability) [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #4523:
URL: https://github.com/apache/datafusion-comet/pull/4523#discussion_r3330244847
##########
spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala:
##########
@@ -125,6 +125,37 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper {
}
}
+ test("GetStructField: non-nullable field of a nullable struct (Delta action-frame shape)") {
+ // Repro for the under-declared `GetStructField` nullability that crashed Comet's native
+ // execution with "Column '...' is declared as non-nullable but contains null values".
+ //
+ // Models Delta's action frame: each log row is exactly ONE action type, so action columns are
+ // NULLABLE structs, but their inner fields are declared NON-nullable by Delta's typed
+ // SingleAction schema (e.g. `add.size`). We build that exact shape with an explicit in-memory
+ // schema (a Parquet round-trip would mark every field nullable, and a CreateNamedStruct would
+ // be declined). Pushing the struct through a Comet shuffle and projecting the non-nullable
+ // inner field (GetStructField) used to produce a null in a column declared non-nullable, which
+ // Comet's native execution rejected during RecordBatch validation.
+ val schema = StructType(
+ Seq(
+ StructField(
+ "add",
+ StructType(Seq(StructField("size", LongType, nullable = false))),
+ nullable = true),
+ StructField("v", IntegerType, nullable = false)))
+ val rows = (0 until 1000).map(i => Row(if (i % 2 == 0) Row(i.toLong) else null, i))
+ withSQLConf(
+ CometConf.COMET_EXEC_SHUFFLE_ENABLED.key -> "true",
+ CometConf.COMET_EXEC_SHUFFLE_WITH_HASH_PARTITIONING_ENABLED.key -> "true") {
+ val df = spark
+ .createDataFrame(spark.sparkContext.parallelize(rows), schema)
+ .repartition(4, col("v")) // materialize the typed struct through a Comet shuffle
+ .select(col("add.size").as("size")) // GetStructField on the non-nullable inner field
+ .repartition(4, col("size")) // re-shuffle: read-back validates the declared schema
+ checkSparkAnswer(df)
Review Comment:
Can `checkSparkAnswerAndOperator` be used here?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org