Search in sources :

Example 96 with TupleDomain

use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.

the class TestPrometheusSplit method testPredicatePushDownSetsLowerBoundOnly.

@Test(enabled = false)
public void testPredicatePushDownSetsLowerBoundOnly() {
    long predicateLowValue = 1568638171999L - 600000L;
    Range lowRange = Range.greaterThanOrEqual(TIMESTAMP_COLUMN_TYPE, packDateTimeWithZone(predicateLowValue, UTC_KEY));
    ValueSet valueSet = ValueSet.ofRanges(lowRange);
    Domain testDomain = Domain.create(valueSet, false);
    TupleDomain<ColumnHandle> testTupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(new PrometheusColumnHandle("timestamp", TIMESTAMP_COLUMN_TYPE, 2), testDomain));
    PrometheusTableHandle prometheusTableHandle = new PrometheusTableHandle("schemaName", "tableName").withPredicate(testTupleDomain);
    io.airlift.units.Duration maxQueryRangeDuration = new io.airlift.units.Duration(120, TimeUnit.SECONDS);
    io.airlift.units.Duration queryChunkSizeDuration = new io.airlift.units.Duration(30, TimeUnit.SECONDS);
    Instant now = ofEpochMilli(1568638171999L);
    TemporalAmount maxQueryAsTime = java.time.Duration.ofMillis(maxQueryRangeDuration.toMillis());
    List<String> splitTimes = PrometheusSplitManager.generateTimesForSplits(now, maxQueryRangeDuration, queryChunkSizeDuration, prometheusTableHandle);
    String earliestSplit = splitTimes.get(0);
    Instant earliestSplitAsTime = ofEpochMilli(longFromDecimalSecondString(earliestSplit));
    TemporalAmount queryChunkAsTime = java.time.Duration.ofMillis(queryChunkSizeDuration.toMillis());
    Instant startOfQuery = earliestSplitAsTime.minus(queryChunkAsTime);
    assertNotEquals(startOfQuery, now.minus(maxQueryAsTime).minus(java.time.Duration.ofMillis((splitTimes.size() - 1) * OFFSET_MILLIS)));
    assertEquals(startOfQuery.toEpochMilli(), ofEpochMilli(predicateLowValue).toEpochMilli() - ((splitTimes.size() - 1) * OFFSET_MILLIS));
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) Instant(java.time.Instant) Duration(java.time.Duration) PrometheusSplitManager.decimalSecondString(io.trino.plugin.prometheus.PrometheusSplitManager.decimalSecondString) Range(io.trino.spi.predicate.Range) TemporalAmount(java.time.temporal.TemporalAmount) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) ValueSet(io.trino.spi.predicate.ValueSet) Test(org.testng.annotations.Test)

Example 97 with TupleDomain

use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.

the class TestPostgreSqlConnectorTest method testStringPushdownWithCollate.

