Search in sources :

Example 76 with TupleDomain

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

the class TableStatisticsMaker method dataFileMatches.

private boolean dataFileMatches(DataFile dataFile, Constraint constraint, List<PartitionField> partitionFields, Map<Integer, ColumnFieldDetails> fieldDetails) {
    // Currently this method is used only for IcebergMetadata.getTableStatistics and there Constraint never carries a predicate.
    // TODO support pruning with constraint when this changes.
    verify(constraint.predicate().isEmpty(), "Unexpected Constraint predicate");
    TupleDomain<ColumnHandle> constraintSummary = constraint.getSummary();
    Map<ColumnHandle, Domain> domains = constraintSummary.getDomains().get();
    for (int index = 0; index < partitionFields.size(); index++) {
        PartitionField field = partitionFields.get(index);
        int fieldId = field.fieldId();
        ColumnFieldDetails details = fieldDetails.get(fieldId);
        IcebergColumnHandle column = details.getColumnHandle();
        Object value = convertIcebergValueToTrino(details.getIcebergType(), dataFile.partition().get(index, details.getJavaClass()));
        Domain allowedDomain = domains.get(column);
        if (allowedDomain != null && !allowedDomain.includesNullableValue(value)) {
            return false;
        }
    }
    return true;
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) PartitionField(org.apache.iceberg.PartitionField) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) Constraint(io.trino.spi.connector.Constraint)

Example 77 with TupleDomain

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

the class TestLocalDynamicFilterConsumer method testShortCircuitOnAllTupleDomain.

@Test
public void testShortCircuitOnAllTupleDomain() throws Exception {
    LocalDynamicFilterConsumer filter = new LocalDynamicFilterConsumer(ImmutableMap.of(new DynamicFilterId("123"), 0), ImmutableMap.of(new DynamicFilterId("123"), INTEGER), 2);
    Consumer<TupleDomain<DynamicFilterId>> consumer = filter.getTupleDomainConsumer();
    ListenableFuture<Map<DynamicFilterId, Domain>> result = filter.getDynamicFilterDomains();
    assertFalse(result.isDone());
    consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("123"), Domain.all(INTEGER))));
    assertEquals(result.get(), ImmutableMap.of(new DynamicFilterId("123"), Domain.all(INTEGER)));
    // adding another partition domain won't change final domain
    consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("123"), Domain.singleValue(INTEGER, 1L))));
    assertEquals(result.get(), ImmutableMap.of(new DynamicFilterId("123"), Domain.all(INTEGER)));
}
Also used : TupleDomain(io.trino.spi.predicate.TupleDomain) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 78 with TupleDomain

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

the class TestLocalDynamicFilterConsumer method testMultipleColumns.

@Test
public void testMultipleColumns() throws Exception {
    LocalDynamicFilterConsumer filter = new LocalDynamicFilterConsumer(ImmutableMap.of(new DynamicFilterId("123"), 0, new DynamicFilterId("456"), 1), ImmutableMap.of(new DynamicFilterId("123"), INTEGER, new DynamicFilterId("456"), INTEGER), 1);
    assertEquals(filter.getBuildChannels(), ImmutableMap.of(new DynamicFilterId("123"), 0, new DynamicFilterId("456"), 1));
    Consumer<TupleDomain<DynamicFilterId>> consumer = filter.getTupleDomainConsumer();
    ListenableFuture<Map<DynamicFilterId, Domain>> result = filter.getDynamicFilterDomains();
    assertFalse(result.isDone());
    consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("123"), Domain.singleValue(INTEGER, 10L), new DynamicFilterId("456"), Domain.singleValue(INTEGER, 20L))));
    assertEquals(result.get(), ImmutableMap.of(new DynamicFilterId("123"), Domain.singleValue(INTEGER, 10L), new DynamicFilterId("456"), Domain.singleValue(INTEGER, 20L)));
}
Also used : TupleDomain(io.trino.spi.predicate.TupleDomain) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 79 with TupleDomain

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

the class TestLocalDynamicFilterConsumer method testSimple.

@Test
public void testSimple() throws Exception {
    LocalDynamicFilterConsumer filter = new LocalDynamicFilterConsumer(ImmutableMap.of(new DynamicFilterId("123"), 0), ImmutableMap.of(new DynamicFilterId("123"), INTEGER), 1);
    assertEquals(filter.getBuildChannels(), ImmutableMap.of(new DynamicFilterId("123"), 0));
    Consumer<TupleDomain<DynamicFilterId>> consumer = filter.getTupleDomainConsumer();
    ListenableFuture<Map<DynamicFilterId, Domain>> result = filter.getDynamicFilterDomains();
    assertFalse(result.isDone());
    consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("123"), Domain.singleValue(INTEGER, 7L))));
    assertEquals(result.get(), ImmutableMap.of(new DynamicFilterId("123"), Domain.singleValue(INTEGER, 7L)));
}
Also used : TupleDomain(io.trino.spi.predicate.TupleDomain) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 80 with TupleDomain

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

the class TestLocalDynamicFilterConsumer method testAllDomain.

@Test
public void testAllDomain() throws Exception {
    DynamicFilterId filter1 = new DynamicFilterId("123");
    DynamicFilterId filter2 = new DynamicFilterId("124");
    LocalDynamicFilterConsumer filter = new LocalDynamicFilterConsumer(ImmutableMap.of(filter1, 0, filter2, 1), ImmutableMap.of(filter1, INTEGER, filter2, INTEGER), 1);
    Consumer<TupleDomain<DynamicFilterId>> consumer = filter.getTupleDomainConsumer();
    ListenableFuture<Map<DynamicFilterId, Domain>> result = filter.getDynamicFilterDomains();
    assertFalse(result.isDone());
    consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of(filter1, Domain.all(INTEGER), filter2, Domain.singleValue(INTEGER, 1L))));
    assertEquals(result.get(), ImmutableMap.of(filter1, Domain.all(INTEGER), filter2, Domain.singleValue(INTEGER, 1L)));
}
Also used : TupleDomain(io.trino.spi.predicate.TupleDomain) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

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