From 50906c729ea0613489b530fb73e184a600a0ac74 Mon Sep 17 00:00:00 2001 From: huaxingao Date: Mon, 25 Jul 2022 08:12:46 -0700 Subject: [PATCH 1/2] [SPARK-39784][SQL][FOLLOW-UP] Use BinaryComparison instead of Predicate (if) for type check --- .../apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala b/sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala index 70c85def45d99..fa1f3c99386df 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala @@ -154,8 +154,8 @@ class V2ExpressionBuilder(e: Expression, isPredicate: Boolean = false) { val r = generateExpression(b.right) if (l.isDefined && r.isDefined) { b match { - case _: Predicate if isBinaryComparisonOperator(b.sqlOperator) && - l.get.isInstanceOf[LiteralValue[_]] && r.get.isInstanceOf[FieldReference] => + case _: BinaryComparison if l.get.isInstanceOf[LiteralValue[_]] && + r.get.isInstanceOf[FieldReference] => Some(new V2Predicate(flipComparisonOperatorName(b.sqlOperator), Array[V2Expression](r.get, l.get))) case _: Predicate => From bc951df4fdeeafb2ec82a305ca453cf71449c374 Mon Sep 17 00:00:00 2001 From: huaxingao Date: Mon, 25 Jul 2022 08:29:40 -0700 Subject: [PATCH 2/2] remove un-used method --- .../spark/sql/catalyst/util/V2ExpressionBuilder.scala | 7 ------- 1 file changed, 7 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala b/sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala index fa1f3c99386df..d5b75b3f02230 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala @@ -269,13 +269,6 @@ class V2ExpressionBuilder(e: Expression, isPredicate: Boolean = false) { case _ => None } - private def isBinaryComparisonOperator(operatorName: String): Boolean = { - operatorName match { - case ">" | "<" | ">=" | "<=" | "=" | "<=>" => true - case _ => false - } - } - private def flipComparisonOperatorName(operatorName: String): String = { operatorName match { case ">" => "<"