use of com.facebook.presto.spi.predicate.ValueSet in project presto by prestodb.
the class HivePartitionManager method toCompactTupleDomain.
private static TupleDomain<HiveColumnHandle> toCompactTupleDomain(TupleDomain<ColumnHandle> effectivePredicate, int threshold) {
checkArgument(effectivePredicate.getDomains().isPresent());
ImmutableMap.Builder<HiveColumnHandle, Domain> builder = ImmutableMap.builder();
for (Map.Entry<ColumnHandle, Domain> entry : effectivePredicate.getDomains().get().entrySet()) {
HiveColumnHandle hiveColumnHandle = (HiveColumnHandle) entry.getKey();
ValueSet values = entry.getValue().getValues();
ValueSet compactValueSet = values.getValuesProcessor().<Optional<ValueSet>>transform(ranges -> ranges.getRangeCount() > threshold ? Optional.of(ValueSet.ofRanges(ranges.getSpan())) : Optional.empty(), discreteValues -> discreteValues.getValues().size() > threshold ? Optional.of(ValueSet.all(values.getType())) : Optional.empty(), allOrNone -> Optional.empty()).orElse(values);
builder.put(hiveColumnHandle, Domain.create(compactValueSet, entry.getValue().isNullAllowed()));
}
return TupleDomain.withColumnDomains(builder.build());
}
use of com.facebook.presto.spi.predicate.ValueSet in project presto by prestodb.
the class HiveBucketing method getHiveBucketNumbers.
public static List<HiveBucket> getHiveBucketNumbers(Table table, TupleDomain<ColumnHandle> effectivePredicate) {
if (!table.getStorage().getBucketProperty().isPresent()) {
return ImmutableList.of();
}
Optional<Map<ColumnHandle, NullableValue>> bindings = TupleDomain.extractFixedValues(effectivePredicate);
if (!bindings.isPresent()) {
return ImmutableList.of();
}
Optional<HiveBucket> singleBucket = getHiveBucket(table, bindings.get());
if (singleBucket.isPresent()) {
return ImmutableList.of(singleBucket.get());
}
if (!effectivePredicate.getDomains().isPresent()) {
return ImmutableList.of();
}
Optional<Domain> domain = effectivePredicate.getDomains().get().entrySet().stream().filter(entry -> ((HiveColumnHandle) entry.getKey()).getName().equals(BUCKET_COLUMN_NAME)).findFirst().map(Entry::getValue);
if (!domain.isPresent()) {
return ImmutableList.of();
}
ValueSet values = domain.get().getValues();
ImmutableList.Builder<HiveBucket> builder = ImmutableList.builder();
int bucketCount = table.getStorage().getBucketProperty().get().getBucketCount();
for (int i = 0; i < bucketCount; i++) {
if (values.containsValue((long) i)) {
builder.add(new HiveBucket(i, bucketCount));
}
}
return builder.build();
}
use of com.facebook.presto.spi.predicate.ValueSet in project presto by prestodb.
the class DomainUtils method simplifyDomain.
/**
* Reduces the number of discrete components in the Domain if there are too many.
*/
public static Domain simplifyDomain(Domain domain) {
ValueSet values = domain.getValues();
ValueSet simplifiedValueSet = values.getValuesProcessor().<Optional<ValueSet>>transform(ranges -> {
if (ranges.getOrderedRanges().size() <= 32) {
return Optional.empty();
}
return Optional.of(ValueSet.ofRanges(ranges.getSpan()));
}, discreteValues -> {
if (discreteValues.getValues().size() <= 32) {
return Optional.empty();
}
return Optional.of(ValueSet.all(domain.getType()));
}, allOrNone -> Optional.empty()).orElse(values);
return Domain.create(simplifiedValueSet, domain.isNullAllowed());
}
Aggregations