/** * 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 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); }
Symbol symbol = Symbol.from(symbolExpression); NullableValue value = normalized.getValue(); Type type = value.getType(); // common type for symbol and value return createComparisonExtractionResult(normalized.getComparisonOperator(), symbol, type, value.getValue(), complement);
.map(argument -> { if (argument.isConstant()) { return argument.getConstant().getType();
private static Optional<String> getFilterColumn(Map<String, NullableValue> filters, String columnName) { NullableValue value = filters.get(columnName); if (value == null || value.getValue() == null) { return Optional.empty(); } if (value.getType().equals(VARCHAR)) { return Optional.of(((Slice) value.getValue()).toStringUtf8().toLowerCase(ENGLISH)); } return Optional.empty(); } }
/** * 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<NullableValue> coerce(NullableValue value, Type targetType) { if (!TypeRegistry.canCoerce(value.getType(), targetType)) { return Optional.empty(); } if (value.isNull()) { return Optional.of(NullableValue.asNull(targetType)); } Object coercedValue = new FunctionInvoker(metadata.getFunctionRegistry()) .invoke(metadata.getFunctionRegistry().getCoercion(value.getType(), targetType), session.toConnectorSession(), value.getValue()); return Optional.of(NullableValue.of(targetType, coercedValue)); }
@Override protected ExtractionResult visitComparisonExpression(ComparisonExpression node, Boolean complement) { Optional<NormalizedSimpleComparison> optionalNormalized = toNormalizedSimpleComparison(session, metadata, types, node); if (!optionalNormalized.isPresent()) { return super.visitComparisonExpression(node, complement); } NormalizedSimpleComparison normalized = optionalNormalized.get(); Symbol symbol = Symbol.fromQualifiedName(normalized.getNameReference().getName()); Type fieldType = checkedTypeLookup(symbol); NullableValue value = normalized.getValue(); // when the field is BIGINT and the value is DOUBLE, transform the expression in such a way that // the semantics are preserved while doing the comparisons in terms of double // TODO: figure out a way to generalize this for other types if (value.getType().equals(DOUBLE) && fieldType.equals(BIGINT)) { return process(coerceDoubleToLongComparison(normalized), complement); } Optional<NullableValue> coercedValue = coerce(value, fieldType); if (!coercedValue.isPresent()) { return super.visitComparisonExpression(node, complement); } return createComparisonExtractionResult(normalized.getComparisonType(), symbol, fieldType, coercedValue.get().getValue(), complement); }
.map(argument -> { if (argument.isConstant()) { return argument.getConstant().getType();
private static Expression coerceDoubleToLongComparison(NormalizedSimpleComparison normalized) checkArgument(normalized.getValue().getType().equals(DOUBLE), "Value should be of DOUBLE type"); checkArgument(!normalized.getValue().isNull(), "Value should not be null"); QualifiedNameReference reference = normalized.getNameReference();