LuciferYang commented on code in PR #52451:
URL: https://github.com/apache/spark/pull/52451#discussion_r2379018128
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala:
##########
@@ -915,12 +915,13 @@ 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)
- }
+ val privileges = (matchedActions ++ notMatchedActions ++
notMatchedBySourceActions)
+ .collect {
+ case _: DeleteAction => TableWritePrivilege.DELETE
+ case _: UpdateAction | _: UpdateStarAction =>
TableWritePrivilege.UPDATE
+ case _: InsertAction | _: InsertStarAction =>
TableWritePrivilege.INSERT
+ }
+ .toSet
Review Comment:
If performance is the top priority, I recommend sticking to the original way
of writing, as it converts the original data into a Set with just a single
traversal. In contrast, although the new method appears more concise, it
requires two traversals to put the data into the Set.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]