Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix misleading function alias name for RuntimeReplaceable
  • Loading branch information
cloud-fan committed Mar 11, 2022
commit 0fe1c710a5d91249556ac767a08b6f723e29b7ba
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ import org.apache.spark.util.Utils
* we use this to replace Every and Any with Min and Max respectively.
*/
object ReplaceExpressions extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan.transformAllExpressionsWithPruning(
def apply(plan: LogicalPlan): LogicalPlan = plan.transformWithPruning(
_.containsAnyPattern(RUNTIME_REPLACEABLE)) {
case e: RuntimeReplaceable => e.replacement
case p => p.mapExpressions(replace)
}

private def replace(e: Expression): Expression = e match {
case r: RuntimeReplaceable => replace(r.replacement)
case _ => e.mapChildren(replace)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ExplainSuite extends ExplainSuiteHelper with DisableAdaptiveExecutionSuite
keywords = "InMemoryRelation", "StorageLevel(disk, memory, deserialized, 1 replicas)")
}

test("optimized plan should show the rewritten aggregate expression") {
test("optimized plan should show the rewritten expression") {
withTempView("test_agg") {
sql(
"""
Expand All @@ -125,6 +125,13 @@ class ExplainSuite extends ExplainSuiteHelper with DisableAdaptiveExecutionSuite
"Aggregate [k#x], [k#x, every(v#x) AS every(v)#x, some(v#x) AS some(v)#x, " +
"any(v#x) AS any(v)#x]")
}

withTable("t") {
sql("CREATE TABLE t(col TIMESTAMP) USING parquet")
val df = sql("SELECT date_part('month', col) FROM t")
checkKeywordsExistsInExplain(df,
"Project [month(cast(col#x as date)) AS date_part(month, col)#x]")
}
}

test("explain inline tables cross-joins") {
Expand Down