@@ -94,25 +94,9 @@ object ConstantFolding extends Rule[LogicalPlan] {
9494 case q : LogicalPlan => q transformExpressionsDown {
9595 // Skip redundant folding of literals.
9696 case l : Literal => l
97- case e @ If (Literal (v, _), trueValue, falseValue) => if (v == true ) trueValue else falseValue
98- case e @ In (Literal (v, _), list) if (list.exists(c => c match {
99- case Literal (candidate, _) if (candidate == v) => true
100- case _ => false
101- })) => Literal (true , BooleanType )
102- case e if e.foldable => Literal (e.eval(null ), e.dataType)
103- }
104- }
105- }
106-
107- /**
108- * The expression may be constant value, due to one or more of its children expressions is null or
109- * not null constantly, replaces [[catalyst.expressions.Expression Expressions ]] with equivalent
110- * [[catalyst.expressions.Literal Literal ]] values if possible caused by that.
111- */
112- object NullPropagation extends Rule [LogicalPlan ] {
113- def apply (plan : LogicalPlan ): LogicalPlan = plan transform {
114- case q : LogicalPlan => q transformExpressionsUp {
115- case l : Literal => l
97+ case e @ Count (Literal (null , _)) => Literal (null , e.dataType)
98+ case e @ Sum (Literal (null , _)) => Literal (null , e.dataType)
99+ case e @ Average (Literal (null , _)) => Literal (null , e.dataType)
116100 case e @ IsNull (Literal (null , _)) => Literal (true , BooleanType )
117101 case e @ IsNull (Literal (_, _)) => Literal (false , BooleanType )
118102 case e @ IsNull (c @ Rand ) => Literal (false , BooleanType )
@@ -135,6 +119,11 @@ object NullPropagation extends Rule[LogicalPlan] {
135119 Coalesce (newChildren)
136120 }
137121 }
122+ case e @ If (Literal (v, _), trueValue, falseValue) => if (v == true ) trueValue else falseValue
123+ case e @ In (Literal (v, _), list) if (list.exists(c => c match {
124+ case Literal (candidate, _) if (candidate == v) => true
125+ case _ => false
126+ })) => Literal (true , BooleanType )
138127 // TODO put exceptional cases(Unary & Binary Expression) before here.
139128 case e : UnaryExpression => e.child match {
140129 case Literal (null , _) => Literal (null , e.dataType)
@@ -143,6 +132,7 @@ object NullPropagation extends Rule[LogicalPlan] {
143132 case Literal (null , _) :: right :: Nil => Literal (null , e.dataType)
144133 case left :: Literal (null , _) :: Nil => Literal (null , e.dataType)
145134 }
135+ case e if e.foldable => Literal (e.eval(null ), e.dataType)
146136 }
147137 }
148138}
0 commit comments