Skip to content

Commit 867b1a9

Browse files
committed
Move topN pushdown test into BaseConnectorTest
Previously, there was no test to exercise topN pushdown behavior for non-JDBC connectors, regardless of whether they declare support for the `SUPPORTS_TOPN_PUSHDOWN` TestingConnectorBehavior.
1 parent 3248961 commit 867b1a9

File tree

2 files changed

+71
-58
lines changed

2 files changed

+71
-58
lines changed

plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/BaseJdbcConnectorTest.java

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -973,70 +973,15 @@ public void testTopNPushdownDisabled()
973973
}
974974

975975
@Test
976+
@Override
976977
public void testTopNPushdown()
977978
{
979+
super.testTopNPushdown();
980+
978981
if (!hasBehavior(SUPPORTS_TOPN_PUSHDOWN)) {
979-
assertThat(query("SELECT orderkey FROM orders ORDER BY orderkey LIMIT 10"))
980-
.ordered()
981-
.isNotFullyPushedDown(TopNNode.class);
982982
return;
983983
}
984984

985-
assertThat(query("SELECT orderkey FROM orders ORDER BY orderkey LIMIT 10"))
986-
.ordered()
987-
.isFullyPushedDown();
988-
989-
assertThat(query("SELECT orderkey FROM orders ORDER BY orderkey DESC LIMIT 10"))
990-
.ordered()
991-
.isFullyPushedDown();
992-
993-
// multiple sort columns with different orders
994-
assertThat(query("SELECT * FROM orders ORDER BY shippriority DESC, totalprice ASC LIMIT 10"))
995-
.ordered()
996-
.isFullyPushedDown();
997-
998-
// TopN over aggregation column
999-
if (hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN)) {
1000-
assertThat(query("SELECT sum(totalprice) AS total FROM orders GROUP BY custkey ORDER BY total DESC LIMIT 10"))
1001-
.ordered()
1002-
.isFullyPushedDown();
1003-
}
1004-
1005-
// TopN over TopN
1006-
assertThat(query("SELECT orderkey, totalprice FROM (SELECT orderkey, totalprice FROM orders ORDER BY 1, 2 LIMIT 10) ORDER BY 2, 1 LIMIT 5"))
1007-
.ordered()
1008-
.isFullyPushedDown();
1009-
1010-
assertThat(query("" +
1011-
"SELECT orderkey, totalprice " +
1012-
"FROM (SELECT orderkey, totalprice FROM (SELECT orderkey, totalprice FROM orders ORDER BY 1, 2 LIMIT 10) " +
1013-
"ORDER BY 2, 1 LIMIT 5) ORDER BY 1, 2 LIMIT 3"))
1014-
.ordered()
1015-
.isFullyPushedDown();
1016-
1017-
// TopN over limit - use high limit for deterministic result
1018-
assertThat(query("SELECT orderkey, totalprice FROM (SELECT orderkey, totalprice FROM orders LIMIT 15000) ORDER BY totalprice ASC LIMIT 5"))
1019-
.ordered()
1020-
.isFullyPushedDown();
1021-
1022-
// TopN over limit with filter
1023-
assertThat(query("" +
1024-
"SELECT orderkey, totalprice " +
1025-
"FROM (SELECT orderkey, totalprice FROM orders WHERE orderdate = DATE '1995-09-16' LIMIT 20) " +
1026-
"ORDER BY totalprice ASC LIMIT 5"))
1027-
.ordered()
1028-
.isFullyPushedDown();
1029-
1030-
// TopN over aggregation with filter
1031-
if (hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN)) {
1032-
assertThat(query("" +
1033-
"SELECT * " +
1034-
"FROM (SELECT SUM(totalprice) as sum, custkey AS total FROM orders GROUP BY custkey HAVING COUNT(*) > 3) " +
1035-
"ORDER BY sum DESC LIMIT 10"))
1036-
.ordered()
1037-
.isFullyPushedDown();
1038-
}
1039-
1040985
// TopN over LEFT join (enforces SINGLE TopN cannot be pushed below OUTER side of join)
1041986
// We expect PARTIAL TopN on the LEFT side of join to be pushed down.
1042987
assertThat(query(

testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
import io.trino.sql.planner.Plan;
3939
import io.trino.sql.planner.assertions.PlanMatchPattern;
4040
import io.trino.sql.planner.plan.AggregationNode;
41+
import io.trino.sql.planner.plan.ExchangeNode;
4142
import io.trino.sql.planner.plan.FilterNode;
43+
import io.trino.sql.planner.plan.JoinNode;
4244
import io.trino.sql.planner.plan.LimitNode;
4345
import io.trino.sql.planner.plan.OutputNode;
4446
import io.trino.sql.planner.plan.ProjectNode;
@@ -495,6 +497,72 @@ public void testLimitPushdown()
495497
topnOverTableScan);
496498
}
497499

