Package com.facebook.presto.sql.tree

Examples of com.facebook.presto.sql.tree.ComparisonExpression


                    // HACK! we don't support cross joins right now, so put in a simple fake join predicate instead if all of the join clauses got simplified out
                    // TODO: remove this code when cross join support is added
                    Iterable<Expression> simplifiedJoinConjuncts = transform(extractConjuncts(newJoinPredicate), simplifyExpressions());
                    simplifiedJoinConjuncts = filter(simplifiedJoinConjuncts, not(Predicates.<Expression>equalTo(BooleanLiteral.TRUE_LITERAL)));
                    if (Iterables.isEmpty(simplifiedJoinConjuncts)) {
                        simplifiedJoinConjuncts = ImmutableList.<Expression>of(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new LongLiteral("0"), new LongLiteral("0")));
                    }

                    // Create new projections for the new join clauses
                    ImmutableList.Builder<JoinNode.EquiJoinClause> builder = ImmutableList.builder();
                    for (Expression conjunct : simplifiedJoinConjuncts) {
                        checkState(joinEqualityExpression(node.getLeft().getOutputSymbols()).apply(conjunct), "Expected join predicate to be a valid join equality");

                        ComparisonExpression equality = (ComparisonExpression) conjunct;

                        boolean alignedComparison = Iterables.all(DependencyExtractor.extractUnique(equality.getLeft()), in(node.getLeft().getOutputSymbols()));
                        Expression leftExpression = (alignedComparison) ? equality.getLeft() : equality.getRight();
                        Expression rightExpression = (alignedComparison) ? equality.getRight() : equality.getLeft();

                        Symbol leftSymbol = symbolAllocator.newSymbol(leftExpression, extractType(leftExpression));
                        leftProjections.put(leftSymbol, leftExpression);
                        Symbol rightSymbol = symbolAllocator.newSymbol(rightExpression, extractType(rightExpression));
                        rightProjections.put(rightSymbol, rightExpression);
View Full Code Here


            return combineConjuncts(builder.build());
        }

        private static Expression equalsExpression(Symbol symbol1, Symbol symbol2)
        {
            return new ComparisonExpression(ComparisonExpression.Type.EQUAL,
                    new QualifiedNameReference(symbol1.toQualifiedName()),
                    new QualifiedNameReference(symbol2.toQualifiedName()));
        }
