Skip to content

Commit 6d39b39

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 deada40 commit 6d39b39

File tree

2 files changed

+69
-62
lines changed

2 files changed

+69
-62
lines changed

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

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -971,69 +971,10 @@ public void testTopNPushdownDisabled()
971971
}
972972

973973
@Test
974-
public void testTopNPushdown()
974+
public void testTopNPushdownWithJoin()
975975
{
976-
if (!hasBehavior(SUPPORTS_TOPN_PUSHDOWN)) {
977-
assertThat(query("SELECT orderkey FROM orders ORDER BY orderkey LIMIT 10"))
978-
.ordered()
979-
.isNotFullyPushedDown(TopNNode.class);
980-
return;
981-
}
982-
983-
assertThat(query("SELECT orderkey FROM orders ORDER BY orderkey LIMIT 10"))
984-
.ordered()
985-
.isFullyPushedDown();
986-
987-
assertThat(query("SELECT orderkey FROM orders ORDER BY orderkey DESC LIMIT 10"))
988-
.ordered()
989-
.isFullyPushedDown();
990-
991-
// multiple sort columns with different orders
992-
assertThat(query("SELECT * FROM orders ORDER BY shippriority DESC, totalprice ASC LIMIT 10"))
993-
.ordered()
994-
.isFullyPushedDown();
995-
996-
// TopN over aggregation column
997-
if (hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN)) {
998-
assertThat(query("SELECT sum(totalprice) AS total FROM orders GROUP BY custkey ORDER BY total DESC LIMIT 10"))
999-
.ordered()
1000-
.isFullyPushedDown();
1001-
}
1002-
1003-
// TopN over TopN
1004-
assertThat(query("SELECT orderkey, totalprice FROM (SELECT orderkey, totalprice FROM orders ORDER BY 1, 2 LIMIT 10) ORDER BY 2, 1 LIMIT 5"))
1005-
.ordered()
1006-
.isFullyPushedDown();
1007-
1008-
assertThat(query("" +
1009-
"SELECT orderkey, totalprice " +
1010-
"FROM (SELECT orderkey, totalprice FROM (SELECT orderkey, totalprice FROM orders ORDER BY 1, 2 LIMIT 10) " +
1011-
"ORDER BY 2, 1 LIMIT 5) ORDER BY 1, 2 LIMIT 3"))
1012-
.ordered()
1013-
.isFullyPushedDown();
1014-
1015-
// TopN over limit - use high limit for deterministic result
1016-
assertThat(query("SELECT orderkey, totalprice FROM (SELECT orderkey, totalprice FROM orders LIMIT 15000) ORDER BY totalprice ASC LIMIT 5"))
1017-
.ordered()
1018-
.isFullyPushedDown();
1019-
1020-
// TopN over limit with filter
1021-
assertThat(query("" +
1022-
"SELECT orderkey, totalprice " +
1023-
"FROM (SELECT orderkey, totalprice FROM orders WHERE orderdate = DATE '1995-09-16' LIMIT 20) " +
1024-
"ORDER BY totalprice ASC LIMIT 5"))
1025-
.ordered()
1026-
.isFullyPushedDown();
1027-
1028-
// TopN over aggregation with filter
1029-
if (hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN)) {
1030-
assertThat(query("" +
1031-
"SELECT * " +
1032-
"FROM (SELECT SUM(totalprice) as sum, custkey AS total FROM orders GROUP BY custkey HAVING COUNT(*) > 3) " +
1033-
"ORDER BY sum DESC LIMIT 10"))
1034-
.ordered()
1035-
.isFullyPushedDown();
1036-
}
976+
// covered by testTopNPushdown
977+
skipTestUnless(hasBehavior(SUPPORTS_TOPN_PUSHDOWN));
1037978

1038979
// TopN over LEFT join (enforces SINGLE TopN cannot be pushed below OUTER side of join)
1039980
// We expect PARTIAL TopN on the LEFT side of join to be pushed down.

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,72 @@ public void testLimitPushdown()
495495
topnOverTableScan);
496496
}
497497

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

0 commit comments

Comments
 (0)