cloud-fan commented on a change in pull request #34738:
URL: https://github.com/apache/spark/pull/34738#discussion_r768923388
##########
File path: sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCV2Suite.scala
##########
@@ -120,56 +122,119 @@ 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 df5 = spark.read
- .table("h2.test.employee")
- .sort("SALARY")
- .limit(1)
- checkPushedLimit(df5, false, 0)
- checkAnswer(df5, Seq(Row(1, "cathy", 9000.00, 1200.0)))
-
val name = udf { (x: String) => x.matches("cat|dav|amy") }
val sub = udf { (x: String) => x.substring(0, 3) }
- val df6 = spark.read
+ val df5 = spark.read
.table("h2.test.employee")
.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(df6, false, 0)
- checkAnswer(df6, Seq(Row(10000.00, 1000.0, "amy")))
+ checkPushedLimit(df5, None)
+ checkAnswer(df5, Seq(Row(10000.00, 1000.0, "amy")))
}
- private def checkPushedLimit(df: DataFrame, pushed: Boolean, limit: Int):
Unit = {
+ private def checkPushedLimit(df: DataFrame, limit: Option[Int] = None,
+ sortValues: Seq[SortValue] = Nil): 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)
- }
+ assert(v1.pushedDownOperators.limit === limit)
+ assert(v1.pushedDownOperators.sortValues === sortValues)
}
}
}
+ test("simple scan with top N") {
+ val df1 = spark.read
+ .table("h2.test.employee")
+ .sort("salary")
+ .limit(1)
+ checkPushedLimit(df1, Some(1), createSortValues())
+ checkAnswer(df1, Seq(Row(1, "cathy", 9000.00, 1200.0)))
+
+ val df2 = spark.read.table("h2.test.employee")
+ .where($"dept" === 1).orderBy($"salary").limit(1)
+ checkPushedLimit(df2, Some(1), createSortValues())
+ checkAnswer(df2, Seq(Row(1, "cathy", 9000.00, 1200.0)))
+
+ val df3 = spark.read
+ .option("partitionColumn", "dept")
+ .option("lowerBound", "0")
+ .option("upperBound", "2")
+ .option("numPartitions", "2")
+ .table("h2.test.employee")
+ .filter($"dept" > 1)
+ .orderBy($"salary".desc)
+ .limit(1)
+ checkPushedLimit(
+ df3, Some(1), createSortValues(SortDirection.DESCENDING,
NullOrdering.NULLS_LAST))
+ checkAnswer(df3, Seq(Row(2, "alex", 12000.00, 1200.0)))
+
+ val df4 =
+ sql("SELECT name FROM h2.test.employee WHERE dept > 1 ORDER BY salary
NULLS LAST LIMIT 1")
+ val scan = df4.queryExecution.optimizedPlan.collectFirst {
+ case s: DataSourceV2ScanRelation => s
+ }.get
+ assert(scan.schema.names.sameElements(Seq("NAME", "SALARY")))
+ checkPushedLimit(df4, Some(1), createSortValues(nullOrdering =
NullOrdering.NULLS_LAST))
+ checkAnswer(df4, Seq(Row("david")))
+
+ val df5 = spark.read.table("h2.test.employee")
+ .where($"dept" === 1).orderBy($"salary")
+ checkPushedLimit(df5, None, Seq.empty)
+ checkAnswer(df5, Seq(Row(1, "cathy", 9000.00, 1200.0), Row(1, "amy",
10000.00, 1000.0)))
+
+ val df6 = spark.read.table("h2.test.employee")
+ .where($"dept" === 1).limit(1)
Review comment:
This has been covered by the limit pushdown tests already.
--
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]