beliefer commented on a change in pull request #34738:
URL: https://github.com/apache/spark/pull/34738#discussion_r762066369



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCV2Suite.scala
##########
@@ -138,11 +140,79 @@ class JDBCV2Suite extends QueryTest with 
SharedSparkSession with ExplainSuiteHel
     checkPushedLimit(df4, false, 0)
     checkAnswer(df4, Seq(Row(1, 19000.00)))
 
+    val name = udf { (x: String) => x.matches("cat|dav|amy") }
+    val sub = udf { (x: String) => x.substring(0, 3) }
     val df5 = spark.read
       .table("h2.test.employee")
-      .sort("SALARY")
+      .select($"SALARY", $"BONUS", sub($"NAME").as("shortName"))
+      .filter(name($"shortName"))
       .limit(1)
+    // LIMIT is pushed down only if all the filters are pushed down
     checkPushedLimit(df5, false, 0)
+    checkAnswer(df5, Seq(Row(10000.00, 1000.0, "amy")))
+  }
+
+  private def checkPushedLimit(df: DataFrame, pushed: Boolean, limit: Int): 
Unit = {
+    df.queryExecution.optimizedPlan.collect {
+      case relation: DataSourceV2ScanRelation => relation.scan match {
+        case v1: V1ScanWrapper =>
+          if (pushed) {
+            assert(v1.pushedDownOperators.limit === Some(limit))
+          } else {
+            assert(v1.pushedDownOperators.limit.isEmpty)
+          }
+      }
+    }
+  }
+
+  test("simple scan with top N") {
+    val df1 = spark.read.table("h2.test.employee")
+      .where($"dept" === 1).orderBy($"salary").limit(1)

Review comment:
       OK




-- 
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