View Full Code Here

                @Override
                public boolean apply(Expression expression)
                {
                    // At this point in time, our join predicates need to be deterministic
                    if (isDeterministic(expression) && expression instanceof ComparisonExpression) {
                        ComparisonExpression comparison = (ComparisonExpression) expression;
                        if (comparison.getType() == ComparisonExpression.Type.EQUAL) {
                            Set<Symbol> symbols1 = DependencyExtractor.extractUnique(comparison.getLeft());
                            Set<Symbol> symbols2 = DependencyExtractor.extractUnique(comparison.getRight());
                            return (Iterables.all(symbols1, in(leftSymbols)) && Iterables.all(symbols2, not(in(leftSymbols)))) ||
                                    (Iterables.all(symbols2, in(leftSymbols)) && Iterables.all(symbols1, not(in(leftSymbols))));
                        }
                    }
                    return false;
View Full Code Here

                    @Override
                    public Expression apply(Map.Entry<Symbol, Expression> entry)
                    {
                        QualifiedNameReference reference = new QualifiedNameReference(entry.getKey().toQualifiedName());
                        Expression expression = entry.getValue();
                        return new ComparisonExpression(ComparisonExpression.Type.EQUAL, reference, expression);
                    }
                });

        return pullExpressionThroughSymbols(combineConjuncts(
                ImmutableList.<Expression>builder()
View Full Code Here

        Expression leftPredicate = node.getLeft().accept(this, context);
        Expression rightPredicate = node.getRight().accept(this, context);

        List<Expression> joinConjuncts = new ArrayList<>();
        for (JoinNode.EquiJoinClause clause : node.getCriteria()) {
            joinConjuncts.add(new ComparisonExpression(ComparisonExpression.Type.EQUAL,
                    new QualifiedNameReference(clause.getLeft().toQualifiedName()),
                    new QualifiedNameReference(clause.getRight().toQualifiedName())));
        }

        switch (node.getType()) {
View Full Code Here

        @Override
        public Void visitJoin(JoinNode node, Integer indent)
        {
            List<Expression> joinExpressions = new ArrayList<>();
            for (JoinNode.EquiJoinClause clause : node.getCriteria()) {
                joinExpressions.add(new ComparisonExpression(ComparisonExpression.Type.EQUAL,
                        new QualifiedNameReference(clause.getLeft().toQualifiedName()),
                        new QualifiedNameReference(clause.getRight().toQualifiedName())));
            }

            print(indent, "- %s[%s] => [%s]", node.getType().getJoinLabel(), Joiner.on(" AND ").join(joinExpressions), formatOutputs(node.getOutputSymbols()));
View Full Code Here

                }
                else if (left instanceof Slice && right instanceof Slice) {
                    return !left.equals(right);
                }

                return new ComparisonExpression(node.getType(), toExpression(left), toExpression(right));
            }

            Object left = process(node.getLeft(), context);
            if (left == null) {
                return null;
            }
            Object right = process(node.getRight(), context);
            if (right == null) {
                return null;
            }

            if (left instanceof Long && right instanceof Long) {
                switch (node.getType()) {
                    case EQUAL:
                        return ((Number) left).longValue() == ((Number) right).longValue();
                    case NOT_EQUAL:
                        return ((Number) left).longValue() != ((Number) right).longValue();
                    case LESS_THAN:
                        return ((Number) left).longValue() < ((Number) right).longValue();
                    case LESS_THAN_OR_EQUAL:
                        return ((Number) left).longValue() <= ((Number) right).longValue();
                    case GREATER_THAN:
                        return ((Number) left).longValue() > ((Number) right).longValue();
                    case GREATER_THAN_OR_EQUAL:
                        return ((Number) left).longValue() >= ((Number) right).longValue();
                }
                throw new UnsupportedOperationException("unhandled type: " + node.getType());
            }

            if (left instanceof Number && right instanceof Number) {
                switch (node.getType()) {
                    case EQUAL:
                        return ((Number) left).doubleValue() == ((Number) right).doubleValue();
                    case NOT_EQUAL:
                        return ((Number) left).doubleValue() != ((Number) right).doubleValue();
                    case LESS_THAN:
                        return ((Number) left).doubleValue() < ((Number) right).doubleValue();
                    case LESS_THAN_OR_EQUAL:
                        return ((Number) left).doubleValue() <= ((Number) right).doubleValue();
                    case GREATER_THAN:
                        return ((Number) left).doubleValue() > ((Number) right).doubleValue();
                    case GREATER_THAN_OR_EQUAL:
                        return ((Number) left).doubleValue() >= ((Number) right).doubleValue();
                }
                throw new UnsupportedOperationException("unhandled type: " + node.getType());
            }

            if (left instanceof Slice && right instanceof Slice) {
                switch (node.getType()) {
                    case EQUAL:
                        return left.equals(right);
                    case NOT_EQUAL:
                        return !left.equals(right);
                    case LESS_THAN:
                        return ((Slice) left).compareTo((Slice) right) < 0;
                    case LESS_THAN_OR_EQUAL:
                        return ((Slice) left).compareTo((Slice) right) <= 0;
                    case GREATER_THAN:
                        return ((Slice) left).compareTo((Slice) right) > 0;
                    case GREATER_THAN_OR_EQUAL:
                        return ((Slice) left).compareTo((Slice) right) >= 0;
                }
                throw new UnsupportedOperationException("unhandled type: " + node.getType());
            }

            if (left instanceof Boolean && right instanceof Boolean) {
                switch (node.getType()) {
                    case EQUAL:
                        return left.equals(right);
                    case NOT_EQUAL:
                        return !left.equals(right);
                }
                throw new UnsupportedOperationException("unhandled type: " + node.getType());
            }

            return new ComparisonExpression(node.getType(), toExpression(left), toExpression(right));
        }
View Full Code Here

            // if pattern is a constant without % or _ replace with a comparison
            if (pattern instanceof Slice && escape == null) {
                String stringPattern = ((Slice) pattern).toString(Charsets.UTF_8);
                if (!stringPattern.contains("%") && !stringPattern.contains("_")) {
                    return new ComparisonExpression(ComparisonExpression.Type.EQUAL, toExpression(value), toExpression(pattern));
                }
            }

            Expression optimizedEscape = null;
            if (node.getEscape() != null) {
View Full Code Here

            for (Expression conjunct : ExpressionUtils.extractConjuncts((Expression) optimizedExpression)) {
                if (!(conjunct instanceof ComparisonExpression)) {
                    throw new SemanticException(NOT_SUPPORTED, node, "Non-equi joins not supported: %s", conjunct);
                }

                ComparisonExpression comparison = (ComparisonExpression) conjunct;
                if (comparison.getType() != ComparisonExpression.Type.EQUAL) {
                    throw new SemanticException(NOT_SUPPORTED, node, "Non-equi joins not supported: %s", conjunct);
                }

                Set<QualifiedName> firstDependencies = DependencyExtractor.extract(comparison.getLeft());
                Set<QualifiedName> secondDependencies = DependencyExtractor.extract(comparison.getRight());

                Expression leftExpression;
                Expression rightExpression;
                if (Iterables.all(firstDependencies, left.canResolvePredicate()) && Iterables.all(secondDependencies, right.canResolvePredicate())) {
                    leftExpression = comparison.getLeft();
                    rightExpression = comparison.getRight();
                }
                else if (Iterables.all(firstDependencies, right.canResolvePredicate()) && Iterables.all(secondDependencies, left.canResolvePredicate())) {
                    leftExpression = comparison.getRight();
                    rightExpression = comparison.getLeft();
                }
                else {
                    // must have a complex expression that involves both tuples on one side of the comparison expression (e.g., coalesce(left.x, right.x) = 1)
                    throw new SemanticException(NOT_SUPPORTED, node, "Non-equi joins not supported: %s", conjunct);
                }
View Full Code Here

        @Override
        public Void visitJoin(JoinNode node, Void context)
        {
            List<Expression> joinExpressions = new ArrayList<>();
            for (JoinNode.EquiJoinClause clause : node.getCriteria()) {
                joinExpressions.add(new ComparisonExpression(ComparisonExpression.Type.EQUAL,
                        new QualifiedNameReference(clause.getLeft().toQualifiedName()),
                        new QualifiedNameReference(clause.getRight().toQualifiedName())));
            }

            String criteria = Joiner.on(" AND ").join(joinExpressions);
View Full Code Here

TOP

Related Classes of com.facebook.presto.sql.tree.ComparisonExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.