use of io.trino.testing.TestingConnectorBehavior.SUPPORTS_INSERT 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))))));
}
}
}
Aggregations