[SPARK-56171][SQL] Enable V2 file write path for non-partitioned DataFrame API writes and delete FallBackFileSourceV2#54998
Open
LuciferYang wants to merge 1 commit intoapache:masterfrom
Open
Conversation
Contributor
Author
|
Follow-up tickets
The currently recorded plan: https://issues.apache.org/jira/browse/SPARK-56170 |
Member
|
Wow, this and many TODO IDs. Thank you for working on this area, @LuciferYang . |
…Frame API writes and delete FallBackFileSourceV2 Key changes: - FileWrite: added partitionSchema, customPartitionLocations, dynamicPartitionOverwrite, isTruncate; path creation and truncate logic; dynamic partition overwrite via FileCommitProtocol - FileTable: createFileWriteBuilder with SupportsDynamicOverwrite and SupportsTruncate; capabilities now include TRUNCATE and OVERWRITE_DYNAMIC; fileIndex skips file existence checks when userSpecifiedSchema is provided (write path) - All file format writes (Parquet, ORC, CSV, JSON, Text, Avro) use createFileWriteBuilder with partition/truncate/overwrite support - DataFrameWriter.lookupV2Provider: enabled FileDataSourceV2 for non-partitioned Append and Overwrite via df.write.save(path) - DataFrameWriter.insertInto: V1 fallback for file sources (TODO: SPARK-56175) - DataFrameWriter.saveAsTable: V1 fallback for file sources (TODO: SPARK-56230, needs StagingTableCatalog) - DataSourceV2Utils.getTableProvider: V1 fallback for file sources (TODO: SPARK-56175) - Removed FallBackFileSourceV2 rule - V2SessionCatalog.createTable: V1 FileFormat data type validation
30a677f to
677a482
Compare
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 V2 file write path for non-partitioned
df.write.mode("append"/"overwrite").save(path)operations across all built-in file formats (Parquet, ORC, JSON, CSV, Text, Avro), and deletes theFallBackFileSourceV2analysis rule which is now redundant.Key changes
V2 write foundation (
FileTable,FileWrite,*Write,*Table)FileTable.createFileWriteBuilder: new infrastructure for creatingWriteBuilderwithSupportsTruncateandSupportsDynamicOverwritecapabilitiesFileWrite: partition schema support, truncation (overwrite), dynamic partition overwrite, schema validation (nested column name duplication, data type, collation in map keys)Writecase classes (ParquetWrite,OrcWrite,JsonWrite,CSVWrite,TextWrite,AvroWrite) accept new parameters fromcreateFileWriteBuilderTableclasses implementnewWriteBuilderviacreateFileWriteBuilderDelete
FallBackFileSourceV2BaseSessionStateBuilderandHiveSessionStateBuilderUSE_V1_SOURCE_LIST(defaulting to all built-in formats) already prevents V2 file tables from being created, andDataSourceV2Utils.getTableProvidergates catalog table loadingCache invalidation (
DataSourceV2Strategy)refreshCache: userecacheByPath(instead ofrecacheByPlan) forFileTablewrites, withfileIndex.refresh()to update the cached file listingError handling (
FileFormatDataWriter)writeAllto wrap errors withTASK_WRITE_FAILED, consistent with the per-rowwrite()methodV2 write gating (
DataFrameWriter,DataSourceV2Utils)DataFrameWriter.lookupV2Provider: allow V2 forFileDataSourceV2only when mode isAppendorOverwriteAND nopartitionByis specified; fall back to V1 forErrorIfExists/Ignore(TODO: SPARK-56174) and partitioned writes (TODO: SPARK-56185)DataFrameWriter.saveAsTable/insertInto: always fall back to V1 forFileDataSourceV2(TODO: SPARK-56185)DataSourceV2Utils.getTableProvider: returnNoneforFileDataSourceV2to prevent V2 catalog table loading until stats, partition management, and data type validation gaps are addressed (TODO: SPARK-56185)Data type validation (
V2SessionCatalog)FileFormat.supportDataTypevalidation in thecreateTablefallback branch, ensuringCREATE TABLEwith unsupported types (e.g., Variant in CSV) is rejected consistentlyAvro Table
formatNamefrom"AVRO"to"Avro"to match V1'sAvroFileFormat.toStringWhy are the changes needed?
The V2 Data Source API provides a cleaner, more extensible write path than V1's
InsertIntoHadoopFsRelationCommand. Enabling V2 writes for built-in file formats is a step toward fully migrating file sources to V2, which will simplify the codebase and enable future optimizations.FallBackFileSourceV2was an analysis rule that converted V2 fileInsertIntoStatementback to V1. It is no longer needed because:USE_V1_SOURCE_LIST(default: all built-in formats) prevents V2 file tables from being created for reads or writesDataSourceV2Utils.getTableProvidergates V2 catalog table loadingAppendData/OverwriteByExpression, notInsertIntoStatementDoes this PR introduce any user-facing change?
No. With default configuration (
spark.sql.sources.useV1SourceList="avro,csv,json,kafka,orc,parquet,text"), all file writes continue to use the V1 path. The V2 write path is only activated when a user explicitly clearsUSE_V1_SOURCE_LISTand usesdf.write.mode("append"/"overwrite").save(path)withoutpartitionBy.How was this patch tested?
FileDataSourceV2WriteSuite(23 tests) covering:Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code 4.6