Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit b779c93

Browse files
gatorsmilecloud-fan
authored andcommitted
[SPARK-22815][SQL] Keep PromotePrecision in Optimized Plans
## What changes were proposed in this pull request? We could get incorrect results by running DecimalPrecision twice. This PR resolves the original found in apache#15048 and apache#14797. After this PR, it becomes easier to change it back using `children` instead of using `innerChildren`. ## How was this patch tested? The existing test. Author: gatorsmile <[email protected]> Closes apache#20000 from gatorsmile/keepPromotePrecision.
1 parent 2831571 commit b779c93

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/StreamingJoinHelper.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package org.apache.spark.sql.catalyst.analysis
2020
import scala.util.control.NonFatal
2121

2222
import org.apache.spark.internal.Logging
23-
import org.apache.spark.sql.catalyst.expressions.{Add, AttributeReference, AttributeSet, Cast, CheckOverflow, Expression, ExpressionSet, GreaterThan, GreaterThanOrEqual, LessThan, LessThanOrEqual, Literal, Multiply, PreciseTimestampConversion, PredicateHelper, Subtract, TimeAdd, TimeSub, UnaryMinus}
23+
import org.apache.spark.sql.catalyst.expressions._
2424
import org.apache.spark.sql.catalyst.planning.ExtractEquiJoinKeys
2525
import org.apache.spark.sql.catalyst.plans.logical.{EventTimeWatermark, LogicalPlan}
2626
import org.apache.spark.sql.catalyst.plans.logical.EventTimeWatermark._
@@ -238,6 +238,8 @@ object StreamingJoinHelper extends PredicateHelper with Logging {
238238
collect(child, !negate)
239239
case CheckOverflow(child, _) =>
240240
collect(child, negate)
241+
case PromotePrecision(child) =>
242+
collect(child, negate)
241243
case Cast(child, dataType, _) =>
242244
dataType match {
243245
case _: NumericType | _: TimestampType => collect(child, negate)

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/decimalExpressions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ case class MakeDecimal(child: Expression, precision: Int, scale: Int) extends Un
7070
case class PromotePrecision(child: Expression) extends UnaryExpression {
7171
override def dataType: DataType = child.dataType
7272
override def eval(input: InternalRow): Any = child.eval(input)
73+
/** Just a simple pass-through for code generation. */
7374
override def genCode(ctx: CodegenContext): ExprCode = child.genCode(ctx)
7475
override protected def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = ev.copy("")
7576
override def prettyName: String = "promote_precision"
7677
override def sql: String = child.sql
78+
override lazy val canonicalized: Expression = child.canonicalized
7779
}
7880

7981
/**

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,6 @@ object SimplifyCasts extends Rule[LogicalPlan] {
614614
object RemoveDispensableExpressions extends Rule[LogicalPlan] {
615615
def apply(plan: LogicalPlan): LogicalPlan = plan transformAllExpressions {
616616
case UnaryPositive(child) => child
617-
case PromotePrecision(child) => child
618617
}
619618
}
620619

0 commit comments

Comments
 (0)