Skip to content

Commit c22a9e3

Browse files
committed
Move limit pushdown test into BaseConnectorTest
Previously, there was no test to exercise limit pushdown behavior for non-JDBC connectors, regardless of whether they declare support for the `SUPPORTS_LIMIT_PUSHDOWN` TestingConnectorBehavior
1 parent e0aaffb commit c22a9e3

File tree

14 files changed

+114
-101
lines changed

14 files changed

+114
-101
lines changed

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

Lines changed: 16 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -937,84 +937,28 @@ protected TestTable createTableWithDoubleAndRealColumns(String name, List<String
937937
}
938938

939939
@Test
940+
@Override
940941
public void testLimitPushdown()
941942
{
942-
if (!hasBehavior(SUPPORTS_LIMIT_PUSHDOWN)) {
943-
assertThat(query("SELECT name FROM nation LIMIT 30")).isNotFullyPushedDown(LimitNode.class); // Use high limit for result determinism
944-
return;
945-
}
943+
super.testLimitPushdown();
946944

947-
assertThat(query("SELECT name FROM nation LIMIT 30")).isFullyPushedDown(); // Use high limit for result determinism
948-
assertThat(query("SELECT name FROM nation LIMIT 3")).skipResultsCorrectnessCheckForPushdown().isFullyPushedDown();
945+
if (hasBehavior(SUPPORTS_LIMIT_PUSHDOWN)) {
946+
// distinct limit can be pushed down even without aggregation pushdown
947+
assertThat(query("SELECT DISTINCT regionkey FROM nation LIMIT 5")).isFullyPushedDown();
949948

950-
// with filter over numeric column
951-
assertThat(query("SELECT name FROM nation WHERE regionkey = 3 LIMIT 5")).isFullyPushedDown();
952-
953-
// with filter over varchar column
954-
PlanMatchPattern filterOverTableScan = node(FilterNode.class, node(TableScanNode.class));
955-
assertConditionallyPushedDown(
956-
getSession(),
957-
"SELECT name FROM nation WHERE name < 'EEE' LIMIT 5",
958-
hasBehavior(SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_INEQUALITY),
959-
filterOverTableScan);
960-
961-
// with aggregation
962-
PlanMatchPattern aggregationOverTableScan = node(AggregationNode.class, anyTree(node(TableScanNode.class)));
963-
assertConditionallyPushedDown(
964-
getSession(),
965-
"SELECT max(regionkey) FROM nation LIMIT 5", // global aggregation, LIMIT removed
966-
hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN),
967-
aggregationOverTableScan);
968-
assertConditionallyPushedDown(
969-
getSession(),
970-
"SELECT regionkey, max(nationkey) FROM nation GROUP BY regionkey LIMIT 5",
971-
hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN),
972-
aggregationOverTableScan);
973-
974-
// distinct limit can be pushed down even without aggregation pushdown
975-
assertThat(query("SELECT DISTINCT regionkey FROM nation LIMIT 5")).isFullyPushedDown();
976-
977-
// with aggregation and filter over numeric column
978-
assertConditionallyPushedDown(
979-
getSession(),
980-
"SELECT regionkey, count(*) FROM nation WHERE nationkey < 5 GROUP BY regionkey LIMIT 3",
981-
hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN),
982-
aggregationOverTableScan);
983-
// with aggregation and filter over varchar column
984-
if (hasBehavior(SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_INEQUALITY)) {
949+
// with join
950+
PlanMatchPattern joinOverTableScans = node(JoinNode.class,
951+
anyTree(node(TableScanNode.class)),
952+
anyTree(node(TableScanNode.class)));
985953
assertConditionallyPushedDown(
986-
getSession(),
987-
"SELECT regionkey, count(*) FROM nation WHERE name < 'EGYPT' GROUP BY regionkey LIMIT 3",
988-
hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN),
989-
aggregationOverTableScan);
954+
joinPushdownEnabled(getSession()),
955+
"SELECT n.name, r.name " +
956+
"FROM nation n " +
957+
"LEFT JOIN region r USING (regionkey) " +
958+
"LIMIT 30",
959+
hasBehavior(SUPPORTS_JOIN_PUSHDOWN),
960+
joinOverTableScans);
990961
}
991-
992-
// with TopN over numeric column
993-
PlanMatchPattern topnOverTableScan = project(node(TopNNode.class, anyTree(node(TableScanNode.class))));
994-
assertConditionallyPushedDown(
995-
getSession(),
996-
"SELECT * FROM (SELECT regionkey FROM nation ORDER BY nationkey ASC LIMIT 10) LIMIT 5",
997-
hasBehavior(SUPPORTS_TOPN_PUSHDOWN),
998-
topnOverTableScan);
999-
// with TopN over varchar column
1000-
assertConditionallyPushedDown(
1001-
getSession(),
1002-
"SELECT * FROM (SELECT regionkey FROM nation ORDER BY name ASC LIMIT 10) LIMIT 5",
1003-
hasBehavior(SUPPORTS_TOPN_PUSHDOWN_WITH_VARCHAR),
1004-
topnOverTableScan);
1005-
1006-
// with join
1007-
PlanMatchPattern joinOverTableScans = node(JoinNode.class,
1008-
anyTree(node(TableScanNode.class)),
1009-
anyTree(node(TableScanNode.class)));
1010-
assertConditionallyPushedDown(
1011-
joinPushdownEnabled(getSession()),
1012-
"SELECT n.name, r.name " +
1013-
"FROM nation n " +
1014-
"LEFT JOIN region r USING (regionkey) " +
1015-
"LIMIT 30",
1016-
hasBehavior(SUPPORTS_JOIN_PUSHDOWN),
1017-
joinOverTableScans);
1018962
}
1019963

