@@ -94,25 +94,9 @@ object ConstantFolding extends Rule[LogicalPlan] {
94
94
case q : LogicalPlan => q transformExpressionsDown {
95
95
// Skip redundant folding of literals.
96
96
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)
116
100
case e @ IsNull (Literal (null , _)) => Literal (true , BooleanType )
117
101
case e @ IsNull (Literal (_, _)) => Literal (false , BooleanType )
118
102
case e @ IsNull (c @ Rand ) => Literal (false , BooleanType )
@@ -135,6 +119,11 @@ object NullPropagation extends Rule[LogicalPlan] {
135
119
Coalesce (newChildren)
136
120
}
137
121
}
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 )
138
127
// TODO put exceptional cases(Unary & Binary Expression) before here.
139
128
case e : UnaryExpression => e.child match {
140
129
case Literal (null , _) => Literal (null , e.dataType)
@@ -143,6 +132,7 @@ object NullPropagation extends Rule[LogicalPlan] {
143
132
case Literal (null , _) :: right :: Nil => Literal (null , e.dataType)
144
133
case left :: Literal (null , _) :: Nil => Literal (null , e.dataType)
145
134
}
135
+ case e if e.foldable => Literal (e.eval(null ), e.dataType)
146
136
}
147
137
}
148
138
}
0 commit comments