@Test
public void testStringPushdownWithCollate() {
    Session session = Session.builder(getSession()).setCatalogSessionProperty("postgresql", "enable_string_pushdown_with_collate", "true").build();
    // varchar range
    assertThat(query(session, "SELECT regionkey, nationkey, name FROM nation WHERE name BETWEEN 'POLAND' AND 'RPA'")).matches("VALUES (BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar(25)))").isFullyPushedDown();
    // varchar IN with small compaction threshold
    assertThat(query(Session.builder(session).setCatalogSessionProperty("postgresql", "domain_compaction_threshold", "1").build(), "SELECT regionkey, nationkey, name FROM nation WHERE name IN ('POLAND', 'ROMANIA', 'VIETNAM')")).matches("VALUES " + "(BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar(25))), " + "(BIGINT '2', BIGINT '21', CAST('VIETNAM' AS varchar(25)))").isNotFullyPushedDown(node(FilterNode.class, tableScan(tableHandle -> {
        TupleDomain<ColumnHandle> constraint = ((JdbcTableHandle) tableHandle).getConstraint();
        ColumnHandle nameColumn = constraint.getDomains().orElseThrow().keySet().stream().map(JdbcColumnHandle.class::cast).filter(column -> column.getColumnName().equals("name")).collect(onlyElement());
        return constraint.getDomains().get().get(nameColumn).getValues().getRanges().getOrderedRanges().equals(ImmutableList.of(Range.range(createVarcharType(25), utf8Slice("POLAND"), true, utf8Slice("VIETNAM"), true)));
    }, TupleDomain.all(), ImmutableMap.of())));
    // varchar predicate over join
    Session joinPushdownEnabled = joinPushdownEnabled(session);
    assertThat(query(joinPushdownEnabled, "SELECT c.name, n.name FROM customer c JOIN nation n ON c.custkey = n.nationkey WHERE address < 'TcGe5gaZNgVePxU5kRrvXBfkasDTea'")).isFullyPushedDown();
    // join on varchar columns is not pushed down
    assertThat(query(joinPushdownEnabled, "SELECT c.name, n.name FROM customer c JOIN nation n ON c.address = n.name")).isNotFullyPushedDown(node(JoinNode.class, anyTree(node(TableScanNode.class)), anyTree(node(TableScanNode.class))));
}
Also used : Connection(java.sql.Connection) IntStream.range(java.util.stream.IntStream.range) 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) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) FilterNode(io.trino.sql.planner.plan.FilterNode) Duration(io.airlift.units.Duration) PlanMatchPattern.exchange(io.trino.sql.planner.assertions.PlanMatchPattern.exchange) Math.round(java.lang.Math.round) Map(java.util.Map) TestingConnectorBehavior(io.trino.testing.TestingConnectorBehavior) SqlExecutor(io.trino.testing.sql.SqlExecutor) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) JoinNode(io.trino.sql.planner.plan.JoinNode) Assert.assertFalse(org.testng.Assert.assertFalse) TableScanNode(io.trino.sql.planner.plan.TableScanNode) TestTable.randomTableSuffix(io.trino.testing.sql.TestTable.randomTableSuffix) ImmutableMap(com.google.common.collect.ImmutableMap) Range(io.trino.spi.predicate.Range) TestView(io.trino.testing.sql.TestView) BeforeClass(org.testng.annotations.BeforeClass) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PostgreSqlQueryRunner.createPostgreSqlQueryRunner(io.trino.plugin.postgresql.PostgreSqlQueryRunner.createPostgreSqlQueryRunner) UUID(java.util.UUID) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) 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) ExchangeNode(io.trino.sql.planner.plan.ExchangeNode) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle) Session(io.trino.Session) JoinCondition(io.trino.spi.connector.JoinCondition) Assert.assertEquals(org.testng.Assert.assertEquals) SUPPORTS_TOPN_PUSHDOWN(io.trino.testing.TestingConnectorBehavior.SUPPORTS_TOPN_PUSHDOWN) JdbcSqlExecutor(io.trino.testing.sql.JdbcSqlExecutor) SQLException(java.sql.SQLException) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) SUPPORTS_LIMIT_PUSHDOWN(io.trino.testing.TestingConnectorBehavior.SUPPORTS_LIMIT_PUSHDOWN) ColumnHandle(io.trino.spi.connector.ColumnHandle) SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_EQUALITY(io.trino.testing.TestingConnectorBehavior.SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_EQUALITY) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) RemoteDatabaseEvent(io.trino.plugin.jdbc.RemoteDatabaseEvent) TopNNode(io.trino.sql.planner.plan.TopNNode) TupleDomain(io.trino.spi.predicate.TupleDomain) BaseJdbcConnectorTest(io.trino.plugin.jdbc.BaseJdbcConnectorTest) PlanMatchPattern.node(io.trino.sql.planner.assertions.PlanMatchPattern.node) QueryRunner(io.trino.testing.QueryRunner) Statement(java.sql.Statement) Assert.assertTrue(org.testng.Assert.assertTrue) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) DriverManager(java.sql.DriverManager) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ColumnHandle(io.trino.spi.connector.ColumnHandle) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) TableScanNode(io.trino.sql.planner.plan.TableScanNode) JoinNode(io.trino.sql.planner.plan.JoinNode) FilterNode(io.trino.sql.planner.plan.FilterNode) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle) Session(io.trino.Session) Test(org.testng.annotations.Test) BaseJdbcConnectorTest(io.trino.plugin.jdbc.BaseJdbcConnectorTest)

Aggregations

TupleDomain (io.trino.spi.predicate.TupleDomain)97 Domain (io.trino.spi.predicate.Domain)77 Map (java.util.Map)50 ColumnHandle (io.trino.spi.connector.ColumnHandle)48 ImmutableMap (com.google.common.collect.ImmutableMap)43 ImmutableList (com.google.common.collect.ImmutableList)41 List (java.util.List)40 Optional (java.util.Optional)36 Set (java.util.Set)33 Test (org.testng.annotations.Test)33 Objects.requireNonNull (java.util.Objects.requireNonNull)32 ConnectorSession (io.trino.spi.connector.ConnectorSession)29 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)28 ImmutableSet (com.google.common.collect.ImmutableSet)26 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)23 Range (io.trino.spi.predicate.Range)22 String.format (java.lang.String.format)22 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)20 TrinoException (io.trino.spi.TrinoException)20 Type (io.trino.spi.type.Type)19