1020964
@Test
@@ -1439,19 +1383,6 @@ public void testExplainAnalyzePhysicalReadWallTime()
14391383
"Physical input time: .*s");
14401384
}
14411385

1442-
protected QueryAssert assertConditionallyPushedDown(
1443-
Session session,
1444-
@Language("SQL") String query,
1445-
boolean condition,
1446-
PlanMatchPattern otherwiseExpected)
1447-
{
1448-
QueryAssert queryAssert = assertThat(query(session, query));
1449-
if (condition) {
1450-
return queryAssert.isFullyPushedDown();
1451-
}
1452-
return queryAssert.isNotFullyPushedDown(otherwiseExpected);
1453-
}
1454-
14551386
protected QueryAssert assertJoinConditionallyPushedDown(
14561387
Session session,
14571388
@Language("SQL") String query,

plugin/trino-cassandra/src/test/java/io/trino/plugin/cassandra/TestCassandraConnectorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
9595
SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT,
9696
SUPPORTS_CREATE_VIEW,
9797
SUPPORTS_DEFAULT_COLUMN_VALUE,
98+
SUPPORTS_LIMIT_PUSHDOWN,
9899
SUPPORTS_MAP_TYPE,
99100
SUPPORTS_MERGE,
100101
SUPPORTS_NOT_NULL_CONSTRAINT,

plugin/trino-elasticsearch/src/test/java/io/trino/plugin/elasticsearch/BaseElasticsearchConnectorTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.google.common.collect.ImmutableMap;
1919
import io.trino.Session;
2020
import io.trino.spi.type.VarcharType;
21-
import io.trino.sql.planner.plan.LimitNode;
2221
import io.trino.testing.AbstractTestQueries;
2322
import io.trino.testing.BaseConnectorTest;
2423
import io.trino.testing.MaterializedResult;
@@ -1711,13 +1710,6 @@ public void testFiltersCharset()
17111710
.matches("VALUES (VARCHAR 'Türkiye')");
17121711
}
17131712

1714-
@Test
1715-
public void testLimitPushdown()
1716-
throws IOException
1717-
{
1718-
assertThat(query("SELECT name FROM nation LIMIT 30")).isNotFullyPushedDown(LimitNode.class); // Use high limit for result determinism
1719-
}
1720-
17211713
@Test
17221714
public void testDataTypesNested()
17231715
throws IOException

plugin/trino-hive/src/test/java/io/trino/plugin/hive/BaseHiveConnectorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
255255
SUPPORTS_CREATE_MATERIALIZED_VIEW,
256256
SUPPORTS_DEFAULT_COLUMN_VALUE,
257257
SUPPORTS_DROP_FIELD,
258+
SUPPORTS_LIMIT_PUSHDOWN,
258259
SUPPORTS_MERGE,
259260
SUPPORTS_NOT_NULL_CONSTRAINT,
260261
SUPPORTS_REFRESH_VIEW,

