gatorsmile commented on code in PR #47611:
URL: https://github.com/apache/spark/pull/47611#discussion_r1720886166
##########
sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala:
##########
@@ -25,15 +27,44 @@ 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] = {
+
+ if (isPredicate) {
+ val translated = build()
+
+ val modifiedExprOpt = if (
+ SQLConf.get.getConf(SQLConf.DATA_SOURCE_DONT_ASSERT_ON_PREDICATE)
+ && translated.isDefined
+ && !translated.get.isInstanceOf[V2Predicate]) {
+
+ // When isPredicate is specified we always expect to receive predicate.
+ // If this is not the case, and we received something that is not a
predicate -
+ // don't fail query, act as if we didn't know how to translate it at
all.
Review Comment:
How about ?
```Scala
// If a predicate is expected but the translation yields something else,
// log a warning and proceed as if the translation was not possible.```
--
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]