Search in sources :

Example 1 with FALSE_LITERAL

use of com.facebook.presto.sql.tree.BooleanLiteral.FALSE_LITERAL in project presto by prestodb.

the class ExpressionDomainTranslator method toPredicate.

private Expression toPredicate(Domain domain, SymbolReference reference) {
    if (domain.getValues().isNone()) {
        return domain.isNullAllowed() ? new IsNullPredicate(reference) : FALSE_LITERAL;
    }
    if (domain.getValues().isAll()) {
        return domain.isNullAllowed() ? TRUE_LITERAL : new NotExpression(new IsNullPredicate(reference));
    }
    List<Expression> disjuncts = new ArrayList<>();
    disjuncts.addAll(domain.getValues().getValuesProcessor().transform(ranges -> extractDisjuncts(domain.getType(), ranges, reference), discreteValues -> extractDisjuncts(domain.getType(), discreteValues, reference), allOrNone -> {
        throw new IllegalStateException("Case should not be reachable");
    }));
    // Add nullability disjuncts
    if (domain.isNullAllowed()) {
        disjuncts.add(new IsNullPredicate(reference));
    }
    return combineDisjunctsWithDefault(disjuncts, TRUE_LITERAL);
}
Also used : WarningCollector(com.facebook.presto.spi.WarningCollector) SATURATED_FLOOR_CAST(com.facebook.presto.metadata.CastType.SATURATED_FLOOR_CAST) DiscreteValues(com.facebook.presto.common.predicate.DiscreteValues) IsNullPredicate(com.facebook.presto.sql.tree.IsNullPredicate) SortedRangeSet(com.facebook.presto.common.predicate.SortedRangeSet) PeekingIterator(com.google.common.collect.PeekingIterator) NOT_EQUAL(com.facebook.presto.sql.tree.ComparisonExpression.Operator.NOT_EQUAL) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Map(java.util.Map) Marker(com.facebook.presto.common.predicate.Marker) BetweenPredicate(com.facebook.presto.sql.tree.BetweenPredicate) NotExpression(com.facebook.presto.sql.tree.NotExpression) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) NullableValue(com.facebook.presto.common.predicate.NullableValue) InterpretedFunctionInvoker(com.facebook.presto.sql.InterpretedFunctionInvoker) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.emptyList(java.util.Collections.emptyList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Range(com.facebook.presto.common.predicate.Range) SqlParser(com.facebook.presto.sql.parser.SqlParser) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TRUE_LITERAL(com.facebook.presto.sql.tree.BooleanLiteral.TRUE_LITERAL) BooleanLiteral(com.facebook.presto.sql.tree.BooleanLiteral) NullLiteral(com.facebook.presto.sql.tree.NullLiteral) ExpressionUtils.combineDisjunctsWithDefault(com.facebook.presto.sql.ExpressionUtils.combineDisjunctsWithDefault) LogicalBinaryExpression(com.facebook.presto.sql.tree.LogicalBinaryExpression) List(java.util.List) InPredicate(com.facebook.presto.sql.tree.InPredicate) OperatorNotFoundException(com.facebook.presto.metadata.OperatorNotFoundException) Optional(java.util.Optional) CAST(com.facebook.presto.metadata.CastType.CAST) GREATER_THAN_OR_EQUAL(com.facebook.presto.sql.tree.ComparisonExpression.Operator.GREATER_THAN_OR_EQUAL) Ranges(com.facebook.presto.common.predicate.Ranges) Utils(com.facebook.presto.common.Utils) ExpressionUtils.combineConjuncts(com.facebook.presto.sql.ExpressionUtils.combineConjuncts) ExpressionUtils.and(com.facebook.presto.sql.ExpressionUtils.and) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) ExpressionUtils(com.facebook.presto.sql.ExpressionUtils) ArrayList(java.util.ArrayList) LESS_THAN(com.facebook.presto.sql.tree.ComparisonExpression.Operator.LESS_THAN) InListExpression(com.facebook.presto.sql.tree.InListExpression) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Cast(com.facebook.presto.sql.tree.Cast) Comparator.comparing(java.util.Comparator.comparing) LESS_THAN_OR_EQUAL(com.facebook.presto.sql.tree.ComparisonExpression.Operator.LESS_THAN_OR_EQUAL) Iterators.peekingIterator(com.google.common.collect.Iterators.peekingIterator) Type(com.facebook.presto.common.type.Type) Nullable(javax.annotation.Nullable) ExpressionUtils.or(com.facebook.presto.sql.ExpressionUtils.or) FALSE_LITERAL(com.facebook.presto.sql.tree.BooleanLiteral.FALSE_LITERAL) Session(com.facebook.presto.Session) EQUAL(com.facebook.presto.sql.tree.ComparisonExpression.Operator.EQUAL) AstVisitor(com.facebook.presto.sql.tree.AstVisitor) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) IsNotNullPredicate(com.facebook.presto.sql.tree.IsNotNullPredicate) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) NodeRef(com.facebook.presto.sql.tree.NodeRef) Collectors.toList(java.util.stream.Collectors.toList) ExpressionAnalyzer(com.facebook.presto.sql.analyzer.ExpressionAnalyzer) Expression(com.facebook.presto.sql.tree.Expression) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) GREATER_THAN(com.facebook.presto.sql.tree.ComparisonExpression.Operator.GREATER_THAN) Block(com.facebook.presto.common.block.Block) ValueSet(com.facebook.presto.common.predicate.ValueSet) Metadata(com.facebook.presto.metadata.Metadata) NotExpression(com.facebook.presto.sql.tree.NotExpression) LogicalBinaryExpression(com.facebook.presto.sql.tree.LogicalBinaryExpression) InListExpression(com.facebook.presto.sql.tree.InListExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) ArrayList(java.util.ArrayList) IsNullPredicate(com.facebook.presto.sql.tree.IsNullPredicate) NotExpression(com.facebook.presto.sql.tree.NotExpression)

