GetCurrentDatabase Logical Optimization
GetCurrentDatabase
is a base logical optimization that gives the current database for current_database
SQL function.
GetCurrentDatabase
is part of the Finish Analysis once-executed batch in the standard batches of the Catalyst Optimizer.
GetCurrentDatabase
is simply a Catalyst rule for transforming logical plans, i.e. Rule[LogicalPlan]
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
val q = sql("SELECT current_database() AS db") val analyzedPlan = q.queryExecution.analyzed scala> println(analyzedPlan.numberedTreeString) 00 Project [current_database() AS db#22] 01 +- OneRowRelation import org.apache.spark.sql.catalyst.optimizer.GetCurrentDatabase val afterGetCurrentDatabase = GetCurrentDatabase(spark.sessionState.catalog)(analyzedPlan) scala> println(afterGetCurrentDatabase.numberedTreeString) 00 Project [default AS db#22] 01 +- OneRowRelation |
Note
|
You can access the current database in Scala using
|
Executing Rule — apply
Method
1 2 3 4 5 |
apply(plan: LogicalPlan): LogicalPlan |
Note
|
apply is part of the Rule Contract to execute (apply) a rule on a TreeNode (e.g. LogicalPlan).
|
apply
…FIXME