Search in sources :

Example 1 with TRUE_LITERAL

use of io.prestosql.sql.tree.BooleanLiteral.TRUE_LITERAL in project hetu-core by openlookeng.

the class TransformCorrelatedLateralJoinToJoin method apply.

@Override
public Result apply(LateralJoinNode lateralJoinNode, Captures captures, Context context) {
    PlanNode subquery = lateralJoinNode.getSubquery();
    PlanNodeDecorrelator planNodeDecorrelator = new PlanNodeDecorrelator(context.getIdAllocator(), context.getLookup());
    Optional<DecorrelatedNode> decorrelatedNodeOptional = planNodeDecorrelator.decorrelateFilters(subquery, lateralJoinNode.getCorrelation());
    return decorrelatedNodeOptional.map(decorrelatedNode -> {
        Expression joinFilter = combineConjuncts(decorrelatedNode.getCorrelatedPredicates().orElse(TRUE_LITERAL), lateralJoinNode.getFilter());
        return Result.ofPlanNode(new JoinNode(context.getIdAllocator().getNextId(), lateralJoinNode.getType().toJoinNodeType(), lateralJoinNode.getInput(), decorrelatedNode.getNode(), ImmutableList.of(), lateralJoinNode.getOutputSymbols(), joinFilter.equals(TRUE_LITERAL) ? Optional.empty() : Optional.of(castToRowExpression(joinFilter)), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of()));
    }).orElseGet(Result::empty);
}
Also used : Patterns.lateralJoin(io.prestosql.sql.planner.plan.Patterns.lateralJoin) LateralJoin.correlation(io.prestosql.sql.planner.plan.Patterns.LateralJoin.correlation) ExpressionUtils.combineConjuncts(io.prestosql.sql.ExpressionUtils.combineConjuncts) ImmutableMap(com.google.common.collect.ImmutableMap) Rule(io.prestosql.sql.planner.iterative.Rule) Pattern.nonEmpty(io.prestosql.matching.Pattern.nonEmpty) PlanNodeDecorrelator(io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator) LateralJoinNode(io.prestosql.sql.planner.plan.LateralJoinNode) Pattern(io.prestosql.matching.Pattern) PlanNode(io.prestosql.spi.plan.PlanNode) TRUE_LITERAL(io.prestosql.sql.tree.BooleanLiteral.TRUE_LITERAL) Captures(io.prestosql.matching.Captures) ImmutableList(com.google.common.collect.ImmutableList) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Optional(java.util.Optional) DecorrelatedNode(io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode) Expression(io.prestosql.sql.tree.Expression) JoinNode(io.prestosql.spi.plan.JoinNode) PlanNodeDecorrelator(io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator) PlanNode(io.prestosql.spi.plan.PlanNode) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Expression(io.prestosql.sql.tree.Expression) LateralJoinNode(io.prestosql.sql.planner.plan.LateralJoinNode) JoinNode(io.prestosql.spi.plan.JoinNode) DecorrelatedNode(io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator.DecorrelatedNode)

Example 2 with TRUE_LITERAL

