Search in sources :

Example 1 with Domain

use of com.facebook.presto.spi.predicate.Domain in project presto by prestodb.

the class AccumuloSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout) {
    AccumuloTableLayoutHandle layoutHandle = (AccumuloTableLayoutHandle) layout;
    AccumuloTableHandle tableHandle = layoutHandle.getTable();
    String schemaName = tableHandle.getSchema();
    String tableName = tableHandle.getTable();
    String rowIdName = tableHandle.getRowId();
    // Get non-row ID column constraints
    List<AccumuloColumnConstraint> constraints = getColumnConstraints(rowIdName, layoutHandle.getConstraint());
    // Get the row domain column range
    Optional<Domain> rDom = getRangeDomain(rowIdName, layoutHandle.getConstraint());
    // Call out to our client to retrieve all tablet split metadata using the row ID domain and the secondary index
    List<TabletSplitMetadata> tabletSplits = client.getTabletSplits(session, schemaName, tableName, rDom, constraints, tableHandle.getSerializerInstance());
    // Pack the tablet split metadata into a connector split
    ImmutableList.Builder<ConnectorSplit> cSplits = ImmutableList.builder();
    for (TabletSplitMetadata splitMetadata : tabletSplits) {
        AccumuloSplit split = new AccumuloSplit(connectorId, schemaName, tableName, rowIdName, tableHandle.getSerializerClassName(), splitMetadata.getRanges().stream().map(WrappedRange::new).collect(Collectors.toList()), constraints, tableHandle.getScanAuthorizations(), splitMetadata.getHostPort());
        cSplits.add(split);
    }
    return new FixedSplitSource(cSplits.build());
}
Also used : AccumuloColumnConstraint(com.facebook.presto.accumulo.model.AccumuloColumnConstraint) ImmutableList(com.google.common.collect.ImmutableList) TabletSplitMetadata(com.facebook.presto.accumulo.model.TabletSplitMetadata) AccumuloSplit(com.facebook.presto.accumulo.model.AccumuloSplit) WrappedRange(com.facebook.presto.accumulo.model.WrappedRange) AccumuloTableLayoutHandle(com.facebook.presto.accumulo.model.AccumuloTableLayoutHandle) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) AccumuloTableHandle(com.facebook.presto.accumulo.model.AccumuloTableHandle) ColumnDomain(com.facebook.presto.spi.predicate.TupleDomain.ColumnDomain) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 2 with Domain

use of com.facebook.presto.spi.predicate.Domain in project presto by prestodb.

the class AtopSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layoutHandle) {
    AtopTableLayoutHandle handle = (AtopTableLayoutHandle) layoutHandle;
    AtopTableHandle table = handle.getTableHandle();
    List<ConnectorSplit> splits = new ArrayList<>();
    ZonedDateTime end = ZonedDateTime.now(timeZone);
    for (Node node : nodeManager.getWorkerNodes()) {
        ZonedDateTime start = end.minusDays(maxHistoryDays - 1).withHour(0).withMinute(0).withSecond(0).withNano(0);
        while (start.isBefore(end)) {
            ZonedDateTime splitEnd = start.withHour(23).withMinute(59).withSecond(59).withNano(0);
            Domain splitDomain = Domain.create(ValueSet.ofRanges(Range.range(TIMESTAMP_WITH_TIME_ZONE, 1000 * start.toEpochSecond(), true, 1000 * splitEnd.toEpochSecond(), true)), false);
            if (handle.getStartTimeConstraint().overlaps(splitDomain) && handle.getEndTimeConstraint().overlaps(splitDomain)) {
                splits.add(new AtopSplit(table.getTable(), node.getHostAndPort(), start.toEpochSecond(), start.getZone()));
            }
            start = start.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
        }
    }
    return new FixedSplitSource(splits);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) Node(com.facebook.presto.spi.Node) ArrayList(java.util.ArrayList) Domain(com.facebook.presto.spi.predicate.Domain) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 3 with Domain

use of com.facebook.presto.spi.predicate.Domain in project presto by prestodb.

the class HivePartitionManager method parseValuesAndFilterPartition.

