Skip to content

Commit deada40

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. Aslo fix the bug in Memory connector test where the connector supports limit pushdown.
1 parent e0aaffb commit deada40

File tree

18 files changed

+110
-141
lines changed

18 files changed

+110
-141
lines changed

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

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -937,72 +937,14 @@ protected TestTable createTableWithDoubleAndRealColumns(String name, List<String
937937
}
938938

939939
@Test
940-
public void testLimitPushdown()
940+
public void testLimitPushdownWithDistinctAndJoin()
941941
{
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-
}
946-
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();
949-
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);
942+
// covered by testLimitPushdown
943+
skipTestUnless(hasBehavior(SUPPORTS_LIMIT_PUSHDOWN));
973944

974945
// distinct limit can be pushed down even without aggregation pushdown
975946
assertThat(query("SELECT DISTINCT regionkey FROM nation LIMIT 5")).isFullyPushedDown();
976947

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)) {
985-
assertConditionallyPushedDown(
986-
getSession(),
987-
"SELECT regionkey, count(*) FROM nation WHERE name < 'EGYPT' GROUP BY regionkey LIMIT 3",
988-
hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN),
989-
aggregationOverTableScan);
990-
}
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-
1006948
// with join
1007949
PlanMatchPattern joinOverTableScans = node(JoinNode.class,
1008950
anyTree(node(TableScanNode.class)),
@@ -1439,19 +1381,6 @@ public void testExplainAnalyzePhysicalReadWallTime()
14391381
"Physical input time: .*s");
14401382
}
14411383

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-
14551384
protected QueryAssert assertJoinConditionallyPushedDown(
14561385
Session session,
14571386
@Language("SQL") String query,

plugin/trino-bigquery/src/test/java/io/trino/plugin/bigquery/BaseBigQueryConnectorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
103103
SUPPORTS_CREATE_MATERIALIZED_VIEW,
104104
SUPPORTS_CREATE_VIEW,
105105
SUPPORTS_DEFAULT_COLUMN_VALUE,
106+
SUPPORTS_LIMIT_PUSHDOWN,
106107
SUPPORTS_MAP_TYPE,
107108
SUPPORTS_MERGE,
108109
SUPPORTS_NEGATIVE_DATE,

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-druid/src/test/java/io/trino/plugin/druid/TestDruidConnectorTest.java

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@
1818
import io.trino.plugin.jdbc.BaseJdbcConnectorTest;
1919
import io.trino.spi.connector.ConnectorSession;
2020
import io.trino.spi.connector.SchemaTableName;
21-
import io.trino.sql.planner.assertions.PlanMatchPattern;
2221
import io.trino.sql.planner.plan.AggregationNode;
2322
import io.trino.sql.planner.plan.FilterNode;
24-
import io.trino.sql.planner.plan.JoinNode;
25-
import io.trino.sql.planner.plan.TableScanNode;
26-
import io.trino.sql.planner.plan.TopNNode;
2723
import io.trino.testing.MaterializedResult;
2824
import io.trino.testing.QueryRunner;
2925
import io.trino.testing.TestingConnectorBehavior;
@@ -39,8 +35,6 @@
3935
import static io.trino.plugin.druid.DruidQueryRunner.copyAndIngestTpchData;
4036
import static io.trino.plugin.druid.DruidTpchTables.SELECT_FROM_ORDERS;
4137
import static io.trino.spi.type.VarcharType.VARCHAR;
42-
import static io.trino.sql.planner.assertions.PlanMatchPattern.anyTree;
43-
import static io.trino.sql.planner.assertions.PlanMatchPattern.node;
4438
import static io.trino.sql.planner.assertions.PlanMatchPattern.output;
4539
import static io.trino.sql.planner.assertions.PlanMatchPattern.values;
4640
import static io.trino.testing.MaterializedResult.resultBuilder;
@@ -234,47 +228,6 @@ public void testFilteringForTablesAndColumns()
234228
assertThat(query("DESCRIBE " + datasourceB)).result().matches(expectedColumns);
235229
}
236230

237-
@Test
238-
public void testLimitPushDown()
239-
{
240-
assertThat(query("SELECT name FROM nation LIMIT 30")).isFullyPushedDown(); // Use high limit for result determinism
241-
242-
// with filter over numeric column
243-
assertThat(query("SELECT name FROM nation WHERE regionkey = 3 LIMIT 5")).isFullyPushedDown();
244-
245-
// with filter over varchar column
246-
assertThat(query("SELECT name FROM nation WHERE name < 'EEE' LIMIT 5")).isFullyPushedDown();
247-
248-
// with aggregation
249-
assertThat(query("SELECT max(regionkey) FROM nation LIMIT 5")).isNotFullyPushedDown(AggregationNode.class); // global aggregation, LIMIT removed TODO https://github.com/trinodb/trino/pull/4313
250-
assertThat(query("SELECT regionkey, max(name) FROM nation GROUP BY regionkey LIMIT 5")).isNotFullyPushedDown(AggregationNode.class); // TODO https://github.com/trinodb/trino/pull/4313
251-
252-
// distinct limit can be pushed down even without aggregation pushdown
253-
assertThat(query("SELECT DISTINCT regionkey FROM nation LIMIT 5")).isFullyPushedDown();
254-
255-
// with aggregation and filter over numeric column
256-
assertThat(query("SELECT regionkey, count(*) FROM nation WHERE nationkey < 5 GROUP BY regionkey LIMIT 3")).isNotFullyPushedDown(AggregationNode.class); // TODO https://github.com/trinodb/trino/pull/4313
257-
// with aggregation and filter over varchar column
258-
assertThat(query("SELECT regionkey, count(*) FROM nation WHERE name < 'EGYPT' GROUP BY regionkey LIMIT 3")).isNotFullyPushedDown(AggregationNode.class); // TODO https://github.com/trinodb/trino/pull/4313
259-
260-
// with TopN over numeric column
261-
assertThat(query("SELECT * FROM (SELECT regionkey FROM nation ORDER BY nationkey ASC LIMIT 10) LIMIT 5")).isNotFullyPushedDown(TopNNode.class);
262-
// with TopN over varchar column
263-
assertThat(query("SELECT * FROM (SELECT regionkey FROM nation ORDER BY name ASC LIMIT 10) LIMIT 5")).isNotFullyPushedDown(TopNNode.class);
264-
265-
// with join
266-
PlanMatchPattern joinOverTableScans = node(JoinNode.class,
267-
anyTree(node(TableScanNode.class)),
268-
anyTree(node(TableScanNode.class)));
269-
assertThat(query(
270-
joinPushdownEnabled(getSession()),
271-
"SELECT n.name, r.name " +
272-
"FROM nation n " +
273-
"LEFT JOIN region r USING (regionkey) " +
274-
"LIMIT 30"))
275-
.isNotFullyPushedDown(joinOverTableScans);
276-
}
277-
278231
@Test
279232
@Override
280233
public void testInsertNegativeDate()

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;

0 commit comments

Comments
 (0)