500+
@Test
501+
public void testTopNPushdown()
502+
{
503+
if (!hasBehavior(SUPPORTS_TOPN_PUSHDOWN)) {
504+
assertThat(query("SELECT orderkey FROM orders ORDER BY orderkey LIMIT 10"))
505+
.ordered()
506+
.isNotFullyPushedDown(TopNNode.class);
507+
return;
508+
}
509+
510+
assertThat(query("SELECT orderkey FROM orders ORDER BY orderkey LIMIT 10"))
511+
.ordered()
512+
.isFullyPushedDown();
513+
514+
assertThat(query("SELECT orderkey FROM orders ORDER BY orderkey DESC LIMIT 10"))
515+
.ordered()
516+
.isFullyPushedDown();
517+
518+
// multiple sort columns with different orders
519+
assertThat(query("SELECT * FROM orders ORDER BY shippriority DESC, totalprice ASC LIMIT 10"))
520+
.ordered()
521+
.isFullyPushedDown();
522+
523+
// TopN over aggregation column
524+
if (hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN)) {
525+
assertThat(query("SELECT sum(totalprice) AS total FROM orders GROUP BY custkey ORDER BY total DESC LIMIT 10"))
526+
.ordered()
527+
.isFullyPushedDown();
528+
}
529+
530+
// TopN over TopN
531+
assertThat(query("SELECT orderkey, totalprice FROM (SELECT orderkey, totalprice FROM orders ORDER BY 1, 2 LIMIT 10) ORDER BY 2, 1 LIMIT 5"))
532+
.ordered()
533+
.isFullyPushedDown();
534+
535+
assertThat(query("" +
536+
"SELECT orderkey, totalprice " +
537+
"FROM (SELECT orderkey, totalprice FROM (SELECT orderkey, totalprice FROM orders ORDER BY 1, 2 LIMIT 10) " +
538+
"ORDER BY 2, 1 LIMIT 5) ORDER BY 1, 2 LIMIT 3"))
539+
.ordered()
540+
.isFullyPushedDown();
541+
542+
// TopN over limit - use high limit for deterministic result
543+
assertThat(query("SELECT orderkey, totalprice FROM (SELECT orderkey, totalprice FROM orders LIMIT 15000) ORDER BY totalprice ASC LIMIT 5"))
544+
.ordered()
545+
.isFullyPushedDown();
546+
547+
// TopN over limit with filter
548+
assertThat(query("" +
549+
"SELECT orderkey, totalprice " +
550+
"FROM (SELECT orderkey, totalprice FROM orders WHERE orderdate = DATE '1995-09-16' LIMIT 20) " +
551+
"ORDER BY totalprice ASC LIMIT 5"))
552+
.ordered()
553+
.isFullyPushedDown();
554+
555+
// TopN over aggregation with filter
556+
if (hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN)) {
557+
assertThat(query("" +
558+
"SELECT * " +
559+
"FROM (SELECT SUM(totalprice) as sum, custkey AS total FROM orders GROUP BY custkey HAVING COUNT(*) > 3) " +
560+
"ORDER BY sum DESC LIMIT 10"))
561+
.ordered()
562+
.isFullyPushedDown();
563+
}
564+
}
565+
498566
@Test
499567
public void testAggregation()
500568
{

0 commit comments

Comments
 (0)