Skip to content

Commit e2b0e96

Browse files
committed
make code simpler
1 parent 59fada7 commit e2b0e96

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,8 @@ object SimplifyConditionals extends Rule[LogicalPlan] with PredicateHelper {
415415
val (h, t) = branches.span(_._1 != TrueLiteral)
416416
CaseWhen( h :+ t.head, None)
417417

418-
case CaseWhen(branches, elseValue) if branches.length == 1 =>
419-
// Using pattern matching like `CaseWhen((cond, branchValue) :: Nil, elseValue)` will not
420-
// work since the implementation of `branches` can be `ArrayBuffer`. A full test is in
421-
// "SPARK-24892: simplify `CaseWhen` to `If` when there is only one branch",
422-
// `SQLQuerySuite.scala`.
423-
val cond = branches.head._1
424-
val trueValue = branches.head._2
425-
val falseValue = elseValue.getOrElse(Literal(null, trueValue.dataType))
426-
If(cond, trueValue, falseValue)
418+
case CaseWhen(Seq((cond, trueValue)), elseValue) =>
419+
If(cond, trueValue, elseValue.getOrElse(Literal(null, trueValue.dataType)))
427420
}
428421
}
429422
}

0 commit comments

Comments
 (0)