cloud-fan commented on a change in pull request #34738:
URL: https://github.com/apache/spark/pull/34738#discussion_r767464502



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCV2Suite.scala
##########
@@ -120,52 +122,124 @@ class JDBCV2Suite extends QueryTest with 
SharedSparkSession with ExplainSuiteHel
       .table("h2.test.employee")
       .filter($"dept" > 1)
       .limit(1)
-    checkPushedLimit(df2, true, 1)
+    checkPushedLimit(df2, Some(1))
     checkAnswer(df2, Seq(Row(2, "alex", 12000.00, 1200.0)))
 
     val df3 = sql("SELECT name FROM h2.test.employee WHERE dept > 1 LIMIT 1")
     val scan = df3.queryExecution.optimizedPlan.collectFirst {
       case s: DataSourceV2ScanRelation => s
     }.get
     assert(scan.schema.names.sameElements(Seq("NAME")))
-    checkPushedLimit(df3, true, 1)
+    checkPushedLimit(df3, Some(1))
     checkAnswer(df3, Seq(Row("alex")))
 
     val df4 = spark.read
       .table("h2.test.employee")
       .groupBy("DEPT").sum("SALARY")
       .limit(1)
-    checkPushedLimit(df4, false, 0)
+    checkPushedLimit(df4, None)
     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, None)
+    checkAnswer(df5, Seq(Row(10000.00, 1000.0, "amy")))
+  }
+
+  private def checkPushedLimit(df: DataFrame, limit: Option[Int]): Unit = {

Review comment:
       shall we merge `checkPushedTopN` into this? `def checkPushedLimit(df: 
DataFrame, limit: Option[Int], sortValues: Seq[SortValue] = Nil)`




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