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));
}
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;
}
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);
}
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;
}
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();
}
Aggregations