plugin/trino-hudi/src/test/java/io/trino/plugin/hudi/TestHudiConnectorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
4949
SUPPORTS_DELETE,
5050
SUPPORTS_DEREFERENCE_PUSHDOWN,
5151
SUPPORTS_INSERT,
52+
SUPPORTS_LIMIT_PUSHDOWN,
5253
SUPPORTS_MERGE,
5354
SUPPORTS_RENAME_COLUMN,
5455
SUPPORTS_RENAME_TABLE,

plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
246246
SUPPORTS_REPORTING_WRITTEN_BYTES -> true;
247247
case SUPPORTS_ADD_COLUMN_NOT_NULL_CONSTRAINT,
248248
SUPPORTS_DEFAULT_COLUMN_VALUE,
249+
SUPPORTS_LIMIT_PUSHDOWN,
249250
SUPPORTS_REFRESH_VIEW,
250251
SUPPORTS_RENAME_MATERIALIZED_VIEW_ACROSS_SCHEMAS,
251252
SUPPORTS_TOPN_PUSHDOWN -> false;

plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaConnectorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
170170
SUPPORTS_CREATE_VIEW,
171171
SUPPORTS_DELETE,
172172
SUPPORTS_DEREFERENCE_PUSHDOWN,
173+
SUPPORTS_LIMIT_PUSHDOWN,
173174
SUPPORTS_MERGE,
174175
SUPPORTS_RENAME_COLUMN,
175176
SUPPORTS_RENAME_TABLE,

plugin/trino-lakehouse/src/test/java/io/trino/plugin/lakehouse/TestLakehouseConnectorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
9090
SUPPORTS_REPORTING_WRITTEN_BYTES -> true;
9191
case SUPPORTS_ADD_COLUMN_NOT_NULL_CONSTRAINT,
9292
SUPPORTS_DEFAULT_COLUMN_VALUE,
93+
SUPPORTS_LIMIT_PUSHDOWN,
9394
SUPPORTS_REFRESH_VIEW,
9495
SUPPORTS_RENAME_MATERIALIZED_VIEW_ACROSS_SCHEMAS,
9596
SUPPORTS_TOPN_PUSHDOWN -> false;

plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/TestMongoConnectorTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
102102
return switch (connectorBehavior) {
103103
case SUPPORTS_ADD_COLUMN_WITH_POSITION,
104104
SUPPORTS_ADD_FIELD,
105+
SUPPORTS_AGGREGATION_PUSHDOWN,
105106
SUPPORTS_CREATE_MATERIALIZED_VIEW,
106107
SUPPORTS_CREATE_VIEW,
107108
SUPPORTS_DEFAULT_COLUMN_VALUE,
@@ -111,6 +112,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
111112
SUPPORTS_RENAME_FIELD,
112113
SUPPORTS_RENAME_SCHEMA,
113114
SUPPORTS_SET_FIELD_TYPE,
115+
SUPPORTS_TOPN_PUSHDOWN,
114116
SUPPORTS_TRUNCATE,
115117
SUPPORTS_UPDATE -> false;
116118
default -> super.hasBehavior(connectorBehavior);
@@ -956,8 +958,10 @@ public void testNullPredicates()
956958
}
957959

958960
@Test
961+
@Override
959962
public void testLimitPushdown()
960963
{
964+
super.testLimitPushdown();
961965
assertThat(query("SELECT name FROM nation LIMIT 30")).isFullyPushedDown(); // Use high limit for result determinism
962966

963967
// Make sure LIMIT 0 returns empty result because cursor.limit(0) means no limit in MongoDB

plugin/trino-opensearch/src/test/java/io/trino/plugin/opensearch/BaseOpenSearchConnectorTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.google.common.net.HostAndPort;
2020
import io.trino.Session;
2121
import io.trino.spi.type.VarcharType;
22-
import io.trino.sql.planner.plan.LimitNode;
2322
import io.trino.sql.planner.plan.ProjectNode;
2423
import io.trino.testing.AbstractTestQueries;
2524
import io.trino.testing.BaseConnectorTest;
@@ -1679,13 +1678,6 @@ public void testFiltersCharset()
16791678
.matches("VALUES (VARCHAR 'Türkiye')");
16801679
}
16811680

1682-
@Test
1683-
public void testLimitPushdown()
1684-
throws IOException
1685-
{
1686-
assertThat(query("SELECT name FROM nation LIMIT 30")).isNotFullyPushedDown(LimitNode.class); // Use high limit for result determinism
1687-
}
1688-
16891681
@Test
16901682
public void testDataTypesNested()
16911683
throws IOException

0 commit comments

Comments
 (0)