gatorsmile commented on code in PR #47611:
URL: https://github.com/apache/spark/pull/47611#discussion_r1706406867
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -1487,6 +1487,13 @@ object SQLConf {
.intConf
.createWithDefault(200)
+ val DATA_SOURCE_DONT_ASSERT_ON_PREDICATE =
+ buildConf("spark.sql.dataSource.skipAssertOnPredicatePushdown")
+ .internal()
+ .doc("Enable skipping assert when expression in not translated to
predicate.")
+ .booleanConf
+ .createWithDefault(true)
Review Comment:
In test mode, we should not skip the assertions so that we can still capture
the bug.
##########
sql/core/src/test/scala/org/apache/spark/sql/connector/PushablePredicateSuite.scala:
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.connector
+
+import org.apache.spark.sql.QueryTest
+import org.apache.spark.sql.catalyst.expressions.Literal
+import org.apache.spark.sql.execution.datasources.v2.PushablePredicate
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.test.SharedSparkSession
+
+class PushablePredicateSuite extends QueryTest with SharedSparkSession {
+
+ test("PushablePredicate returns None") {
+ withSQLConf(SQLConf.DATA_SOURCE_DONT_ASSERT_ON_PREDICATE.key -> "true") {
+ val pushable = PushablePredicate.unapply(Literal.create("string"))
+ assert(!pushable.isDefined)
+ }
+ }
+
+ test("PushablePredicate no log on success") {
+ withSQLConf(SQLConf.DATA_SOURCE_DONT_ASSERT_ON_PREDICATE.key -> "true") {
+ val pushable = PushablePredicate.unapply(Literal.create(true))
+ assert(pushable.isDefined)
+ }
+ }
+
+ test("PushablePredicate throws") {
+ withSQLConf(SQLConf.DATA_SOURCE_DONT_ASSERT_ON_PREDICATE.key -> "false") {
+ intercept[java.lang.AssertionError] {
+ val pushable = PushablePredicate.unapply(Literal.create("string"))
+ }
+ }
+ }
+}
Review Comment:
add one more line
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala:
##########
@@ -650,10 +651,22 @@ private[sql] object DataSourceV2Strategy extends Logging {
/**
* Get the expression of DS V2 to represent catalyst predicate that can be
pushed down.
*/
-object PushablePredicate {
- def unapply(e: Expression): Option[Predicate] =
- new V2ExpressionBuilder(e, true).build().map { v =>
+object PushablePredicate extends Logging {
+
+ def unapply(e: Expression): Option[Predicate] = {
+ val exprOpt = new V2ExpressionBuilder(e, true).build()
+
+ val modifiedExprOpt =
+ if (SQLConf.get.getConf(SQLConf.DATA_SOURCE_DONT_ASSERT_ON_PREDICATE) &&
+ exprOpt.isDefined &&
+ !exprOpt.get.isInstanceOf[Predicate]) {
+ logWarning(log"Predicate expected but got class: ${MDC(EXPR,
exprOpt.get.describe())}")
+ None
+ } else { exprOpt }
Review Comment:
the indentation is not right. See the guideline
https://github.com/databricks/scala-style-guide#spacing-and-indentation
--
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]