Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zml1206 committed Jan 14, 2025
1 parent 20c31db commit 23f0b46
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ object RewriteWithExpression extends Rule[LogicalPlan] {
} else {
val alias = originalAttr match {
case Some(a) =>
Alias(child, a.name)(a.exprId)
Alias(child, a.name)(a.exprId, a.qualifier, Option(a.metadata))
case _ =>
val aliasName = if (SQLConf.get.getConf(SQLConf.USE_COMMON_EXPR_ID_FOR_ALIAS)) {
s"_common_expr_${id.id}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ class FilterPushdownSuite extends PlanTest {
comparePlans(optimized, originalQuery)
}

test("can't push without rewrite") {
val originalQuery =
testRelation
.select($"a" + $"b" as "e")
.where($"e" === 1)
.analyze

val optimized = Optimize.execute(originalQuery.analyze)
val correctAnswer =
testRelation
.where($"a" + $"b" === 1)
.select($"a" + $"b" as "e")
.analyze

comparePlans(optimized, correctAnswer)
}

test("nondeterministic: can always push down filter through project with deterministic field") {
val originalQuery = testRelation
.select($"a")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class OptimizerLoggingSuite extends PlanTest {
object Optimize extends RuleExecutor[LogicalPlan] {
val batches =
Batch("Optimizer Batch", FixedPoint(100),
PushPredicateThroughNonJoin) ::
PushPredicateThroughNonJoin, ColumnPruning, CollapseProject) ::
Batch("Batch Has No Effect", Once,
ColumnPruning) :: Nil
}
Expand Down Expand Up @@ -60,9 +60,9 @@ class OptimizerLoggingSuite extends PlanTest {
(ruleOrBatch => logMessages.exists(_.contains(ruleOrBatch))))
assert(events.forall(_.getLevel == expectedLevel))
val expectedMetrics = Seq(
"Total number of runs: 7",
"Total number of runs: 15",
"Total time:",
"Total number of effective runs: 3",
"Total number of effective runs: 2",
"Total time of effective runs:")
assert(expectedMetrics.forall(metrics => logMessages.exists(_.contains(metrics))))
}
Expand Down Expand Up @@ -113,17 +113,15 @@ class OptimizerLoggingSuite extends PlanTest {
ColumnPruning.ruleName,
CollapseProject.ruleName).reduce(_ + "," + _) ->
Seq(PushPredicateThroughNonJoin.ruleName,
ColumnPruning.ruleName,
CollapseProject.ruleName),
Seq(PushPredicateThroughNonJoin.ruleName,
ColumnPruning.ruleName).reduce(_ + "," + _) ->
Seq(PushPredicateThroughNonJoin.ruleName,
ColumnPruning.ruleName),
Seq(PushPredicateThroughNonJoin.ruleName),
CollapseProject.ruleName ->
Seq(CollapseProject.ruleName),
Seq(ColumnPruning.ruleName,
"DummyRule").reduce(_ + "," + _) ->
Seq(ColumnPruning.ruleName),
Seq(),
"DummyRule" -> Seq(),
"" -> Seq()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ case class OptimizeMetadataOnlyQuery(catalog: SessionCatalog) extends Rule[Logic
return plan
}

val p = plan.transform {
plan.transform {
case a @ Aggregate(_, aggExprs, child @ PhysicalOperation(
projectList, filters, PartitionedRelation(partAttrs, rel)), _) =>
// We only apply this optimization when only partitioned attributes are scanned.
Expand Down Expand Up @@ -86,7 +86,6 @@ case class OptimizeMetadataOnlyQuery(catalog: SessionCatalog) extends Rule[Logic
a
}
}
p
}

/**
Expand Down

0 comments on commit 23f0b46

Please sign in to comment.