hudi-agent commented on code in PR #18540:
URL: https://github.com/apache/hudi/pull/18540#discussion_r3133097348
##########
hudi-spark-datasource/hudi-spark3-common/src/main/scala/org/apache/spark/sql/hudi/command/InsertIntoHoodieTableCommand.scala:
##########
@@ -111,7 +111,12 @@ object InsertIntoHoodieTableCommand extends Logging with
ProvidesHoodieConfig wi
}
val config = buildHoodieInsertConfig(catalogTable, sparkSession,
isOverWritePartition, isOverWriteTable, partitionSpec, extraOptions,
staticOverwritePartitionPathOpt)
- val df = sparkSession.internalCreateDataFrame(query.execute(),
query.schema)
+ val enrichedSchema = HoodieSchemaConversionUtils.alignSchemaWithCatalog(
+ query.schema,
+ catalogTable.tableSchemaWithoutMetaFields,
+ sparkSession.sessionState.conf.caseSensitiveAnalysis,
+ alignNullability = true)
Review Comment:
🤖 For INSERT/UPDATE, `resolveQueryOutputColumns` is now called with the
*relaxed* schema, so Spark's `TableOutputResolver` won't insert `AssertNotNull`
for BLOB/VARIANT leaf fields (it sees them as nullable). Then
`alignSchemaWithCatalog(..., alignNullability=true)` flips those same leaves
back to non-null on the DataFrame. The Javadoc on `alignSchemaWithCatalog` says
callers must guarantee the rows carry no nulls for non-null catalog columns —
but that precondition is precisely what the relax-pass undoes for these
subtrees. Have you considered what happens for something like
`named_struct('external_path', cast(null as string), 'managed', true)` where an
inner BLOB leaf is legitimately null? It looks like the schema would be
relabeled non-null and the actual null would reach Avro encoding without an
upfront check, potentially surfacing as a confusing runtime
`AvroRuntimeException` or silently writing bad data. Worth either threading the
relaxation through `alignNullability` (
i.e. also skip alignment for BLOB/VARIANT leaves and rely on Spark's runtime
AssertNotNull on 3.5+ / explicit validation on 3.4), or adding an explicit
null-assertion step before the write.
<sub><i>- Generated by an AI agent and may contain mistakes. Please verify
any suggestions before applying.</i></sub>
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]