use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.
the class TestExpressionDomainTranslator method testToPredicateAllIgnored.
@Test
public void testToPredicateAllIgnored() {
TupleDomain<String> tupleDomain = withColumnDomains(ImmutableMap.<String, Domain>builder().put(C_BIGINT, Domain.singleValue(BIGINT, 1L)).put(C_DOUBLE, Domain.onlyNull(DOUBLE)).put(C_VARCHAR, Domain.notNull(VARCHAR)).put(C_BOOLEAN, Domain.all(BOOLEAN)).build());
ExtractionResult result = fromPredicate(toPredicate(tupleDomain));
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<String, Domain>builder().put(C_BIGINT, Domain.singleValue(BIGINT, 1L)).put(C_DOUBLE, Domain.onlyNull(DOUBLE)).put(C_VARCHAR, Domain.notNull(VARCHAR)).build()));
}
use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.
the class TestLocalDynamicFilter method testMultiplePartitionsAndColumns.
@Test
public void testMultiplePartitionsAndColumns() throws ExecutionException, InterruptedException {
LocalDynamicFilter filter = new LocalDynamicFilter(ImmutableMultimap.of("123", new DynamicFilterPlaceholder("123", new VariableReferenceExpression(Optional.empty(), "a", INTEGER), EQUAL), "456", new DynamicFilterPlaceholder("456", new VariableReferenceExpression(Optional.empty(), "b", BIGINT), EQUAL)), ImmutableMap.of("123", 0, "456", 1), 2);
assertEquals(filter.getBuildChannels(), ImmutableMap.of("123", 0, "456", 1));
Consumer<TupleDomain<String>> consumer = filter.getTupleDomainConsumer();
ListenableFuture<TupleDomain<VariableReferenceExpression>> result = filter.getResultFuture();
assertFalse(result.isDone());
consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of("123", Domain.singleValue(INTEGER, 10L), "456", Domain.singleValue(BIGINT, 100L))));
assertFalse(result.isDone());
consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of("123", Domain.singleValue(INTEGER, 20L), "456", Domain.singleValue(BIGINT, 200L))));
assertEquals(result.get(), TupleDomain.withColumnDomains(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "a", INTEGER), Domain.multipleValues(INTEGER, ImmutableList.of(10L, 20L)), new VariableReferenceExpression(Optional.empty(), "b", BIGINT), Domain.multipleValues(BIGINT, ImmutableList.of(100L, 200L)))));
}
use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.
the class TestHiveLogicalPlanner method assertTableLayout.
private void assertTableLayout(Plan plan, String tableName, TupleDomain<Subfield> domainPredicate, RowExpression remainingPredicate, Set<String> predicateColumnNames) {
TableScanNode tableScan = searchFrom(plan.getRoot()).where(node -> isTableScanNode(node, tableName)).findOnlyElement();
assertTrue(tableScan.getTable().getLayout().isPresent());
HiveTableLayoutHandle layoutHandle = (HiveTableLayoutHandle) tableScan.getTable().getLayout().get();
assertEquals(layoutHandle.getPredicateColumns().keySet(), predicateColumnNames);
assertEquals(layoutHandle.getDomainPredicate(), domainPredicate);
assertEquals(layoutHandle.getRemainingPredicate(), remainingPredicate);
assertEquals(layoutHandle.getRemainingPredicate(), remainingPredicate);
}
use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.
the class TestDynamicFilterSourceOperator method testMultipleColumnsCollectMinMaxRangeWhenTooManyPositions.
@Test
public void testMultipleColumnsCollectMinMaxRangeWhenTooManyPositions() {
int maxPositionsCount = 300;
Page largePage = new Page(createLongSequenceBlock(0, 101), createColorSequenceBlock(100, 201), createLongSequenceBlock(200, 301));
List<TupleDomain<String>> expectedTupleDomains = ImmutableList.of(TupleDomain.withColumnDomains(ImmutableMap.of("0", Domain.create(ValueSet.ofRanges(range(BIGINT, 0L, true, 100L, true)), false), "2", Domain.create(ValueSet.ofRanges(range(BIGINT, 200L, true, 300L, true)), false))));
assertDynamicFilters(maxPositionsCount, ImmutableList.of(BIGINT, COLOR, BIGINT), ImmutableList.of(largePage), expectedTupleDomains);
}
use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.
the class HiveMetadata method getPartitionsSystemTable.
private Optional<SystemTable> getPartitionsSystemTable(ConnectorSession session, SchemaTableName tableName, SchemaTableName sourceTableName) {
HiveTableHandle sourceTableHandle = getTableHandle(session, sourceTableName);
if (sourceTableHandle == null) {
return Optional.empty();
}
MetastoreContext metastoreContext = getMetastoreContext(session);
Table sourceTable = metastore.getTable(metastoreContext, sourceTableName.getSchemaName(), sourceTableName.getTableName()).orElseThrow(() -> new TableNotFoundException(sourceTableName));
List<HiveColumnHandle> partitionColumns = getPartitionKeyColumnHandles(sourceTable);
if (partitionColumns.isEmpty()) {
return Optional.empty();
}
List<Type> partitionColumnTypes = partitionColumns.stream().map(HiveColumnHandle::getTypeSignature).map(typeManager::getType).collect(toImmutableList());
List<ColumnMetadata> partitionSystemTableColumns = partitionColumns.stream().map(column -> new ColumnMetadata(column.getName(), typeManager.getType(column.getTypeSignature()), column.getComment().orElse(null), column.isHidden())).collect(toImmutableList());
Map<Integer, HiveColumnHandle> fieldIdToColumnHandle = IntStream.range(0, partitionColumns.size()).boxed().collect(toImmutableMap(identity(), partitionColumns::get));
return Optional.of(createSystemTable(new ConnectorTableMetadata(tableName, partitionSystemTableColumns), constraint -> {
TupleDomain<ColumnHandle> targetTupleDomain = constraint.transform(fieldIdToColumnHandle::get);
Predicate<Map<ColumnHandle, NullableValue>> targetPredicate = convertToPredicate(targetTupleDomain);
Constraint targetConstraint = new Constraint(targetTupleDomain, targetPredicate);
Iterable<List<Object>> records = () -> stream(partitionManager.getPartitionsIterator(metastore, sourceTableHandle, targetConstraint, session)).map(hivePartition -> IntStream.range(0, partitionColumns.size()).mapToObj(fieldIdToColumnHandle::get).map(columnHandle -> ((HivePartition) hivePartition).getKeys().get(columnHandle).getValue()).collect(toList())).iterator();
return new InMemoryRecordSet(partitionColumnTypes, records).cursor();
}));
}
Aggregations