This is an automated email from the ASF dual-hosted git repository.
beliefer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 75267bcb4351 [SPARK-53715][SQL] Refactor getWritePrivileges for
MergeIntoTable
75267bcb4351 is described below
commit 75267bcb4351adb25fed309ff30a9a1869a4ebe5
Author: beliefer <[email protected]>
AuthorDate: Fri Sep 26 15:10:24 2025 +0800
[SPARK-53715][SQL] Refactor getWritePrivileges for MergeIntoTable
### What changes were proposed in this pull request?
This PR proposes to refactor `getWritePrivileges` for `MergeIntoTable`.
### Why are the changes needed?
The object `MergeIntoTable` has a function `getWritePrivileges`.
There exists some optimization points.
**Eliminating variability**: using `toSet` instead of mutable `HashSet`
**Reduce intermediate variables**: use chain calls
**Improving readability**: The collect method expresses the intention of
"transforming and filtering" more clearly
**Performance optimization**: Avoid unnecessary creation of intermediate
sets
### Does this PR introduce _any_ user-facing change?
'No'.
### How was this patch tested?
GA tests.
### Was this patch authored or co-authored using generative AI tooling?
'No'.
Closes #52451 from beliefer/SPARK-53715.
Authored-by: beliefer <[email protected]>
Signed-off-by: beliefer <[email protected]>
---
.../spark/sql/catalyst/plans/logical/v2Commands.scala | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala
index b7bc8ed6e4b0..a5cba44aac6a 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala
@@ -915,13 +915,14 @@ object MergeIntoTable {
matchedActions: Iterable[MergeAction],
notMatchedActions: Iterable[MergeAction],
notMatchedBySourceActions: Iterable[MergeAction]):
Seq[TableWritePrivilege] = {
- val privileges =
scala.collection.mutable.HashSet.empty[TableWritePrivilege]
- (matchedActions.iterator ++ notMatchedActions ++
notMatchedBySourceActions).foreach {
- case _: DeleteAction => privileges.add(TableWritePrivilege.DELETE)
- case _: UpdateAction | _: UpdateStarAction =>
privileges.add(TableWritePrivilege.UPDATE)
- case _: InsertAction | _: InsertStarAction =>
privileges.add(TableWritePrivilege.INSERT)
- }
- privileges.toSeq
+ (matchedActions ++ notMatchedActions ++ notMatchedBySourceActions)
+ .collect {
+ case _: DeleteAction => TableWritePrivilege.DELETE
+ case _: UpdateAction | _: UpdateStarAction =>
TableWritePrivilege.UPDATE
+ case _: InsertAction | _: InsertStarAction =>
TableWritePrivilege.INSERT
+ }
+ .toSet
+ .toSeq
}
def schemaChanges(
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]