@Override public Object getValue(Symbol symbol) { ColumnHandle column = assignments.get(symbol); checkArgument(column != null, "Missing column assignment for %s", symbol); if (!bindings.containsKey(column)) { return symbol.toSymbolReference(); } return bindings.get(column).getValue(); } }
@Override public Object getValue(Symbol symbol) { ColumnHandle column = assignments.get(symbol); checkArgument(column != null, "Missing column assignment for %s", symbol); if (!bindings.containsKey(column)) { return symbol.toSymbolReference(); } return bindings.get(column).getValue(); } }
private TupleDomain<ColumnHandle> toTupleDomain(Map<TpchColumnHandle, Set<NullableValue>> predicate) { return TupleDomain.withColumnDomains(predicate.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> { Type type = entry.getKey().getType(); return entry.getValue().stream() .map(nullableValue -> Domain.singleValue(type, nullableValue.getValue())) .reduce((Domain::union)) .orElse(Domain.none(type)); }))); }
private static int getSize(NullableValue nullableValue) { if (nullableValue.isNull()) { return 0; } Object value = nullableValue.getValue(); checkArgument(value instanceof Slice, "value is expected to be of Slice type"); return ((Slice) value).length(); }
private TupleDomain<ColumnHandle> toTupleDomain(Map<TpchColumnHandle, Set<NullableValue>> predicate) { return TupleDomain.withColumnDomains(predicate.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> { Type type = entry.getKey().getType(); return entry.getValue().stream() .map(nullableValue -> Domain.singleValue(type, nullableValue.getValue())) .reduce((Domain::union)) .orElse(Domain.none(type)); }))); }
static String getStringValue(NullableValue value) { if ((value == null) || value.isNull()) { return null; } return ((Slice) value.getValue()).toStringUtf8(); } }
/** * Convert a map of columns to values into the TupleDomain which requires * those columns to be fixed to those values. Null is allowed as a fixed value. */ public static <T> TupleDomain<T> fromFixedValues(Map<T, NullableValue> fixedValues) { return TupleDomain.withColumnDomains(fixedValues.entrySet().stream() .collect(toMap( Map.Entry::getKey, entry -> { Type type = entry.getValue().getType(); Object value = entry.getValue().getValue(); return value == null ? Domain.onlyNull(type) : Domain.singleValue(type, value); }))); }
private Optional<Expression> coerceComparisonWithRounding( Type symbolExpressionType, Expression symbolExpression, NullableValue nullableValue, ComparisonExpression.Operator comparisonOperator) { requireNonNull(nullableValue, "nullableValue is null"); if (nullableValue.isNull()) { return Optional.empty(); } Type valueType = nullableValue.getType(); Object value = nullableValue.getValue(); return floorValue(valueType, symbolExpressionType, value) .map((floorValue) -> rewriteComparisonExpression(symbolExpressionType, symbolExpression, valueType, value, floorValue, comparisonOperator)); }
private Optional<Expression> coerceComparisonWithRounding( Type symbolExpressionType, Expression symbolExpression, NullableValue nullableValue, ComparisonExpression.Operator comparisonOperator) { requireNonNull(nullableValue, "nullableValue is null"); if (nullableValue.isNull()) { return Optional.empty(); } Type valueType = nullableValue.getType(); Object value = nullableValue.getValue(); return floorValue(valueType, symbolExpressionType, value) .map((floorValue) -> rewriteComparisonExpression(symbolExpressionType, symbolExpression, valueType, value, floorValue, comparisonOperator)); }
private Optional<HivePartition> parseValuesAndFilterPartition( SchemaTableName tableName, String partitionId, List<HiveColumnHandle> partitionColumns, List<Type> partitionColumnTypes, Constraint<ColumnHandle> constraint) { HivePartition partition = parsePartition(tableName, partitionId, partitionColumns, partitionColumnTypes, timeZone); Map<ColumnHandle, Domain> domains = constraint.getSummary().getDomains().get(); for (HiveColumnHandle column : partitionColumns) { NullableValue value = partition.getKeys().get(column); Domain allowedDomain = domains.get(column); if (allowedDomain != null && !allowedDomain.includesNullableValue(value.getValue())) { return Optional.empty(); } } if (constraint.predicate().isPresent() && !constraint.predicate().get().test(partition.getKeys())) { return Optional.empty(); } return Optional.of(partition); }
@Override public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) { TupleDomain<ColumnHandle> targetTupleDomain = constraint.transform(fieldIdToColumnHandle::get); Predicate<Map<ColumnHandle, NullableValue>> targetPredicate = convertToPredicate(targetTupleDomain); Constraint<ColumnHandle> targetConstraint = new Constraint<>(targetTupleDomain, targetPredicate); Iterable<List<Object>> records = () -> stream(partitionManager.getPartitions(metastore, sourceTableHandle, targetConstraint).getPartitions()) .map(hivePartition -> (List<Object>) IntStream.range(0, partitionColumns.size()) .mapToObj(fieldIdToColumnHandle::get) .map(columnHandle -> hivePartition.getKeys().get(columnHandle).getValue()) .collect(toList())) .iterator(); return new InMemoryRecordSet(partitionColumnTypes, records).cursor(); } };
HiveColumnHandle colHandle = (HiveColumnHandle) entry.getKey(); if (!entry.getValue().isNull() && bucketColumns.contains(colHandle.getName())) { bucketBindings.put(colHandle.getName(), entry.getValue().getValue());
private static Domain buildColumnDomain(ColumnHandle column, List<HivePartition> partitions) { checkArgument(!partitions.isEmpty(), "partitions cannot be empty"); boolean hasNull = false; List<Object> nonNullValues = new ArrayList<>(); Type type = null; for (HivePartition partition : partitions) { NullableValue value = partition.getKeys().get(column); if (value == null) { throw new PrestoException(HIVE_UNKNOWN_ERROR, format("Partition %s does not have a value for partition column %s", partition, column)); } if (value.isNull()) { hasNull = true; } else { nonNullValues.add(value.getValue()); } if (type == null) { type = value.getType(); } } if (!nonNullValues.isEmpty()) { Domain domain = Domain.multipleValues(type, nonNullValues); if (hasNull) { return domain.union(Domain.onlyNull(type)); } return domain; } return Domain.onlyNull(type); }
List<Type> rawFixedTypes = new ArrayList<>(fixedValueColumns.size()); for (ColumnHandle fixedValueColumn : fixedValueColumns) { rawFixedValues.add(fixedValues.get(fixedValueColumn).getValue()); rawFixedTypes.add(((TpchColumnHandle) fixedValueColumn).getType());
private static void assertConvertPartitionValueToDouble(Type type, String value, double expected) { Object prestoValue = parsePartitionValue(format("p=%s", value), value, type, DateTimeZone.getDefault()).getValue(); assertEquals(convertPartitionValueToDouble(type, prestoValue), expected); }
private static void assertConvertPartitionValueToDouble(Type type, String value, double expected) { Object prestoValue = parsePartitionValue(format("p=%s", value), value, type, DateTimeZone.getDefault()).getValue(); assertEquals(convertPartitionValueToDouble(type, prestoValue), expected); }
NullableValue value = normalized.getValue(); return createComparisonExtractionResult(normalized.getComparisonOperator(), symbol, type, value.getValue(), complement);