Example 2 with FALSE_LITERAL

use of com.facebook.presto.sql.tree.BooleanLiteral.FALSE_LITERAL in project presto by prestodb.

the class DomainTranslator method toPredicate.

private static Expression toPredicate(Domain domain, SymbolReference reference) {
    if (domain.getValues().isNone()) {
        return domain.isNullAllowed() ? new IsNullPredicate(reference) : FALSE_LITERAL;
    }
    if (domain.getValues().isAll()) {
        return domain.isNullAllowed() ? TRUE_LITERAL : new NotExpression(new IsNullPredicate(reference));
    }
    List<Expression> disjuncts = new ArrayList<>();
    disjuncts.addAll(domain.getValues().getValuesProcessor().transform(ranges -> extractDisjuncts(domain.getType(), ranges, reference), discreteValues -> extractDisjuncts(domain.getType(), discreteValues, reference), allOrNone -> {
        throw new IllegalStateException("Case should not be reachable");
    }));
    // Add nullability disjuncts
    if (domain.isNullAllowed()) {
        disjuncts.add(new IsNullPredicate(reference));
    }
    return combineDisjunctsWithDefault(disjuncts, TRUE_LITERAL);
}
Also used : ComparisonExpressionType(com.facebook.presto.sql.tree.ComparisonExpressionType) Block(com.facebook.presto.spi.block.Block) GREATER_THAN(com.facebook.presto.sql.tree.ComparisonExpressionType.GREATER_THAN) GREATER_THAN_OR_EQUAL(com.facebook.presto.sql.tree.ComparisonExpressionType.GREATER_THAN_OR_EQUAL) IsNullPredicate(com.facebook.presto.sql.tree.IsNullPredicate) PeekingIterator(com.google.common.collect.PeekingIterator) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Map(java.util.Map) NullableValue(com.facebook.presto.spi.predicate.NullableValue) BetweenPredicate(com.facebook.presto.sql.tree.BetweenPredicate) NotExpression(com.facebook.presto.sql.tree.NotExpression) EQUAL(com.facebook.presto.sql.tree.ComparisonExpressionType.EQUAL) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.emptyList(java.util.Collections.emptyList) SortedRangeSet(com.facebook.presto.spi.predicate.SortedRangeSet) Marker(com.facebook.presto.spi.predicate.Marker) SqlParser(com.facebook.presto.sql.parser.SqlParser) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TRUE_LITERAL(com.facebook.presto.sql.tree.BooleanLiteral.TRUE_LITERAL) LESS_THAN(com.facebook.presto.sql.tree.ComparisonExpressionType.LESS_THAN) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) BooleanLiteral(com.facebook.presto.sql.tree.BooleanLiteral) NullLiteral(com.facebook.presto.sql.tree.NullLiteral) ExpressionUtils.combineDisjunctsWithDefault(com.facebook.presto.sql.ExpressionUtils.combineDisjunctsWithDefault) Domain(com.facebook.presto.spi.predicate.Domain) LogicalBinaryExpression(com.facebook.presto.sql.tree.LogicalBinaryExpression) List(java.util.List) Utils(com.facebook.presto.spi.predicate.Utils) InPredicate(com.facebook.presto.sql.tree.InPredicate) Optional(java.util.Optional) Ranges(com.facebook.presto.spi.predicate.Ranges) ExpressionUtils.combineConjuncts(com.facebook.presto.sql.ExpressionUtils.combineConjuncts) ExpressionUtils.and(com.facebook.presto.sql.ExpressionUtils.and) ArrayList(java.util.ArrayList) InListExpression(com.facebook.presto.sql.tree.InListExpression) ImmutableList(com.google.common.collect.ImmutableList) ValueSet(com.facebook.presto.spi.predicate.ValueSet) Type(com.facebook.presto.spi.type.Type) Objects.requireNonNull(java.util.Objects.requireNonNull) Cast(com.facebook.presto.sql.tree.Cast) Iterators.peekingIterator(com.google.common.collect.Iterators.peekingIterator) Nullable(javax.annotation.Nullable) ExpressionUtils.or(com.facebook.presto.sql.ExpressionUtils.or) FALSE_LITERAL(com.facebook.presto.sql.tree.BooleanLiteral.FALSE_LITERAL) Session(com.facebook.presto.Session) Signature(com.facebook.presto.metadata.Signature) AstVisitor(com.facebook.presto.sql.tree.AstVisitor) Signature.internalOperator(com.facebook.presto.metadata.Signature.internalOperator) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) IsNotNullPredicate(com.facebook.presto.sql.tree.IsNotNullPredicate) SATURATED_FLOOR_CAST(com.facebook.presto.spi.function.OperatorType.SATURATED_FLOOR_CAST) DiscreteValues(com.facebook.presto.spi.predicate.DiscreteValues) Range(com.facebook.presto.spi.predicate.Range) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) LiteralInterpreter.toExpression(com.facebook.presto.sql.planner.LiteralInterpreter.toExpression) LESS_THAN_OR_EQUAL(com.facebook.presto.sql.tree.ComparisonExpressionType.LESS_THAN_OR_EQUAL) NOT_EQUAL(com.facebook.presto.sql.tree.ComparisonExpressionType.NOT_EQUAL) Collectors.toList(java.util.stream.Collectors.toList) ExpressionAnalyzer(com.facebook.presto.sql.analyzer.ExpressionAnalyzer) Expression(com.facebook.presto.sql.tree.Expression) FunctionInvoker(com.facebook.presto.sql.FunctionInvoker) IdentityLinkedHashMap(com.facebook.presto.util.maps.IdentityLinkedHashMap) Metadata(com.facebook.presto.metadata.Metadata) NotExpression(com.facebook.presto.sql.tree.NotExpression) LogicalBinaryExpression(com.facebook.presto.sql.tree.LogicalBinaryExpression) InListExpression(com.facebook.presto.sql.tree.InListExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) LiteralInterpreter.toExpression(com.facebook.presto.sql.planner.LiteralInterpreter.toExpression) Expression(com.facebook.presto.sql.tree.Expression) ArrayList(java.util.ArrayList) IsNullPredicate(com.facebook.presto.sql.tree.IsNullPredicate) NotExpression(com.facebook.presto.sql.tree.NotExpression)

