Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix
  • Loading branch information
wangyum committed Dec 29, 2020
commit 931c66cd1cd771a7b797cc45651e276436c16c6c
Original file line number Diff line number Diff line change
Expand Up @@ -549,18 +549,27 @@ object PushFoldableIntoBranches extends Rule[LogicalPlan] with PredicateHelper {
}

// Not all UnaryExpression support push into (if / case) branches, e.g. Alias.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all UnaryExpression can be pushed into (if / case) branches, e.g. Alias.

private def supportedUnaryExpression(u: UnaryExpression): Boolean = u match {
case IsNull(_) | IsNotNull(_) => true
case _: UnaryMathExpression | Abs(_) | Bin(_) | Factorial(_) | Hex(_) => true
case _: String2StringExpression | Ascii(_) | Base64(_) | BitLength(_) | Chr(_) | Length(_) =>
private def supportedUnaryExpression(e: UnaryExpression): Boolean = e match {
case _: IsNull | _: IsNotNull => true
case _: UnaryMathExpression | _: Abs | _: Bin | _: Factorial | _: Hex => true
case _: String2StringExpression | _: Ascii | _: Base64 | _: BitLength | _: Chr | _: Length =>
true
case _: CastBase => true
case _: GetDateField | LastDay(_) => true
case _: GetDateField | _: LastDay => true
case _: ExtractIntervalPart => true
case _: ArraySetLike => true
case _ => false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's include ExtractValue as well, which is common with nested fields.

}

private def supportedBinaryExpression(e: BinaryExpression): Boolean = e match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add comments as well.

case _: BinaryComparison | _: StringPredicate | _: StringRegexExpression => true
case _: BinaryArithmetic => true
case _: BinaryMathExpression => true
case _: AddMonths | _: DateAdd | _: DateAddInterval | _: DateDiff | _: DateSub => true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the property should the expression have to be here? For example, can I add DateAddYMInterval, TimestampAddYMInterval and TimeAdd?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I opened the JIRA for that: SPARK-34841

case _: FindInSet | _: RoundBase => true
case _ => false
}

def apply(plan: LogicalPlan): LogicalPlan = plan transform {
case q: LogicalPlan => q transformExpressionsUp {
case u @ UnaryExpression(i @ If(_, trueValue, falseValue))
Expand All @@ -576,13 +585,15 @@ object PushFoldableIntoBranches extends Rule[LogicalPlan] with PredicateHelper {
elseValue.map(e => u.withNewChildren(Array(e))))

case b @ BinaryExpression(i @ If(_, trueValue, falseValue), right)
if right.foldable && atMostOneUnfoldable(Seq(trueValue, falseValue)) =>
if supportedBinaryExpression(b) && right.foldable &&
atMostOneUnfoldable(Seq(trueValue, falseValue)) =>
i.copy(
trueValue = b.withNewChildren(Array(trueValue, right)),
falseValue = b.withNewChildren(Array(falseValue, right)))

case b @ BinaryExpression(left, i @ If(_, trueValue, falseValue))
if left.foldable && atMostOneUnfoldable(Seq(trueValue, falseValue)) =>
if supportedBinaryExpression(b) && left.foldable &&
atMostOneUnfoldable(Seq(trueValue, falseValue)) =>
i.copy(
trueValue = b.withNewChildren(Array(left, trueValue)),
falseValue = b.withNewChildren(Array(left, falseValue)))
Expand Down