private Optional<Map<ColumnHandle, NullableValue>> parseValuesAndFilterPartition(String partitionName, List<HiveColumnHandle> partitionColumns, List<Type> partitionTypes, Constraint<ColumnHandle> constraint) {
    List<String> partitionValues = extractPartitionKeyValues(partitionName);
    Map<ColumnHandle, Domain> domains = constraint.getSummary().getDomains().get();
    ImmutableMap.Builder<ColumnHandle, NullableValue> builder = ImmutableMap.builder();
    for (int i = 0; i < partitionColumns.size(); i++) {
        HiveColumnHandle column = partitionColumns.get(i);
        NullableValue parsedValue = parsePartitionValue(partitionName, partitionValues.get(i), partitionTypes.get(i), timeZone);
        Domain allowedDomain = domains.get(column);
        if (allowedDomain != null && !allowedDomain.includesNullableValue(parsedValue.getValue())) {
            return Optional.empty();
        }
        builder.put(column, parsedValue);
    }
    Map<ColumnHandle, NullableValue> values = builder.build();
    if (!constraint.predicate().test(values)) {
        return Optional.empty();
    }
    return Optional.of(values);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) NullableValue(com.facebook.presto.spi.predicate.NullableValue) ProtectMode.getProtectModeFromString(org.apache.hadoop.hive.metastore.ProtectMode.getProtectModeFromString) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) ImmutableMap(com.google.common.collect.ImmutableMap) Constraint(com.facebook.presto.spi.Constraint)

Example 4 with Domain

use of com.facebook.presto.spi.predicate.Domain in project presto by prestodb.

the class HivePartitionManager method getFilteredPartitionNames.

private List<String> getFilteredPartitionNames(SemiTransactionalHiveMetastore metastore, SchemaTableName tableName, List<HiveColumnHandle> partitionKeys, TupleDomain<ColumnHandle> effectivePredicate) {
    checkArgument(effectivePredicate.getDomains().isPresent());
    List<String> filter = new ArrayList<>();
    for (HiveColumnHandle partitionKey : partitionKeys) {
        Domain domain = effectivePredicate.getDomains().get().get(partitionKey);
        if (domain != null && domain.isNullableSingleValue()) {
            Object value = domain.getNullableSingleValue();
            if (value == null) {
                filter.add(HivePartitionKey.HIVE_DEFAULT_DYNAMIC_PARTITION);
            } else if (value instanceof Slice) {
                filter.add(((Slice) value).toStringUtf8());
            } else if ((value instanceof Boolean) || (value instanceof Double) || (value instanceof Long)) {
                if (assumeCanonicalPartitionKeys) {
                    filter.add(value.toString());
                } else {
                    // Hive treats '0', 'false', and 'False' the same. However, the metastore differentiates between these.
                    filter.add(PARTITION_VALUE_WILDCARD);
                }
            } else {
                throw new PrestoException(NOT_SUPPORTED, "Only Boolean, Double and Long partition keys are supported");
            }
        } else {
            filter.add(PARTITION_VALUE_WILDCARD);
        }
    }
    // fetch the partition names
    return metastore.getPartitionNamesByParts(tableName.getSchemaName(), tableName.getTableName(), filter).orElseThrow(() -> new TableNotFoundException(tableName));
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Slice(io.airlift.slice.Slice) ArrayList(java.util.ArrayList) PrestoException(com.facebook.presto.spi.PrestoException) ProtectMode.getProtectModeFromString(org.apache.hadoop.hive.metastore.ProtectMode.getProtectModeFromString) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain)

Example 5 with Domain

use of com.facebook.presto.spi.predicate.Domain 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)

Aggregations

Domain (com.facebook.presto.spi.predicate.Domain)39 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)36 ImmutableList (com.google.common.collect.ImmutableList)18 Map (java.util.Map)17 ImmutableMap (com.google.common.collect.ImmutableMap)13 ColumnHandle (com.facebook.presto.spi.ColumnHandle)12 Range (com.facebook.presto.spi.predicate.Range)10 ArrayList (java.util.ArrayList)10 Type (com.facebook.presto.spi.type.Type)9 List (java.util.List)9 Test (org.testng.annotations.Test)8 ValueSet (com.facebook.presto.spi.predicate.ValueSet)7 Objects.requireNonNull (java.util.Objects.requireNonNull)7 Optional (java.util.Optional)7 PrestoException (com.facebook.presto.spi.PrestoException)6 NullableValue (com.facebook.presto.spi.predicate.NullableValue)6 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)6 ImmutableSet (com.google.common.collect.ImmutableSet)6 Slice (io.airlift.slice.Slice)6 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)4