[SPARK-56171][SQL] Enable file source V2 write path with partition, dynamic overwrite, and catalog table support#54977
Closed
LuciferYang wants to merge 7 commits intoapache:masterfrom
Closed
[SPARK-56171][SQL] Enable file source V2 write path with partition, dynamic overwrite, and catalog table support#54977LuciferYang wants to merge 7 commits intoapache:masterfrom
LuciferYang wants to merge 7 commits intoapache:masterfrom
Conversation
Contributor
Author
|
Full plan: https://issues.apache.org/jira/browse/SPARK-56170 Known limitations of this patch (addressed in follow-up patches):
Remaining subtasks:
|
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?
This PR enables the file source V2 write path (
FileWrite) to support partition columns, dynamic partition overwrite, and truncate (full overwrite), gated behind a new feature flagspark.sql.sources.v2.file.write.enabled(defaultfalse). It also removes the guard that blockedFileDataSourceV2from working with catalog tables.Previously, the V2 file write path was completely disabled —
DataFrameWriterreturnedNoneforFileDataSourceV2,FallBackFileSourceV2converted allInsertIntoStatementtargetingFileTableback to the V1 path, andDataSourceV2Utils.getTableProviderunconditionally filtered outFileDataSourceV2for catalog tables. TheFileWrite.createWriteJobDescriptionhardcodedpartitionColumns = Seq.emptyanddataColumns = allColumns, meaning partitioned writes were impossible even if the V2 path was reached.Key changes:
DataSourceV2Utils:
getTableProvider: replace unconditionalFileDataSourceV2filter withV2_FILE_WRITE_ENABLEDflag check, enabling catalog-managed tables to use V2 path when the flag is enabledFileWrite:
partitionSchema,dynamicPartitionOverwrite, andisTruncateabstract/default fieldsallColumnsintodataColumnsandpartitionColumnsincreateWriteJobDescriptionusingpartitionSchemaRequiresDistributionAndOrdering— sort by partition columns to ensureDynamicPartitionDataSingleWritersees each partition value contiguouslytoBatchdynamicPartitionOverwritetoFileCommitProtocolfor staging-based dynamic overwritelazy val descriptiontoval—prepareWritemust run beforesetupJobfor correct Job configuration (e.g., ParquetJOB_SUMMARY_LEVEL)checkNoCollationsInMapKeysvalidation aligned with V1supportsDataTypecheck for partition columns usingsqlConf.resolverfor correct case-sensitive/insensitive matching (partition columns are written as directory names, not data values)jobIdfor bothFileCommitProtocolandWriteJobDescription.uuidFileTable:
createFileWriteBuilderhelper that providesWriteBuilderwithSupportsDynamicOverwriteandSupportsTruncatemixinsBATCH_WRITE,TRUNCATE, andOVERWRITE_DYNAMICcapabilitiesFallBackFileSourceV2:
V2_FILE_WRITE_ENABLEDflag — whentrue, skip the V2-to-V1 conversionDataFrameWriter:
lookupV2Provider: allowFileDataSourceV2through when flag is enabled, forAppendandOverwritemodes (ErrorIfExists/Ignore requireSupportsCatalogOptions, deferred to SPARK-56174)All format Write/Table classes (Parquet, ORC, CSV, JSON, Text, Avro):
partitionSchema,dynamicPartitionOverwrite,isTruncateparameterscreateFileWriteBuilderinnewWriteBuilderWhy are the changes needed?
The file source V2 write path has been disabled since SPARK-28396 with a
TODOcomment. This blocks V2 from being the default for built-in file formats. The V2 API offers advantages over V1 (custom metrics, aggregate/limit/join pushdown, runtime filtering, row-level operations), but the write path must work before V2 can replace V1.This is the first patch in a series to close the V1-V2 feature gap. It establishes the write infrastructure behind a feature flag so that subsequent patches can build on it incrementally: cache invalidation, flag flip, and delete FallBackFileSourceV2 (SPARK-56173), ErrorIfExists/Ignore modes (SPARK-56174), partition management (SPARK-56175), statistics (SPARK-56176), bucketing (SPARK-56177), and MSCK REPAIR TABLE (SPARK-56178).
Does this PR introduce any user-facing change?
No. The feature flag
spark.sql.sources.v2.file.write.enableddefaults tofalse. All existing behavior is unchanged. When explicitly enabled, the V2 write path is used forAppendandOverwritemodes via the DataFrame API, and catalog tables using file-based formats are loaded as V2FileTableinstances.How was this patch tested?
Added 13 new tests in
FileDataSourceV2FallBackSuite:Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code 4.6.