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 0bcff44a1784 [SPARK-51222][SQL] Optimize ReplaceCurrentLike 0bcff44a1784 is described below commit 0bcff44a17843d0bdfbd05a2288b72c1a3fec9b7 Author: Szehon Ho <szehon.apa...@gmail.com> AuthorDate: Sun Feb 16 17:24:24 2025 +0800 [SPARK-51222][SQL] Optimize ReplaceCurrentLike ### What changes were proposed in this pull request? Improve ReplaceCurrentLike FinishAnalysis rule. This was found as a result of debugging SPARK-51119. ### Why are the changes needed? The rule calls the catalog unnecessarily, and this can be done lazily only if it is resolving current_catalog() and current_database() expressions. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Existing unit test ### Was this patch authored or co-authored using generative AI tooling? No Closes #49963 from szehon-ho/SPARK-51222. Authored-by: Szehon Ho <szehon.apa...@gmail.com> Signed-off-by: beliefer <belie...@163.com> --- .../apache/spark/sql/catalyst/optimizer/finishAnalysis.scala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/finishAnalysis.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/finishAnalysis.scala index 8f94253c4694..4e6a976d8f0d 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/finishAnalysis.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/finishAnalysis.scala @@ -142,22 +142,22 @@ object ComputeCurrentTime extends Rule[LogicalPlan] { } /** - * Replaces the expression of CurrentDatabase with the current database name. - * Replaces the expression of CurrentCatalog with the current catalog name. + * Replaces the expression of CurrentDatabase, CurrentCatalog, and CurrentUser + * with the current values. */ case class ReplaceCurrentLike(catalogManager: CatalogManager) extends Rule[LogicalPlan] { def apply(plan: LogicalPlan): LogicalPlan = { import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._ - val currentNamespace = catalogManager.currentNamespace.quoted - val currentCatalog = catalogManager.currentCatalog.name() - val currentUser = CurrentUserContext.getCurrentUser plan.transformAllExpressionsWithPruning(_.containsPattern(CURRENT_LIKE)) { case CurrentDatabase() => + val currentNamespace = catalogManager.currentNamespace.quoted Literal.create(currentNamespace, StringType) case CurrentCatalog() => + val currentCatalog = catalogManager.currentCatalog.name() Literal.create(currentCatalog, StringType) case CurrentUser() => + val currentUser = CurrentUserContext.getCurrentUser Literal.create(currentUser, StringType) } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org