use of io.trino.spi.predicate.Domain in project trino by trinodb.
the class TestHiveMetadata method testCreatePredicate.
@Test(timeOut = 10_000)
public void testCreatePredicate() {
ImmutableList.Builder<HivePartition> partitions = ImmutableList.builder();
for (int i = 0; i < 5_000; i++) {
partitions.add(new HivePartition(new SchemaTableName("test", "test"), Integer.toString(i), ImmutableMap.of(TEST_COLUMN_HANDLE, NullableValue.of(VARCHAR, utf8Slice(Integer.toString(i))))));
}
Domain domain = createPredicate(ImmutableList.of(TEST_COLUMN_HANDLE), partitions.build()).getDomains().orElseThrow().get(TEST_COLUMN_HANDLE);
assertEquals(domain, Domain.create(ValueSet.copyOf(VARCHAR, IntStream.range(0, 5_000).mapToObj(i -> utf8Slice(Integer.toString(i))).collect(toImmutableList())), false));
}
use of io.trino.spi.predicate.Domain in project trino by trinodb.
the class TestHiveMetadata method testCreateOnlyNullsPredicate.
@Test
public void testCreateOnlyNullsPredicate() {
ImmutableList.Builder<HivePartition> partitions = ImmutableList.builder();
for (int i = 0; i < 5; i++) {
partitions.add(new HivePartition(new SchemaTableName("test", "test"), Integer.toString(i), ImmutableMap.of(TEST_COLUMN_HANDLE, NullableValue.asNull(VARCHAR))));
}
Domain domain = createPredicate(ImmutableList.of(TEST_COLUMN_HANDLE), partitions.build()).getDomains().orElseThrow().get(TEST_COLUMN_HANDLE);
assertEquals(domain, Domain.onlyNull(VARCHAR));
}
use of io.trino.spi.predicate.Domain 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.Domain in project trino by trinodb.
the class TestLocalDynamicFiltersCollector method testDynamicFilterCoercion.
@Test
public void testDynamicFilterCoercion() {
LocalDynamicFiltersCollector collector = new LocalDynamicFiltersCollector(TEST_SESSION);
DynamicFilterId filterId = new DynamicFilterId("filter");
collector.register(ImmutableSet.of(filterId));
SymbolAllocator symbolAllocator = new SymbolAllocator();
Symbol symbol = symbolAllocator.newSymbol("symbol", INTEGER);
ColumnHandle column = new TestingColumnHandle("column");
DynamicFilter filter = createDynamicFilter(collector, ImmutableList.of(new DynamicFilters.Descriptor(filterId, new Cast(symbol.toSymbolReference(), toSqlType(BIGINT)))), ImmutableMap.of(symbol, column), symbolAllocator.getTypes());
assertEquals(filter.getColumnsCovered(), Set.of(column), "columns covered");
// Filter is blocked and not completed.
CompletableFuture<?> isBlocked = filter.isBlocked();
assertFalse(filter.isComplete());
assertTrue(filter.isAwaitable());
assertFalse(isBlocked.isDone());
assertEquals(filter.getCurrentPredicate(), TupleDomain.all());
Domain domain = Domain.singleValue(BIGINT, 7L);
collector.collectDynamicFilterDomains(ImmutableMap.of(filterId, domain));
// Unblocked and completed.
assertTrue(filter.isComplete());
assertFalse(filter.isAwaitable());
assertTrue(isBlocked.isDone());
assertEquals(filter.getCurrentPredicate(), TupleDomain.withColumnDomains(ImmutableMap.of(column, Domain.singleValue(INTEGER, 7L))));
}
use of io.trino.spi.predicate.Domain 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())));
}
Aggregations