Skip to content

Commit 33d9184

Browse files
committed
fixup! Move limit pushdown test into BaseConnectorTest
1 parent a75e43d commit 33d9184

File tree

2 files changed

+72
-50
lines changed

2 files changed

+72
-50
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,9 @@ void testLimitPushdownWithDistinctAndJoin()
952952
assertConditionallyPushedDown(
953953
joinPushdownEnabled(getSession()),
954954
"SELECT n.name, r.name " +
955-
"FROM nation n " +
956-
"LEFT JOIN region r USING (regionkey) " +
957-
"LIMIT 30",
955+
"FROM nation n " +
956+
"LEFT JOIN region r USING (regionkey) " +
957+
"LIMIT 30",
958958
hasBehavior(SUPPORTS_JOIN_PUSHDOWN),
959959
joinOverTableScans);
960960
}

plugin/trino-druid/src/test/java/io/trino/plugin/druid/TestDruidConnectorTest.java

Lines changed: 69 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()
@@ -323,6 +276,75 @@ public void testNativeQueryInsertStatementTableExists()
323276
abort("cannot create test table for Druid");
324277
}
325278

279+
@Test
280+
public void testPredicatePushdown()
281+
{
282+
// varchar equality
283+
assertThat(query("SELECT regionkey, nationkey, name FROM nation WHERE name = 'ROMANIA'"))
284+
.matches("VALUES (BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar))")
285+
.isFullyPushedDown();
286+
287+
// varchar range
288+
assertThat(query("SELECT regionkey, nationkey, name FROM nation WHERE name BETWEEN 'POLAND' AND 'RPA'"))
289+
.matches("VALUES (BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar))")
290+
.isFullyPushedDown();
291+
292+
// varchar IN without domain compaction
293+
assertThat(query("SELECT regionkey, nationkey, name FROM nation WHERE name IN ('POLAND', 'ROMANIA', 'VIETNAM')"))
294+
.matches("VALUES " +
295+
"(BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar)), " +
296+
"(BIGINT '2', BIGINT '21', CAST('VIETNAM' AS varchar))")
297+
.isFullyPushedDown();
298+
299+
// varchar IN with small compaction threshold
300+
assertThat(query(
301+
Session.builder(getSession())
302+
.setCatalogSessionProperty("druid", "domain_compaction_threshold", "1")
303+
.build(),
304+
"SELECT regionkey, nationkey, name FROM nation WHERE name IN ('POLAND', 'ROMANIA', 'VIETNAM')"))
305+
.matches("VALUES " +
306+
"(BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar)), " +
307+
"(BIGINT '2', BIGINT '21', CAST('VIETNAM' AS varchar))")
308+
// Filter node is retained as no constraint is pushed into connector.
309+
.isNotFullyPushedDown(FilterNode.class);
310+
311+
// varchar different case
312+
assertThat(query("SELECT regionkey, nationkey, name FROM nation WHERE name = 'romania'"))
313+
.returnsEmptyResult()
314+
.isFullyPushedDown();
315+
316+
// bigint equality
317+
assertThat(query("SELECT regionkey, nationkey, name FROM nation WHERE nationkey = 19"))
318+
.matches("VALUES (BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar))")
319+
.isFullyPushedDown();
320+
321+
// bigint equality with small compaction threshold
322+
assertThat(query(
323+
Session.builder(getSession())
324+
.setCatalogSessionProperty("druid", "domain_compaction_threshold", "1")
325+
.build(),
326+
"SELECT regionkey, nationkey, name FROM nation WHERE nationkey IN (19, 21)"))
327+
.matches("VALUES " +
328+
"(BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar)), " +
329+
"(BIGINT '2', BIGINT '21', CAST('VIETNAM' AS varchar))")
330+
.isNotFullyPushedDown(FilterNode.class);
331+
332+
// bigint range, with decimal to bigint simplification
333+
assertThat(query("SELECT regionkey, nationkey, name FROM nation WHERE nationkey BETWEEN 18.5 AND 19.5"))
334+
.matches("VALUES (BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar))")
335+
.isFullyPushedDown();
336+
337+
// Druid doesn't support Aggregation Pushdown
338+
assertThat(query("SELECT * FROM (SELECT regionkey, sum(nationkey) FROM nation GROUP BY regionkey) WHERE regionkey = 3"))
339+
.matches("VALUES (BIGINT '3', BIGINT '77')")
340+
.isNotFullyPushedDown(AggregationNode.class);
341+
342+
// Druid doesn't support Aggregation Pushdown
343+
assertThat(query("SELECT regionkey, sum(nationkey) FROM nation GROUP BY regionkey HAVING sum(nationkey) = 77"))
344+
.matches("VALUES (BIGINT '3', BIGINT '77')")
345+
.isNotFullyPushedDown(AggregationNode.class);
346+
}
347+
326348
@Test
327349
public void testPredicatePushdownForTimestampWithSecondsPrecision()
328350
{

0 commit comments

Comments
 (0)