Search in sources :

Example 1 with ValueSet

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());
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) Table(com.facebook.presto.hive.metastore.Table) TypeManager(com.facebook.presto.spi.type.TypeManager) Slice(io.airlift.slice.Slice) HiveUtil.getPartitionKeyColumnHandles(com.facebook.presto.hive.HiveUtil.getPartitionKeyColumnHandles) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) ProtectMode(org.apache.hadoop.hive.metastore.ProtectMode) PrestoException(com.facebook.presto.spi.PrestoException) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) Predicates.not(com.google.common.base.Predicates.not) ValueSet(com.facebook.presto.spi.predicate.ValueSet) Type(com.facebook.presto.spi.type.Type) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Predicates(com.google.common.base.Predicates) HiveBucket(com.facebook.presto.hive.HiveBucketing.HiveBucket) NullableValue(com.facebook.presto.spi.predicate.NullableValue) HIVE_EXCEEDED_PARTITION_LIMIT(com.facebook.presto.hive.HiveErrorCode.HIVE_EXCEEDED_PARTITION_LIMIT) ImmutableMap(com.google.common.collect.ImmutableMap) ProtectMode.getProtectModeFromString(org.apache.hadoop.hive.metastore.ProtectMode.getProtectModeFromString) Constraint(com.facebook.presto.spi.Constraint) SemiTransactionalHiveMetastore(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore) HiveBucketing.getHiveBucketHandle(com.facebook.presto.hive.HiveBucketing.getHiveBucketHandle) Maps(com.google.common.collect.Maps) String.format(java.lang.String.format) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) ColumnHandle(com.facebook.presto.spi.ColumnHandle) HiveBucketing.getHiveBucketNumbers(com.facebook.presto.hive.HiveBucketing.getHiveBucketNumbers) FileUtils(org.apache.hadoop.hive.common.FileUtils) Optional(java.util.Optional) HiveUtil.parsePartitionValue(com.facebook.presto.hive.HiveUtil.parsePartitionValue) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ValueSet(com.facebook.presto.spi.predicate.ValueSet) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with ValueSet

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();
}
Also used : Maps.immutableEntry(com.google.common.collect.Maps.immutableEntry) Entry(java.util.Map.Entry) ImmutableList(com.google.common.collect.ImmutableList) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) Map(java.util.Map) HashMap(java.util.HashMap) ValueSet(com.facebook.presto.spi.predicate.ValueSet)

Example 3 with ValueSet

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());
}
Also used : ImmutableBiMap(com.google.common.collect.ImmutableBiMap) Domain(com.facebook.presto.spi.predicate.Domain) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ValueSet(com.facebook.presto.spi.predicate.ValueSet) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) ValueSet(com.facebook.presto.spi.predicate.ValueSet)

Aggregations

Domain (com.facebook.presto.spi.predicate.Domain)3 ValueSet (com.facebook.presto.spi.predicate.ValueSet)3 Map (java.util.Map)3 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Optional (java.util.Optional)2 HiveBucket (com.facebook.presto.hive.HiveBucketing.HiveBucket)1 HiveBucketing.getHiveBucketHandle (com.facebook.presto.hive.HiveBucketing.getHiveBucketHandle)1 HiveBucketing.getHiveBucketNumbers (com.facebook.presto.hive.HiveBucketing.getHiveBucketNumbers)1 HIVE_EXCEEDED_PARTITION_LIMIT (com.facebook.presto.hive.HiveErrorCode.HIVE_EXCEEDED_PARTITION_LIMIT)1 HiveUtil.getPartitionKeyColumnHandles (com.facebook.presto.hive.HiveUtil.getPartitionKeyColumnHandles)1 HiveUtil.parsePartitionValue (com.facebook.presto.hive.HiveUtil.parsePartitionValue)1 SemiTransactionalHiveMetastore (com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore)1 Table (com.facebook.presto.hive.metastore.Table)1 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)1 Constraint (com.facebook.presto.spi.Constraint)1 PrestoException (com.facebook.presto.spi.PrestoException)1 SchemaTableName (com.facebook.presto.spi.SchemaTableName)1