-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement PURGE to remove DVs from Delta tables
## Description This PR introduces a `REORG TABLE ... APPLY (PURGE)` SQL command that can materialize soft-delete operations by DVs. The command works by rewriting and bin-packing (if applicable) only files that have DVs attached, which is different from the `OPTIMIZE` command where all files (with and without) DV will be bin-packed. To achieve this, we hack the `OPTIMIZE` logic so files of any size with DVs will be rewritten. Follow-up: - Set the correct commit info. Now the resulting version is marked as `optimize` rather than `purge`. - Clean up DVs from the filesystem. New tests. Closes #1732 Signed-off-by: Venki Korukanti <[email protected]> GitOrigin-RevId: 98ef156d62698986bfb54681e386971e2fec08b8
- Loading branch information
1 parent
dcad4fd
commit 9fac2e6
Showing
11 changed files
with
313 additions
and
31 deletions.
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
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
55 changes: 55 additions & 0 deletions
55
core/src/main/scala/org/apache/spark/sql/delta/commands/DeltaReorgTableCommand.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,55 @@ | ||
/* | ||
* Copyright (2021) The Delta Lake Project Authors. | ||
* | ||
* 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 org.apache.spark.sql.delta.commands | ||
|
||
import org.apache.spark.sql.delta.catalog.DeltaTableV2 | ||
|
||
import org.apache.spark.sql.{Row, SparkSession} | ||
import org.apache.spark.sql.catalyst.plans.logical.{IgnoreCachedData, LeafCommand, LogicalPlan, UnaryCommand} | ||
|
||
case class DeltaReorgTable(target: LogicalPlan)(val predicates: Seq[String]) extends UnaryCommand { | ||
|
||
def child: LogicalPlan = target | ||
|
||
protected def withNewChildInternal(newChild: LogicalPlan): LogicalPlan = | ||
copy(target = newChild)(predicates) | ||
|
||
override val otherCopyArgs: Seq[AnyRef] = predicates :: Nil | ||
} | ||
|
||
/** | ||
* The PURGE command. | ||
*/ | ||
case class DeltaReorgTableCommand(target: DeltaTableV2)(val predicates: Seq[String]) | ||
extends OptimizeTableCommandBase with LeafCommand with IgnoreCachedData { | ||
|
||
override val otherCopyArgs: Seq[AnyRef] = predicates :: Nil | ||
|
||
override def run(sparkSession: SparkSession): Seq[Row] = { | ||
val command = OptimizeTableCommand( | ||
Option(target.path.toString), | ||
target.catalogTable.map(_.identifier), | ||
predicates, | ||
options = Map.empty, | ||
optimizeContext = DeltaOptimizeContext( | ||
isPurge = true, | ||
minFileSize = Some(0L), | ||
maxDeletedRowsRatio = Some(0d)) | ||
)(zOrderBy = Nil) | ||
command.run(sparkSession) | ||
} | ||
} |
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
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
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
Oops, something went wrong.