use of io.prestosql.sql.tree.BooleanLiteral.TRUE_LITERAL in project hetu-core by openlookeng.

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 : GREATER_THAN_OR_EQUAL(io.prestosql.sql.tree.ComparisonExpression.Operator.GREATER_THAN_OR_EQUAL) LESS_THAN_OR_EQUAL(io.prestosql.sql.tree.ComparisonExpression.Operator.LESS_THAN_OR_EQUAL) DiscreteValues(io.prestosql.spi.predicate.DiscreteValues) OperatorNotFoundException(io.prestosql.metadata.OperatorNotFoundException) FALSE_LITERAL(io.prestosql.sql.tree.BooleanLiteral.FALSE_LITERAL) ValueSet(io.prestosql.spi.predicate.ValueSet) NullableValue(io.prestosql.spi.predicate.NullableValue) SqlParser(io.prestosql.sql.parser.SqlParser) PeekingIterator(com.google.common.collect.PeekingIterator) Cast(io.prestosql.sql.tree.Cast) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Slices(io.airlift.slice.Slices) Map(java.util.Map) EQUAL(io.prestosql.sql.tree.ComparisonExpression.Operator.EQUAL) Type(io.prestosql.spi.type.Type) TypeCoercion(io.prestosql.type.TypeCoercion) SliceUtf8.getCodePointAt(io.airlift.slice.SliceUtf8.getCodePointAt) IsNullPredicate(io.prestosql.sql.tree.IsNullPredicate) ExpressionUtils.or(io.prestosql.sql.ExpressionUtils.or) ImmutableMap(com.google.common.collect.ImmutableMap) CastType(io.prestosql.metadata.CastType) IsNotNullPredicate(io.prestosql.sql.tree.IsNotNullPredicate) LikeFunctions(io.prestosql.type.LikeFunctions) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) NullLiteral(io.prestosql.sql.tree.NullLiteral) SortedRangeSet(io.prestosql.spi.predicate.SortedRangeSet) Metadata(io.prestosql.metadata.Metadata) NodeRef(io.prestosql.sql.tree.NodeRef) Preconditions.checkState(com.google.common.base.Preconditions.checkState) FunctionHandle(io.prestosql.spi.function.FunctionHandle) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) List(java.util.List) ExpressionUtils(io.prestosql.sql.ExpressionUtils) SymbolReference(io.prestosql.sql.tree.SymbolReference) StringLiteral(io.prestosql.sql.tree.StringLiteral) Domain(io.prestosql.spi.predicate.Domain) Optional(java.util.Optional) BetweenPredicate(io.prestosql.sql.tree.BetweenPredicate) SymbolUtils.from(io.prestosql.sql.planner.SymbolUtils.from) Utils(io.prestosql.spi.predicate.Utils) InPredicate(io.prestosql.sql.tree.InPredicate) LESS_THAN(io.prestosql.sql.tree.ComparisonExpression.Operator.LESS_THAN) Slice(io.airlift.slice.Slice) InListExpression(io.prestosql.sql.tree.InListExpression) Marker(io.prestosql.spi.predicate.Marker) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) TRUE_LITERAL(io.prestosql.sql.tree.BooleanLiteral.TRUE_LITERAL) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) InterpretedFunctionInvoker(io.prestosql.sql.InterpretedFunctionInvoker) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Range(io.prestosql.spi.predicate.Range) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) LikePredicate(io.prestosql.sql.tree.LikePredicate) CAST(io.prestosql.metadata.CastType.CAST) Comparator.comparing(java.util.Comparator.comparing) AstVisitor(io.prestosql.sql.tree.AstVisitor) Iterators.peekingIterator(com.google.common.collect.Iterators.peekingIterator) Block(io.prestosql.spi.block.Block) Nullable(javax.annotation.Nullable) GREATER_THAN(io.prestosql.sql.tree.ComparisonExpression.Operator.GREATER_THAN) Symbol(io.prestosql.spi.plan.Symbol) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) SliceUtf8.lengthOfCodePoint(io.airlift.slice.SliceUtf8.lengthOfCodePoint) ExpressionUtils.combineConjuncts(io.prestosql.sql.ExpressionUtils.combineConjuncts) Ranges(io.prestosql.spi.predicate.Ranges) TupleDomain(io.prestosql.spi.predicate.TupleDomain) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) ExpressionUtils.and(io.prestosql.sql.ExpressionUtils.and) SliceUtf8.setCodePointAt(io.airlift.slice.SliceUtf8.setCodePointAt) ExpressionUtils.combineDisjunctsWithDefault(io.prestosql.sql.ExpressionUtils.combineDisjunctsWithDefault) Collectors.toList(java.util.stream.Collectors.toList) NOT_EQUAL(io.prestosql.sql.tree.ComparisonExpression.Operator.NOT_EQUAL) SliceUtf8.countCodePoints(io.airlift.slice.SliceUtf8.countCodePoints) VarcharType(io.prestosql.spi.type.VarcharType) Expression(io.prestosql.sql.tree.Expression) InListExpression(io.prestosql.sql.tree.InListExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) ArrayList(java.util.ArrayList) IsNullPredicate(io.prestosql.sql.tree.IsNullPredicate) NotExpression(io.prestosql.sql.tree.NotExpression)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ExpressionUtils.combineConjuncts (io.prestosql.sql.ExpressionUtils.combineConjuncts)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 Iterators.peekingIterator (com.google.common.collect.Iterators.peekingIterator)1 PeekingIterator (com.google.common.collect.PeekingIterator)1 Slice (io.airlift.slice.Slice)1 SliceUtf8.countCodePoints (io.airlift.slice.SliceUtf8.countCodePoints)1 SliceUtf8.getCodePointAt (io.airlift.slice.SliceUtf8.getCodePointAt)1 SliceUtf8.lengthOfCodePoint (io.airlift.slice.SliceUtf8.lengthOfCodePoint)1 SliceUtf8.setCodePointAt (io.airlift.slice.SliceUtf8.setCodePointAt)1 Slices (io.airlift.slice.Slices)1 Session (io.prestosql.Session)1 Captures (io.prestosql.matching.Captures)1 Pattern (io.prestosql.matching.Pattern)1 Pattern.nonEmpty (io.prestosql.matching.Pattern.nonEmpty)1 CastType (io.prestosql.metadata.CastType)1