use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.
the class HivePageSourceProvider method shouldSkipPartition.
private static boolean shouldSkipPartition(TypeManager typeManager, HiveTableLayoutHandle hiveLayout, DateTimeZone hiveStorageTimeZone, HiveSplit hiveSplit, SplitContext splitContext) {
List<HiveColumnHandle> partitionColumns = hiveLayout.getPartitionColumns();
List<Type> partitionTypes = partitionColumns.stream().map(column -> typeManager.getType(column.getTypeSignature())).collect(toList());
List<HivePartitionKey> partitionKeys = hiveSplit.getPartitionKeys();
if (!splitContext.getDynamicFilterPredicate().isPresent() || hiveSplit.getPartitionKeys().isEmpty() || partitionColumns.isEmpty() || partitionColumns.size() != partitionKeys.size()) {
return false;
}
TupleDomain<ColumnHandle> dynamicFilter = splitContext.getDynamicFilterPredicate().get();
Map<ColumnHandle, Domain> domains = dynamicFilter.getDomains().get();
for (int i = 0; i < partitionKeys.size(); i++) {
Type type = partitionTypes.get(i);
HivePartitionKey hivePartitionKey = partitionKeys.get(i);
HiveColumnHandle hiveColumnHandle = partitionColumns.get(i);
Domain allowedDomain = domains.get(hiveColumnHandle);
NullableValue value = parsePartitionValue(hivePartitionKey, type, hiveStorageTimeZone);
if (allowedDomain != null && !allowedDomain.includesNullableValue(value.getValue())) {
return true;
}
}
return false;
}
use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.
the class HivePartitionManager method createPartitionPredicates.
private Map<Column, Domain> createPartitionPredicates(SemiTransactionalHiveMetastore metastore, ConnectorSession session, TupleDomain<ColumnHandle> effectivePredicateColumnHandles, List<HiveColumnHandle> partitionColumns, boolean assumeCanonicalPartitionKeys) {
Optional<Map<ColumnHandle, Domain>> domains = effectivePredicateColumnHandles.getDomains();
if (domains.isPresent()) {
Map<ColumnHandle, Domain> columnHandleDomainMap = domains.get();
ImmutableMap.Builder<Column, Domain> partitionPredicateBuilder = ImmutableMap.builder();
MetastoreContext metastoreContext = new MetastoreContext(session.getIdentity(), session.getQueryId(), session.getClientInfo(), session.getSource(), getMetastoreHeaders(session), isUserDefinedTypeEncodingEnabled(session), metastore.getColumnConverterProvider());
for (HiveColumnHandle partitionColumn : partitionColumns) {
Column key = new Column(partitionColumn.getName(), partitionColumn.getHiveType(), partitionColumn.getComment(), metastoreContext.getColumnConverter().getTypeMetadata(partitionColumn.getHiveType(), partitionColumn.getTypeSignature()));
if (columnHandleDomainMap.containsKey(partitionColumn)) {
if (assumeCanonicalPartitionKeys) {
partitionPredicateBuilder.put(key, columnHandleDomainMap.get(partitionColumn));
} else {
Type type = typeManager.getType(partitionColumn.getTypeSignature());
if (type instanceof VarcharType || type instanceof CharType) {
partitionPredicateBuilder.put(key, columnHandleDomainMap.get(partitionColumn));
} else {
Domain allDomain = Domain.all(typeManager.getType(partitionColumn.getTypeSignature()));
partitionPredicateBuilder.put(key, allDomain);
}
}
} else {
Domain allDomain = Domain.all(typeManager.getType(partitionColumn.getTypeSignature()));
partitionPredicateBuilder.put(key, allDomain);
}
}
return partitionPredicateBuilder.build();
} else {
return ImmutableMap.of();
}
}
use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.
the class Util method domainsMatch.
/**
* @param expectedDomains if empty, the actualConstraint's domains must also be empty.
*/
static boolean domainsMatch(Optional<Map<String, Domain>> expectedDomains, TupleDomain<ColumnHandle> actualConstraint, TableHandle tableHandle, Session session, Metadata metadata) {
Optional<Map<ColumnHandle, Domain>> actualDomains = actualConstraint.getDomains();
if (expectedDomains.isPresent() != actualDomains.isPresent()) {
return false;
}
if (!expectedDomains.isPresent()) {
return true;
}
Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
for (Map.Entry<String, Domain> expectedColumnConstraint : expectedDomains.get().entrySet()) {
if (!columnHandles.containsKey(expectedColumnConstraint.getKey())) {
return false;
}
ColumnHandle columnHandle = columnHandles.get(expectedColumnConstraint.getKey());
if (!actualDomains.get().containsKey(columnHandle)) {
return false;
}
if (!expectedColumnConstraint.getValue().contains(actualDomains.get().get(columnHandle))) {
return false;
}
}
return true;
}
use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.
the class ElasticsearchQueryBuilder method buildSearchQuery.
public static QueryBuilder buildSearchQuery(ConnectorSession session, TupleDomain<ElasticsearchColumnHandle> constraint, Optional<String> query) {
BoolQueryBuilder queryBuilder = new BoolQueryBuilder();
if (constraint.getDomains().isPresent()) {
for (Map.Entry<ElasticsearchColumnHandle, Domain> entry : constraint.getDomains().get().entrySet()) {
ElasticsearchColumnHandle column = entry.getKey();
Domain domain = entry.getValue();
checkArgument(!domain.isNone(), "Unexpected NONE domain for %s", column.getName());
if (!domain.isAll()) {
queryBuilder.filter(new BoolQueryBuilder().must(buildPredicate(session, column.getName(), domain, column.getType())));
}
}
}
query.map(QueryStringQueryBuilder::new).ifPresent(queryBuilder::must);
if (queryBuilder.hasClauses()) {
return queryBuilder;
}
return new MatchAllQueryBuilder();
}
use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.
the class TestRowExpressionDomainTranslator method testBooleanAll.
@Test
public void testBooleanAll() {
RowExpression rowExpression = or(or(equal(C_BOOLEAN, constant(true, BOOLEAN)), equal(C_BOOLEAN, constant(false, BOOLEAN))), isNull(C_BOOLEAN));
ExtractionResult result = fromPredicate(rowExpression);
TupleDomain tupleDomain = result.getTupleDomain();
assertTrue(tupleDomain.isAll());
}
Aggregations