[SPARK-56414][SQL] Per-write options should take precedence over session config in file source writes#55280
Open
cloud-fan wants to merge 4 commits intoapache:masterfrom
Open
Conversation
…on config in Parquet and Avro Co-authored-by: Isaac
Co-authored-by: Isaac
Co-authored-by: Isaac
…ng test Co-authored-by: Isaac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
In Parquet and Avro
prepareWrite, several Hadoop configuration keys are unconditionally set from session-levelSQLConf, silently overwriting any per-write options the user provided. Additionally, some write paths (FileStreamSink,InsertIntoHiveTable) create the Hadoop conf vianewHadoopConf()without merging write options at all, so per-write options never reach the conf.This PR fixes both issues:
FileFormatWriter.write: Merges write options into the Job's Hadoop conf before callingprepareWrite. This is the central fix that ensures per-write options are in the conf regardless of how the caller created it. HandlesCaseInsensitiveMapkey lowercasing by using the original map keys.ParquetUtils.prepareWrite: UsesDataSourceUtils.setConfIfAbsentso that SQLConf defaults are only applied when the key is not already present in the conf (i.e., no per-write option was provided). Affected keys:spark.sql.parquet.writeLegacyFormatspark.sql.parquet.outputTimestampTypespark.sql.parquet.fieldId.write.enabledspark.sql.legacy.parquet.nanosAsLongspark.sql.parquet.annotateVariantLogicalTypeAvroUtils.prepareWrite: Same treatment for Avro compression settings:avro.output.codec.zstd.bufferpool)avro.mapred.<codec>.level)Why are the changes needed?
Per-write options (passed via
DataFrameWriter.option()orDataStreamWriter.option()) should take precedence over session-level SQLConf defaults. This is already the case for compression codecs in both Parquet and Avro, but other write configuration keys had their per-write values silently overwritten. For example, settingspark.sql.parquet.outputTimestampTypeas a write option in a streaming sink had no effect because (a)FileStreamSinkdoesn't merge options into the Hadoop conf, and (b)prepareWritealways replaced the value with the session config.Does this PR introduce any user-facing change?
Yes. Per-write options for the listed keys now take effect instead of being silently ignored. Previously, only the session-level SQLConf value was used regardless of what was passed as a write option.
How was this patch tested?
ParquetEncodingSuite: test verifying per-writeoutputTimestampTypeoverrides session config for batch writes.FileStreamSinkV1Suite: test verifying per-writeoutputTimestampTypeoverrides session config for streaming writes (exercises theFileStreamSinkpath that usesnewHadoopConf()without options).Both tests fail on master and pass with this PR.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (claude-opus-4-6)