|
18 | 18 | import io.trino.plugin.jdbc.BaseJdbcConnectorTest; |
19 | 19 | import io.trino.spi.connector.ConnectorSession; |
20 | 20 | import io.trino.spi.connector.SchemaTableName; |
21 | | -import io.trino.sql.planner.assertions.PlanMatchPattern; |
22 | 21 | import io.trino.sql.planner.plan.AggregationNode; |
23 | 22 | 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; |
27 | 23 | import io.trino.testing.MaterializedResult; |
28 | 24 | import io.trino.testing.QueryRunner; |
29 | 25 | import io.trino.testing.TestingConnectorBehavior; |
|
39 | 35 | import static io.trino.plugin.druid.DruidQueryRunner.copyAndIngestTpchData; |
40 | 36 | import static io.trino.plugin.druid.DruidTpchTables.SELECT_FROM_ORDERS; |
41 | 37 | 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; |
44 | 38 | import static io.trino.sql.planner.assertions.PlanMatchPattern.output; |
45 | 39 | import static io.trino.sql.planner.assertions.PlanMatchPattern.values; |
46 | 40 | import static io.trino.testing.MaterializedResult.resultBuilder; |
@@ -234,47 +228,6 @@ public void testFilteringForTablesAndColumns() |
234 | 228 | assertThat(query("DESCRIBE " + datasourceB)).result().matches(expectedColumns); |
235 | 229 | } |
236 | 230 |
|
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 | | - |
278 | 231 | @Test |
279 | 232 | @Override |
280 | 233 | public void testInsertNegativeDate() |
@@ -323,6 +276,75 @@ public void testNativeQueryInsertStatementTableExists() |
323 | 276 | abort("cannot create test table for Druid"); |
324 | 277 | } |
325 | 278 |
|
| 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 | + |
326 | 348 | @Test |
327 | 349 | public void testPredicatePushdownForTimestampWithSecondsPrecision() |
328 | 350 | { |
|
0 commit comments