Skip to content

ReplaceExpressions Logical Optimization

ReplaceExpressions is a base logical optimization that <>.

ReplaceExpressions is part of the Finish Analysis once-executed batch in the standard batches of the Logical Optimizer.

ReplaceExpressions is simply a <> for transforming <>, i.e. Rule[LogicalPlan].

[source, scala]

val query = sql("select ifnull(NULL, array('2')) from values 1") val analyzedPlan = query.queryExecution.analyzed scala> println(analyzedPlan.numberedTreeString) 00 Project [ifnull(null, array(2)) AS ifnull(NULL, array('2'))#3] 01 +- LocalRelation [col1#2]

import org.apache.spark.sql.catalyst.optimizer.ReplaceExpressions val optimizedPlan = ReplaceExpressions(analyzedPlan) scala> println(optimizedPlan.numberedTreeString) 00 Project [coalesce(cast(null as array), cast(array(2) as array)) AS ifnull(NULL, array('2'))#3] 01 +- LocalRelation [col1#2]

=== [[apply]] Executing Rule -- apply Method

[source, scala]

apply(plan: LogicalPlan): LogicalPlan

apply <> (in the input <>) and replaces a[RuntimeReplaceable] expression into its single child.

apply is part of the Rule abstraction.