gengliangwang commented on code in PR #47611:
URL: https://github.com/apache/spark/pull/47611#discussion_r1723898835


##########
sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala:
##########
@@ -25,15 +27,43 @@ import org.apache.spark.sql.connector.expressions.{Cast => 
V2Cast, Expression =>
 import org.apache.spark.sql.connector.expressions.aggregate.{AggregateFunc, 
Avg, Count, CountStar, GeneralAggregateFunc, Max, Min, Sum, 
UserDefinedAggregateFunc}
 import org.apache.spark.sql.connector.expressions.filter.{AlwaysFalse, 
AlwaysTrue, And => V2And, Not => V2Not, Or => V2Or, Predicate => V2Predicate}
 import org.apache.spark.sql.execution.datasources.PushableExpression
+import org.apache.spark.sql.internal.SQLConf
 import org.apache.spark.sql.types.{BooleanType, DataType, IntegerType, 
StringType}
 
 /**
  * The builder to generate V2 expressions from catalyst expressions.
  */
-class V2ExpressionBuilder(e: Expression, isPredicate: Boolean = false) {
+class V2ExpressionBuilder(e: Expression, isPredicate: Boolean = false) extends 
Logging  {
 
   def build(): Option[V2Expression] = generateExpression(e, isPredicate)
 
+  def buildPredicate(): Option[V2Predicate] = {

Review Comment:
   let's simplify the logic a little bit:
   ```
     def buildPredicate(): Option[V2Predicate] = {
       if (isPredicate) {
         val translated = build()
   
         if (translated.isDefined) {
           if 
(SQLConf.get.getConf(SQLConf.DATA_SOURCE_DONT_ASSERT_ON_PREDICATE)) {
             logWarning(log"Predicate expected but got class: ${MDC(EXPR, 
translated.get.describe())}")
             assert(translated.get.isInstanceOf[V2Predicate])
             Some(translated.asInstanceOf[V2Predicate])
           } else {
             translated.collectFirst({ case p: V2Predicate => p })
           }
         } else {
           None
         }
       } else {
         None
       }
     }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to