Aggregations

Session (com.facebook.presto.Session)2 Metadata (com.facebook.presto.metadata.Metadata)2 ExpressionUtils.and (com.facebook.presto.sql.ExpressionUtils.and)2 ExpressionUtils.combineConjuncts (com.facebook.presto.sql.ExpressionUtils.combineConjuncts)2 ExpressionUtils.combineDisjunctsWithDefault (com.facebook.presto.sql.ExpressionUtils.combineDisjunctsWithDefault)2 ExpressionUtils.or (com.facebook.presto.sql.ExpressionUtils.or)2 ExpressionAnalyzer (com.facebook.presto.sql.analyzer.ExpressionAnalyzer)2 SqlParser (com.facebook.presto.sql.parser.SqlParser)2 AstVisitor (com.facebook.presto.sql.tree.AstVisitor)2 BetweenPredicate (com.facebook.presto.sql.tree.BetweenPredicate)2 BooleanLiteral (com.facebook.presto.sql.tree.BooleanLiteral)2 FALSE_LITERAL (com.facebook.presto.sql.tree.BooleanLiteral.FALSE_LITERAL)2 TRUE_LITERAL (com.facebook.presto.sql.tree.BooleanLiteral.TRUE_LITERAL)2 Cast (com.facebook.presto.sql.tree.Cast)2 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)2 Utils (com.facebook.presto.common.Utils)1 Block (com.facebook.presto.common.block.Block)1 DiscreteValues (com.facebook.presto.common.predicate.DiscreteValues)1 Domain (com.facebook.presto.common.predicate.Domain)1 Marker (com.facebook.presto.common.predicate.Marker)1