Search in sources :

Example 1 with SUPPORTS_AGGREGATION_PUSHDOWN_COUNT_DISTINCT

use of io.trino.testing.TestingConnectorBehavior.SUPPORTS_AGGREGATION_PUSHDOWN_COUNT_DISTINCT in project trino by trinodb.

the class BaseJdbcConnectorTest method testCountDistinctWithStringTypes.

@Test
public void testCountDistinctWithStringTypes() {
    if (!(hasBehavior(SUPPORTS_CREATE_TABLE) && hasBehavior(SUPPORTS_INSERT))) {
        throw new SkipException("Unable to CREATE TABLE to test count distinct");
    }
    List<String> rows = Stream.of("a", "b", "A", "B", " a ", "a", "b", " b ", "ą").map(value -> format("'%1$s', '%1$s'", value)).collect(toImmutableList());
    try (TestTable testTable = new TestTable(getQueryRunner()::execute, "distinct_strings", "(t_char CHAR(5), t_varchar VARCHAR(5))", rows)) {
        if (!(hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN) && hasBehavior(SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_INEQUALITY))) {
            // disabling hash generation to prevent extra projections in the plan which make it hard to write matchers for isNotFullyPushedDown
            Session optimizeHashGenerationDisabled = Session.builder(getSession()).setSystemProperty("optimize_hash_generation", "false").build();
            // It is not captured in the `isNotFullyPushedDown` calls (can't do that) but depending on the connector in use some aggregations
            // still can be pushed down to connector.
            // If `SUPPORTS_AGGREGATION_PUSHDOWN == false` but `SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_INEQUALITY == true` the DISTINCT part of aggregation
            // will still be pushed down to connector as `GROUP BY`. Only the `count` part will remain on the Trino side.
            // If `SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_INEQUALITY == false` both parts of aggregation will be executed on Trino side.
            assertThat(query(optimizeHashGenerationDisabled, "SELECT count(DISTINCT t_varchar) FROM " + testTable.getName())).matches("VALUES BIGINT '7'").isNotFullyPushedDown(AggregationNode.class);
            assertThat(query(optimizeHashGenerationDisabled, "SELECT count(DISTINCT t_char) FROM " + testTable.getName())).matches("VALUES BIGINT '7'").isNotFullyPushedDown(AggregationNode.class);
            assertThat(query("SELECT count(DISTINCT t_char), count(DISTINCT t_varchar) FROM " + testTable.getName())).matches("VALUES (BIGINT '7', BIGINT '7')").isNotFullyPushedDown(MarkDistinctNode.class, ExchangeNode.class, ExchangeNode.class, ProjectNode.class);
        } else {
            // Single count(DISTINCT ...) can be pushed even down even if SUPPORTS_AGGREGATION_PUSHDOWN_COUNT_DISTINCT == false as GROUP BY
            assertThat(query("SELECT count(DISTINCT t_varchar) FROM " + testTable.getName())).matches("VALUES BIGINT '7'").isFullyPushedDown();
            // Single count(DISTINCT ...) can be pushed down even if SUPPORTS_AGGREGATION_PUSHDOWN_COUNT_DISTINCT == false as GROUP BY
            assertThat(query("SELECT count(DISTINCT t_char) FROM " + testTable.getName())).matches("VALUES BIGINT '7'").isFullyPushedDown();
            assertConditionallyPushedDown(getSession(), "SELECT count(DISTINCT t_char), count(DISTINCT t_varchar) FROM " + testTable.getName(), hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_COUNT_DISTINCT), node(MarkDistinctNode.class, node(ExchangeNode.class, node(ExchangeNode.class, node(ProjectNode.class, node(TableScanNode.class))))));
        }
    }
}
Also used : SkipException(org.testng.SkipException) QueryId(io.trino.spi.QueryId) SUPPORTS_JOIN_PUSHDOWN_WITH_VARCHAR_INEQUALITY(io.trino.testing.TestingConnectorBehavior.SUPPORTS_JOIN_PUSHDOWN_WITH_VARCHAR_INEQUALITY) SUPPORTS_ROW_LEVEL_DELETE(io.trino.testing.TestingConnectorBehavior.SUPPORTS_ROW_LEVEL_DELETE) SUPPORTS_AGGREGATION_PUSHDOWN_VARIANCE(io.trino.testing.TestingConnectorBehavior.SUPPORTS_AGGREGATION_PUSHDOWN_VARIANCE) MaterializedResult(io.trino.testing.MaterializedResult) SUPPORTS_AGGREGATION_PUSHDOWN_COVARIANCE(io.trino.testing.TestingConnectorBehavior.SUPPORTS_AGGREGATION_PUSHDOWN_COVARIANCE) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) TestTable(io.trino.testing.sql.TestTable) FilterNode(io.trino.sql.planner.plan.FilterNode) Duration(io.airlift.units.Duration) Future(java.util.concurrent.Future) PlanMatchPattern.exchange(io.trino.sql.planner.assertions.PlanMatchPattern.exchange) SUPPORTS_JOIN_PUSHDOWN_WITH_FULL_JOIN(io.trino.testing.TestingConnectorBehavior.SUPPORTS_JOIN_PUSHDOWN_WITH_FULL_JOIN) TestingConnectorBehavior(io.trino.testing.TestingConnectorBehavior) SUPPORTS_AGGREGATION_PUSHDOWN_COUNT_DISTINCT(io.trino.testing.TestingConnectorBehavior.SUPPORTS_AGGREGATION_PUSHDOWN_COUNT_DISTINCT) SqlExecutor(io.trino.testing.sql.SqlExecutor) JoinNode(io.trino.sql.planner.plan.JoinNode) ENGLISH(java.util.Locale.ENGLISH) TableScanNode(io.trino.sql.planner.plan.TableScanNode) SUPPORTS_CANCELLATION(io.trino.testing.TestingConnectorBehavior.SUPPORTS_CANCELLATION) SUPPORTS_JOIN_PUSHDOWN_WITH_DISTINCT_FROM(io.trino.testing.TestingConnectorBehavior.SUPPORTS_JOIN_PUSHDOWN_WITH_DISTINCT_FROM) SUPPORTS_CREATE_TABLE(io.trino.testing.TestingConnectorBehavior.SUPPORTS_CREATE_TABLE) MarkDistinctNode(io.trino.sql.planner.plan.MarkDistinctNode) TestView(io.trino.testing.sql.TestView) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) UUID(java.util.UUID) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Stream(java.util.stream.Stream) PlanMatchPattern.anyTree(io.trino.sql.planner.assertions.PlanMatchPattern.anyTree) SUPPORTS_AGGREGATION_PUSHDOWN(io.trino.testing.TestingConnectorBehavior.SUPPORTS_AGGREGATION_PUSHDOWN) SUPPORTS_INSERT(io.trino.testing.TestingConnectorBehavior.SUPPORTS_INSERT) USE_MARK_DISTINCT(io.trino.SystemSessionProperties.USE_MARK_DISTINCT) SUPPORTS_PREDICATE_EXPRESSION_PUSHDOWN_WITH_LIKE(io.trino.testing.TestingConnectorBehavior.SUPPORTS_PREDICATE_EXPRESSION_PUSHDOWN_WITH_LIKE) ExchangeNode(io.trino.sql.planner.plan.ExchangeNode) Session(io.trino.Session) JoinCondition(io.trino.spi.connector.JoinCondition) DataProvider(org.testng.annotations.DataProvider) SUPPORTS_AGGREGATION_PUSHDOWN_STDDEV(io.trino.testing.TestingConnectorBehavior.SUPPORTS_AGGREGATION_PUSHDOWN_STDDEV) LimitNode(io.trino.sql.planner.plan.LimitNode) SUPPORTS_JOIN_PUSHDOWN_WITH_VARCHAR_EQUALITY(io.trino.testing.TestingConnectorBehavior.SUPPORTS_JOIN_PUSHDOWN_WITH_VARCHAR_EQUALITY) SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_INEQUALITY(io.trino.testing.TestingConnectorBehavior.SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_INEQUALITY) MINUTES(java.util.concurrent.TimeUnit.MINUTES) SUPPORTS_TOPN_PUSHDOWN(io.trino.testing.TestingConnectorBehavior.SUPPORTS_TOPN_PUSHDOWN) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Verify.verify(com.google.common.base.Verify.verify) SUPPORTS_LIMIT_PUSHDOWN(io.trino.testing.TestingConnectorBehavior.SUPPORTS_LIMIT_PUSHDOWN) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) AggregationNode(io.trino.sql.planner.plan.AggregationNode) ProjectNode(io.trino.sql.planner.plan.ProjectNode) ExecutorService(java.util.concurrent.ExecutorService) SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_EQUALITY(io.trino.testing.TestingConnectorBehavior.SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_EQUALITY) AfterClass(org.testng.annotations.AfterClass) MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) SUPPORTS_TOPN_PUSHDOWN_WITH_VARCHAR(io.trino.testing.TestingConnectorBehavior.SUPPORTS_TOPN_PUSHDOWN_WITH_VARCHAR) CANCELLED(io.trino.plugin.jdbc.RemoteDatabaseEvent.Status.CANCELLED) Language(org.intellij.lang.annotations.Language) RUNNING(io.trino.plugin.jdbc.RemoteDatabaseEvent.Status.RUNNING) TopNNode(io.trino.sql.planner.plan.TopNNode) SortOrder(io.trino.spi.connector.SortOrder) BaseConnectorTest(io.trino.testing.BaseConnectorTest) PlanMatchPattern.node(io.trino.sql.planner.assertions.PlanMatchPattern.node) SUPPORTS_AGGREGATION_PUSHDOWN_CORRELATION(io.trino.testing.TestingConnectorBehavior.SUPPORTS_AGGREGATION_PUSHDOWN_CORRELATION) Assert.assertEventually(io.trino.testing.assertions.Assert.assertEventually) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) QueryAssert(io.trino.sql.query.QueryAssertions.QueryAssert) SUPPORTS_AGGREGATION_PUSHDOWN_REGRESSION(io.trino.testing.TestingConnectorBehavior.SUPPORTS_AGGREGATION_PUSHDOWN_REGRESSION) SUPPORTS_JOIN_PUSHDOWN(io.trino.testing.TestingConnectorBehavior.SUPPORTS_JOIN_PUSHDOWN) JOIN_PUSHDOWN_ENABLED(io.trino.plugin.jdbc.JdbcMetadataSessionProperties.JOIN_PUSHDOWN_ENABLED) MarkDistinctNode(io.trino.sql.planner.plan.MarkDistinctNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) ExchangeNode(io.trino.sql.planner.plan.ExchangeNode) SkipException(org.testng.SkipException) TestTable(io.trino.testing.sql.TestTable) Session(io.trino.Session) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Aggregations

Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Verify.verify (com.google.common.base.Verify.verify)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 MoreCollectors.toOptional (com.google.common.collect.MoreCollectors.toOptional)1 Threads.daemonThreadsNamed (io.airlift.concurrent.Threads.daemonThreadsNamed)1 Duration (io.airlift.units.Duration)1 Session (io.trino.Session)1 USE_MARK_DISTINCT (io.trino.SystemSessionProperties.USE_MARK_DISTINCT)1 JOIN_PUSHDOWN_ENABLED (io.trino.plugin.jdbc.JdbcMetadataSessionProperties.JOIN_PUSHDOWN_ENABLED)1 CANCELLED (io.trino.plugin.jdbc.RemoteDatabaseEvent.Status.CANCELLED)1 RUNNING (io.trino.plugin.jdbc.RemoteDatabaseEvent.Status.RUNNING)1 QueryId (io.trino.spi.QueryId)1 JoinCondition (io.trino.spi.connector.JoinCondition)1 SortOrder (io.trino.spi.connector.SortOrder)1 PlanMatchPattern (io.trino.sql.planner.assertions.PlanMatchPattern)1 PlanMatchPattern.anyTree (io.trino.sql.planner.assertions.PlanMatchPattern.anyTree)1 PlanMatchPattern.exchange (io.trino.sql.planner.assertions.PlanMatchPattern.exchange)1 PlanMatchPattern.node (io.trino.sql.planner.assertions.PlanMatchPattern.node)1 AggregationNode (io.trino.sql.planner.plan.AggregationNode)1