-
Notifications
You must be signed in to change notification settings - Fork 292
Add delete support for iceberg's merge on read mode. #13725
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
Changes from 5 commits
00e5dfa
7c35565
9113cbb
5989558
538785b
25274b5
962c6df
59e7384
a40d432
9979e87
b94ecab
adde725
2e062f3
a5934aa
58a49ee
3faf020
0f3ab0f
e081526
d03960e
067052f
1c14a78
8945fc6
adb0670
c8a6821
bfe59f2
0529fe2
3a5222c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -208,4 +208,77 @@ object GpuIcebergPartitioner { | |||||||||||||||||||||||||||||
| }).toArray | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| private def addRowIdxToTable(table: Table): Table = { | ||||||||||||||||||||||||||||||
| val cols = new Array[CudfColumnVector](table.getNumberOfColumns + 1) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| val rowIdxCol = withResource(Scalar.fromInt(0)) { zero => | ||||||||||||||||||||||||||||||
| CudfColumnVector.sequence(zero, table.getRowCount.toInt) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| cols(table.getNumberOfColumns) = rowIdxCol | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| closeOnExcept(cols) { _ => | ||||||||||||||||||||||||||||||
| for (idx <- 0 until table.getNumberOfColumns) { | ||||||||||||||||||||||||||||||
| cols(idx) = table.getColumn(idx) | ||||||||||||||||||||||||||||||
|
liurenjie1024 marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| new Table(cols: _*) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
liurenjie1024 marked this conversation as resolved.
Outdated
Comment on lines
+194
to
+200
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Double-free bug: The Table constructor at line 199 takes ownership of the columns in the array. When
Suggested change
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def partitionBy(keys: ColumnarBatch, | ||||||||||||||||||||||||||||||
| keyType: Types.StructType, | ||||||||||||||||||||||||||||||
| keySparkType: StructType, | ||||||||||||||||||||||||||||||
| values: ColumnarBatch, | ||||||||||||||||||||||||||||||
| valueSparkType: Array[DataType]): Seq[ColumnarBatchWithPartition] = { | ||||||||||||||||||||||||||||||
| require(keys.numRows() == values.numRows(), | ||||||||||||||||||||||||||||||
| s"Keys row count ${keys.numRows()} not matching with values row count ${values.numRows()}") | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| val keySortOrders = (0 until keys.numCols()).map(OrderByArg.asc(_, true)) | ||||||||||||||||||||||||||||||
| val keyAggCols = (0 until keys.numCols()).toArray | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| withResource(GpuColumnVector.from(keys)) { keysTable => | ||||||||||||||||||||||||||||||
| withResource(GpuColumnVector.from(values)) { valuesTable => | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| val sortedKeysWithRowIdx = withResource(addRowIdxToTable(keysTable)) { t => | ||||||||||||||||||||||||||||||
| t.orderBy(keySortOrders: _*) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| val (partitionKeys, splits) = withResource(sortedKeysWithRowIdx) { _ => | ||||||||||||||||||||||||||||||
| val sortedUniqueKeyTable = { | ||||||||||||||||||||||||||||||
| val uniqueKeyTable = keysTable.groupBy(keyAggCols: _*) | ||||||||||||||||||||||||||||||
| .aggregate() | ||||||||||||||||||||||||||||||
| withResource(uniqueKeyTable) { _ => | ||||||||||||||||||||||||||||||
| uniqueKeyTable.orderBy(keySortOrders: _*) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| withResource(sortedUniqueKeyTable) { _ => | ||||||||||||||||||||||||||||||
| val partKeys = toPartitionKeys(keyType, keySparkType, sortedUniqueKeyTable) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| val splitIdCv = sortedKeysWithRowIdx.upperBound(sortedUniqueKeyTable, keySortOrders: _*) | ||||||||||||||||||||||||||||||
| val splitIds = withResource(splitIdCv) { cv => | ||||||||||||||||||||||||||||||
| GpuColumnVector.toIntArray(cv) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| val sortedRowIdxCol = sortedKeysWithRowIdx | ||||||||||||||||||||||||||||||
| .getColumn(keys.numCols()) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| val splits= withResource(valuesTable.gather(sortedRowIdxCol)) { sortedValuesTable => | ||||||||||||||||||||||||||||||
| sortedValuesTable.contiguousSplit(splitIds: _*) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| (partKeys, splits) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| partitionKeys.zip(splits).map { | ||||||||||||||||||||||||||||||
| case (partKey, split) => ColumnarBatchWithPartition( | ||||||||||||||||||||||||||||||
| SpillableColumnarBatch(split, valueSparkType, SpillPriorities | ||||||||||||||||||||||||||||||
| .ACTIVE_BATCHING_PRIORITY), partKey) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Copyright (c) 2025, 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.iceberg.utils | ||
|
|
||
| import scala.jdk.CollectionConverters._ | ||
|
|
||
| import com.nvidia.spark.rapids.Arm.closeOnExcept | ||
| import com.nvidia.spark.rapids.GpuColumnVector | ||
| import org.apache.iceberg.types.Types.StructType | ||
|
|
||
| import org.apache.spark.sql.vectorized.{ColumnarBatch, ColumnVector} | ||
|
|
||
| /** | ||
| * Gpu version of {@link org.apache.iceberg.util.StructProjection} | ||
| */ | ||
| class GpuStructProjection(val positionMap: Array[Int]) { | ||
| def project(batch: ColumnarBatch): ColumnarBatch = { | ||
| val cols = new Array[ColumnVector](positionMap.length) | ||
| closeOnExcept(cols) { _ => | ||
| for (idx <- positionMap.indices) { | ||
| cols(idx) = batch.column(positionMap(idx)) | ||
| .asInstanceOf[GpuColumnVector] | ||
| .incRefCount() | ||
| } | ||
|
|
||
| new ColumnarBatch(cols, batch.numRows()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| object GpuStructProjection { | ||
| def apply(dataType: StructType, projectType: StructType): GpuStructProjection = { | ||
| if (projectType.fields().asScala.exists(!_.`type`().isPrimitiveType)) { | ||
| throw new IllegalArgumentException( | ||
| "Gpu struct projection currently only supports primitive types") | ||
| } | ||
| val positionMap = new Array[Int](projectType.fields().size()) | ||
|
|
||
| for (idx <- positionMap.indices) { | ||
| val projectedField = projectType.fields().get(idx) | ||
| dataType.fields() | ||
| .asScala | ||
| .zipWithIndex | ||
| .find(p => p._1.fieldId() == projectedField.fieldId()) | ||
| match { | ||
| case Some(f) => positionMap(idx) = f._2 | ||
| case None => throw new IllegalArgumentException( | ||
| s"Field ${projectedField.name()} not found in projection source") | ||
| } | ||
| } | ||
|
|
||
| new GpuStructProjection(positionMap) | ||
| } | ||
| } |
This file was deleted.
This file was deleted.
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.
Please update after this PR is merged: #13688