-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix file format checks to be exact and handle Delta Lake column mapping [databricks] #9279
Merged
+941
−173
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
187c582
Check for exact file format class rather than an instance of the class
jlowe 5fa81d2
Add GpuDeltaParquetFileFormat
jlowe 44fb929
Fix Parquet field IDs not being written when column ID mapping requested
jlowe 3c09367
Merge branch 'branch-23.10' into fix-file-format-check
jlowe 6780351
Merge branch 'branch-23.10' into fix-file-format-check
jlowe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add GpuDeltaParquetFileFormat
Signed-off-by: Jason Lowe <jlowe@nvidia.com>
commit 5fa81d2f6f6b642568873334f596172fd931120b
There are no files selected for viewing
This file contains 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
84 changes: 84 additions & 0 deletions
84
...c/main/databricks/scala/com/nvidia/spark/rapids/delta/GpuDeltaParquetFileFormatBase.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (c) 2023, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.nvidia.spark.rapids.delta | ||
|
||
import com.databricks.sql.transaction.tahoe.{DeltaColumnMapping, DeltaColumnMappingMode, NoMapping} | ||
import com.nvidia.spark.rapids.{GpuMetric, GpuParquetMultiFilePartitionReaderFactory, GpuReadParquetFileFormat} | ||
import org.apache.hadoop.conf.Configuration | ||
|
||
import org.apache.spark.broadcast.Broadcast | ||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.catalyst.InternalRow | ||
import org.apache.spark.sql.connector.read.PartitionReaderFactory | ||
import org.apache.spark.sql.execution.datasources.PartitionedFile | ||
import org.apache.spark.sql.rapids.GpuFileSourceScanExec | ||
import org.apache.spark.sql.sources.Filter | ||
import org.apache.spark.sql.types.StructType | ||
import org.apache.spark.util.SerializableConfiguration | ||
|
||
abstract class GpuDeltaParquetFileFormatBase extends GpuReadParquetFileFormat { | ||
val columnMappingMode: DeltaColumnMappingMode | ||
val referenceSchema: StructType | ||
|
||
def prepareSchema(inputSchema: StructType): StructType = { | ||
DeltaColumnMapping.createPhysicalSchema(inputSchema, referenceSchema, columnMappingMode) | ||
} | ||
|
||
def createMultiFileReaderFactory( | ||
broadcastedConf: Broadcast[SerializableConfiguration], | ||
pushedFilters: Array[Filter], | ||
fileScan: GpuFileSourceScanExec): PartitionReaderFactory = { | ||
GpuParquetMultiFilePartitionReaderFactory( | ||
fileScan.conf, | ||
broadcastedConf, | ||
prepareSchema(fileScan.relation.dataSchema), | ||
prepareSchema(fileScan.requiredSchema), | ||
prepareSchema(fileScan.readPartitionSchema), | ||
pushedFilters, | ||
fileScan.rapidsConf, | ||
fileScan.allMetrics, | ||
fileScan.queryUsesInputFile, | ||
fileScan.alluxioPathsMap) | ||
} | ||
|
||
override def buildReaderWithPartitionValuesAndMetrics( | ||
sparkSession: SparkSession, | ||
dataSchema: StructType, | ||
partitionSchema: StructType, | ||
requiredSchema: StructType, | ||
filters: Seq[Filter], | ||
options: Map[String, String], | ||
hadoopConf: Configuration, | ||
metrics: Map[String, GpuMetric], | ||
alluxioPathReplacementMap: Option[Map[String, String]]) | ||
: PartitionedFile => Iterator[InternalRow] = { | ||
super.buildReaderWithPartitionValuesAndMetrics( | ||
sparkSession, | ||
prepareSchema(dataSchema), | ||
prepareSchema(partitionSchema), | ||
prepareSchema(requiredSchema), | ||
filters, | ||
options, | ||
hadoopConf, | ||
metrics, | ||
alluxioPathReplacementMap) | ||
} | ||
|
||
override def supportFieldName(name: String): Boolean = { | ||
if (columnMappingMode != NoMapping) true else super.supportFieldName(name) | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...mon/src/main/delta-io/scala/com/nvidia/spark/rapids/delta/GpuDeltaParquetFileFormat.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (c) 2023, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.nvidia.spark.rapids.delta | ||
|
||
import com.nvidia.spark.rapids.{GpuMetric, GpuParquetMultiFilePartitionReaderFactory, GpuReadParquetFileFormat} | ||
import org.apache.hadoop.conf.Configuration | ||
|
||
import org.apache.spark.broadcast.Broadcast | ||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.catalyst.InternalRow | ||
import org.apache.spark.sql.connector.read.PartitionReaderFactory | ||
import org.apache.spark.sql.delta.{DeltaColumnMapping, DeltaColumnMappingMode, NoMapping} | ||
import org.apache.spark.sql.execution.datasources.PartitionedFile | ||
import org.apache.spark.sql.rapids.GpuFileSourceScanExec | ||
import org.apache.spark.sql.sources.Filter | ||
import org.apache.spark.sql.types.StructType | ||
import org.apache.spark.util.SerializableConfiguration | ||
|
||
trait GpuDeltaParquetFileFormat extends GpuReadParquetFileFormat { | ||
val columnMappingMode: DeltaColumnMappingMode | ||
val referenceSchema: StructType | ||
|
||
def prepareSchema(inputSchema: StructType): StructType = { | ||
DeltaColumnMapping.createPhysicalSchema(inputSchema, referenceSchema, columnMappingMode) | ||
} | ||
|
||
def createMultiFileReaderFactory( | ||
broadcastedConf: Broadcast[SerializableConfiguration], | ||
pushedFilters: Array[Filter], | ||
fileScan: GpuFileSourceScanExec): PartitionReaderFactory = { | ||
GpuParquetMultiFilePartitionReaderFactory( | ||
fileScan.conf, | ||
broadcastedConf, | ||
prepareSchema(fileScan.relation.dataSchema), | ||
prepareSchema(fileScan.requiredSchema), | ||
prepareSchema(fileScan.readPartitionSchema), | ||
pushedFilters, | ||
fileScan.rapidsConf, | ||
fileScan.allMetrics, | ||
fileScan.queryUsesInputFile, | ||
fileScan.alluxioPathsMap) | ||
} | ||
|
||
override def buildReaderWithPartitionValuesAndMetrics( | ||
sparkSession: SparkSession, | ||
dataSchema: StructType, | ||
partitionSchema: StructType, | ||
requiredSchema: StructType, | ||
filters: Seq[Filter], | ||
options: Map[String, String], | ||
hadoopConf: Configuration, | ||
metrics: Map[String, GpuMetric], | ||
alluxioPathReplacementMap: Option[Map[String, String]]) | ||
: PartitionedFile => Iterator[InternalRow] = { | ||
super.buildReaderWithPartitionValuesAndMetrics( | ||
sparkSession, | ||
prepareSchema(dataSchema), | ||
prepareSchema(partitionSchema), | ||
prepareSchema(requiredSchema), | ||
filters, | ||
options, | ||
hadoopConf, | ||
metrics, | ||
alluxioPathReplacementMap) | ||
} | ||
|
||
override def supportFieldName(name: String): Boolean = { | ||
if (columnMappingMode != NoMapping) true else super.supportFieldName(name) | ||
} | ||
} |
This file contains 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
This file contains 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
27 changes: 27 additions & 0 deletions
27
.../src/main/scala/com/nvidia/spark/rapids/delta/delta20x/GpuDelta20xParquetFileFormat.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2023, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.nvidia.spark.rapids.delta.delta20x | ||
|
||
import com.nvidia.spark.rapids.delta.GpuDeltaParquetFileFormat | ||
|
||
import org.apache.spark.sql.delta.DeltaColumnMappingMode | ||
import org.apache.spark.sql.types.StructType | ||
|
||
case class GpuDelta20xParquetFileFormat( | ||
override val columnMappingMode: DeltaColumnMappingMode, | ||
override val referenceSchema: StructType) extends GpuDeltaParquetFileFormat { | ||
} |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would we ever have replaced the file format and be tagging the plan again? I understand if we are just being cautious, but with the other checks for an exact class it feels like we would have made some horrible franken mix of CPU exec and GPU FileFormat to hit this. That or I don't really understand the context that this is called in. If that is the case, then we need some better docs for the method definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This checks for the GPU version of the format because
isSupportedFormat
is how ExternalSource figures out which source, of many, is supposed to handle a particular call. For example, one of the interfaces iscreateMultiFileReaderFactory
and that happens after we've already converted to a GPU format. I'll add some comments to the variousisSupported
methods of the provider interfaces to make this clearer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay could you add some docs to the isSupportedFormat declaration about who could call this and what is expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided this API is inherently confusing and fragile given it's looking at non-CPU formats. I ended up solving this via #9283 and will update this PR to be based on that. I'll also update the isSupportedFormat calls to check for the explicit CPU class we're expecting.