use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.
the class TestMetastoreUtil method testComputePartitionKeyFilter.
@Test
public void testComputePartitionKeyFilter() {
HiveColumnHandle dsColumn = partitionColumn("ds");
HiveColumnHandle typeColumn = partitionColumn("type");
List<HiveColumnHandle> partitionKeys = ImmutableList.of(dsColumn, typeColumn);
Domain dsDomain = Domain.create(ValueSet.ofRanges(Range.lessThan(VARCHAR, utf8Slice("2018-05-06"))), false);
Domain typeDomain = Domain.create(ValueSet.of(VARCHAR, utf8Slice("fruit")), false);
TupleDomain<HiveColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.<HiveColumnHandle, Domain>builder().put(bucketColumnHandle(), Domain.create(ValueSet.of(INTEGER, 123L), false)).put(dsColumn, dsDomain).put(typeColumn, typeDomain).buildOrThrow());
TupleDomain<String> filter = computePartitionKeyFilter(partitionKeys, tupleDomain);
assertThat(filter.getDomains()).as("output contains only the partition keys").contains(ImmutableMap.<String, Domain>builder().put("ds", dsDomain).put("type", typeDomain).buildOrThrow());
}
use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.
the class TestDynamicFilterSourceOperator method testMultipleColumnsCollectMinMaxRangeWhenTooManyDistinctValues.
@Test
public void testMultipleColumnsCollectMinMaxRangeWhenTooManyDistinctValues() {
int maxDistinctValues = 100;
Page largePage = new Page(createLongSequenceBlock(0, 101), createColorRepeatBlock(100, 101), createLongRepeatBlock(200, 101));
List<TupleDomain<DynamicFilterId>> expectedTupleDomains = ImmutableList.of(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("0"), Domain.create(ValueSet.ofRanges(range(BIGINT, 0L, true, 100L, true)), false), new DynamicFilterId("2"), Domain.create(ValueSet.ofRanges(equal(BIGINT, 200L)), false))));
assertDynamicFilters(maxDistinctValues, ImmutableList.of(BIGINT, COLOR, BIGINT), ImmutableList.of(largePage), expectedTupleDomains);
}
use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.
the class TestDynamicFilterSourceOperator method testMultipleColumnsCollectBelowDistinctValuesLimit.
@Test
public void testMultipleColumnsCollectBelowDistinctValuesLimit() {
int maxDistinctValues = 101;
Page largePage = new Page(createLongSequenceBlock(0, 101), createLongSequenceBlock(100, 201), createLongSequenceBlock(200, 301));
List<TupleDomain<DynamicFilterId>> expectedTupleDomains = ImmutableList.of(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("0"), Domain.create(ValueSet.copyOf(BIGINT, LongStream.rangeClosed(0L, 100L).boxed().collect(toImmutableList())), false), new DynamicFilterId("1"), Domain.create(ValueSet.copyOf(BIGINT, LongStream.rangeClosed(100L, 200L).boxed().collect(toImmutableList())), false), new DynamicFilterId("2"), Domain.create(ValueSet.copyOf(BIGINT, LongStream.rangeClosed(200L, 300L).boxed().collect(toImmutableList())), false))));
assertDynamicFilters(maxDistinctValues, ImmutableList.of(BIGINT, BIGINT, BIGINT), ImmutableList.of(largePage), expectedTupleDomains);
}
use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.
the class TestLogicalPlanner method testLikePredicate.
@Test
public void testLikePredicate() {
assertPlan("SELECT type FROM part WHERE type LIKE 'LARGE PLATED %'", anyTree(tableScan(tableHandle -> {
Map<ColumnHandle, Domain> domains = ((TpchTableHandle) tableHandle).getConstraint().getDomains().orElseThrow(() -> new AssertionError("Unexpected none TupleDomain"));
Domain domain = domains.entrySet().stream().filter(entry -> ((TpchColumnHandle) entry.getKey()).getColumnName().equals("type")).map(Entry::getValue).collect(toOptional()).orElseThrow(() -> new AssertionError("No domain for 'type'"));
assertEquals(domain, Domain.multipleValues(createVarcharType(25), ImmutableList.of("LARGE PLATED BRASS", "LARGE PLATED COPPER", "LARGE PLATED NICKEL", "LARGE PLATED STEEL", "LARGE PLATED TIN").stream().map(Slices::utf8Slice).collect(toImmutableList())));
return true;
}, TupleDomain.withColumnDomains(ImmutableMap.of(tableHandle -> ((TpchColumnHandle) tableHandle).getColumnName().equals("type"), Domain.create(ValueSet.ofRanges(Range.range(createVarcharType(25), utf8Slice("LARGE PLATED "), true, utf8Slice("LARGE PLATED!"), false)), false))), ImmutableMap.of())));
}
use of io.trino.spi.predicate.TupleDomain in project trino by trinodb.
the class TestLocalDynamicFilterConsumer method testMultiplePartitionsAndColumns.
@Test
public void testMultiplePartitionsAndColumns() 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"), BIGINT), 2);
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(BIGINT, 100L))));
assertFalse(result.isDone());
consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("123"), Domain.singleValue(INTEGER, 20L), new DynamicFilterId("456"), Domain.singleValue(BIGINT, 200L))));
assertEquals(result.get(), ImmutableMap.of(new DynamicFilterId("123"), Domain.multipleValues(INTEGER, ImmutableList.of(10L, 20L)), new DynamicFilterId("456"), Domain.multipleValues(BIGINT, ImmutableList.of(100L, 200L))));
}
Aggregations