Search in sources :

Example 6 with TupleDomain

use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.

the class DeltaMetadata method getTableLayouts.

@Override
public List<ConnectorTableLayoutResult> getTableLayouts(ConnectorSession session, ConnectorTableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns) {
    DeltaTableHandle tableHandle = (DeltaTableHandle) table;
    // Split the predicate into partition column predicate and other column predicates
    // Only the partition column predicate is fully enforced. Other predicate is partially enforced (best effort).
    List<TupleDomain<ColumnHandle>> predicate = splitPredicate(constraint.getSummary());
    TupleDomain<ColumnHandle> unenforcedPredicate = predicate.get(1);
    DeltaTableLayoutHandle newDeltaTableLayoutHandle = new DeltaTableLayoutHandle(tableHandle, constraint.getSummary().transform(DeltaColumnHandle.class::cast), Optional.of(constraint.getSummary().toString(session.getSqlFunctionProperties())));
    ConnectorTableLayout newLayout = new ConnectorTableLayout(newDeltaTableLayoutHandle, Optional.empty(), constraint.getSummary(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), Optional.empty());
    return ImmutableList.of(new ConnectorTableLayoutResult(newLayout, unenforcedPredicate));
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout)

Example 7 with TupleDomain

use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.

the class DeltaExpressionUtils method evaluatePartitionPredicate.

private static boolean evaluatePartitionPredicate(TupleDomain<String> partitionPredicate, List<DeltaColumnHandle> partitionColumns, TypeManager typeManager, AddFile addFile) {
    checkArgument(!partitionPredicate.isNone(), "Expecting a predicate with at least one expression");
    for (DeltaColumnHandle partitionColumn : partitionColumns) {
        String columnName = partitionColumn.getName();
        String partitionValue = addFile.getPartitionValues().get(columnName);
        Domain domain = getDomain(partitionColumn, partitionValue, typeManager, addFile.getPath());
        Domain columnPredicate = partitionPredicate.getDomains().get().get(columnName);
        if (columnPredicate == null) {
            // there is no predicate on this column
            continue;
        }
        if (columnPredicate.intersect(domain).isNone()) {
            return false;
        }
    }
    return true;
}
Also used : Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain)

Example 8 with TupleDomain

use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.

the class TestParquetPredicateUtils method testParquetTupleDomainPrimitive.

@Test
public void testParquetTupleDomainPrimitive() {
    HiveColumnHandle columnHandle = new HiveColumnHandle("my_primitive", HiveType.valueOf("bigint"), parseTypeSignature(StandardTypes.BIGINT), 0, REGULAR, Optional.empty(), Optional.empty());
    Domain singleValueDomain = Domain.singleValue(BIGINT, 123L);
    TupleDomain<HiveColumnHandle> domain = withColumnDomains(ImmutableMap.of(columnHandle, singleValueDomain));
    MessageType fileSchema = new MessageType("hive_schema", new PrimitiveType(OPTIONAL, INT64, "my_primitive"));
    Map<List<String>, RichColumnDescriptor> descriptorsByPath = getDescriptors(fileSchema, fileSchema);
    TupleDomain<ColumnDescriptor> tupleDomain = getParquetTupleDomain(descriptorsByPath, domain);
    assertEquals(tupleDomain.getDomains().get().size(), 1);
    ColumnDescriptor descriptor = tupleDomain.getDomains().get().keySet().iterator().next();
    assertEquals(descriptor.getPath().length, 1);
    assertEquals(descriptor.getPath()[0], "my_primitive");
    Domain predicateDomain = Iterables.getOnlyElement(tupleDomain.getDomains().get().values());
    assertEquals(predicateDomain, singleValueDomain);
}
Also used : RichColumnDescriptor(com.facebook.presto.parquet.RichColumnDescriptor) RichColumnDescriptor(com.facebook.presto.parquet.RichColumnDescriptor) ColumnDescriptor(org.apache.parquet.column.ColumnDescriptor) PrimitiveType(org.apache.parquet.schema.PrimitiveType) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ParquetPageSourceFactory.getParquetTupleDomain(com.facebook.presto.hive.parquet.ParquetPageSourceFactory.getParquetTupleDomain) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) HiveColumnHandle(com.facebook.presto.hive.HiveColumnHandle) MessageType(org.apache.parquet.schema.MessageType) Test(org.testng.annotations.Test)

Example 9 with TupleDomain

use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.

the class MongoSession method buildQuery.

@VisibleForTesting
static Document buildQuery(TupleDomain<ColumnHandle> tupleDomain) {
    Document query = new Document();
    if (tupleDomain.getDomains().isPresent()) {
        for (Map.Entry<ColumnHandle, Domain> entry : tupleDomain.getDomains().get().entrySet()) {
            MongoColumnHandle column = (MongoColumnHandle) entry.getKey();
            query.putAll(buildPredicate(column, entry.getValue()));
        }
    }
    return query;
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) Document(org.bson.Document) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) Map(java.util.Map) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 10 with TupleDomain

use of com.facebook.presto.common.predicate.TupleDomain in project presto by prestodb.

the class PreparedStatementBuilder method getWhereClause.

@SuppressWarnings("OptionalGetWithoutIsPresent")
private static String getWhereClause(TupleDomain<Integer> tupleDomain, List<String> columnNames, List<Type> types, Set<Integer> uuidColumnIndexes, List<ValueBuffer> bindValues) {
    if (tupleDomain.isNone()) {
        return "";
    }
    ImmutableList.Builder<String> conjunctsBuilder = ImmutableList.builder();
    Map<Integer, Domain> domainMap = tupleDomain.getDomains().get();
    for (Map.Entry<Integer, Domain> entry : domainMap.entrySet()) {
        int index = entry.getKey();
        String columnName = columnNames.get(index);
        Type type = types.get(index);
        conjunctsBuilder.add(toPredicate(index, columnName, type, entry.getValue(), uuidColumnIndexes, bindValues));
    }
    List<String> conjuncts = conjunctsBuilder.build();
    if (conjuncts.isEmpty()) {
        return "";
    }
    StringBuilder where = new StringBuilder("WHERE ");
    return Joiner.on(" AND\n").appendTo(where, conjuncts).toString();
}
Also used : Varchars.isVarcharType(com.facebook.presto.common.type.Varchars.isVarcharType) Type(com.facebook.presto.common.type.Type) ImmutableList(com.google.common.collect.ImmutableList) UUID.fromString(java.util.UUID.fromString) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) Map(java.util.Map)

Aggregations

TupleDomain (com.facebook.presto.common.predicate.TupleDomain)76 Domain (com.facebook.presto.common.predicate.Domain)54 Map (java.util.Map)39 ColumnHandle (com.facebook.presto.spi.ColumnHandle)36 ImmutableList (com.google.common.collect.ImmutableList)33 ImmutableMap (com.google.common.collect.ImmutableMap)31 List (java.util.List)27 Optional (java.util.Optional)26 Objects.requireNonNull (java.util.Objects.requireNonNull)25 Test (org.testng.annotations.Test)25 ConnectorSession (com.facebook.presto.spi.ConnectorSession)22 SchemaTableName (com.facebook.presto.spi.SchemaTableName)22 Set (java.util.Set)21 Type (com.facebook.presto.common.type.Type)20 PrestoException (com.facebook.presto.spi.PrestoException)20 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)19 ImmutableSet (com.google.common.collect.ImmutableSet)19 String.format (java.lang.String.format)19 NullableValue (com.facebook.presto.common.predicate.NullableValue)17 TypeManager (com.facebook.presto.common.type.TypeManager)15