Package com.facebook.presto.sql.tree

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


            PlanNode source = planRewriter.rewrite(node.getSource(), null);
            if (source instanceof MaterializeSampleNode && Iterables.all(node.getExpressions(), DeterminismEvaluator.deterministic())) {
                Symbol sampleWeightSymbol = ((MaterializeSampleNode) source).getSampleWeightSymbol();
                Map<Symbol, Expression> outputMap = ImmutableMap.<Symbol, Expression>builder()
                        .putAll(node.getOutputMap())
                        .put(sampleWeightSymbol, new QualifiedNameReference(sampleWeightSymbol.toQualifiedName()))
                        .build();
                ProjectNode projectNode = new ProjectNode(node.getId(), ((MaterializeSampleNode) source).getSource(), outputMap);
                return new MaterializeSampleNode(source.getId(), projectNode, sampleWeightSymbol);
            }
            else {
View Full Code Here


            PlanNode source = planRewriter.rewrite(node.getSource(), null);
            if (source instanceof MaterializeSampleNode) {
                // Remove the sample weight, since distinct limit will only output distinct rows
                ImmutableMap.Builder<Symbol, Expression> projections = ImmutableMap.builder();
                for (Symbol symbol : source.getOutputSymbols()) {
                    Expression expression = new QualifiedNameReference(symbol.toQualifiedName());
                    projections.put(symbol, expression);
                }
                source = new ProjectNode(idAllocator.getNextId(), ((MaterializeSampleNode) source).getSource(), projections.build());
                return new DistinctLimitNode(node.getId(), source, node.getLimit());
            }
View Full Code Here

                        node.getOutputSymbols().size() == node.getGroupBy().size() &&
                        node.getOutputSymbols().containsAll(node.getGroupBy())) {
                    // Remove the sample weight, since distinct will only outputs distinct rows
                    ImmutableMap.Builder<Symbol, Expression> projections = ImmutableMap.builder();
                    for (Symbol symbol : source.getOutputSymbols()) {
                        Expression expression = new QualifiedNameReference(symbol.toQualifiedName());
                        projections.put(symbol, expression);
                    }
                    source = new ProjectNode(idAllocator.getNextId(), ((MaterializeSampleNode) source).getSource(), projections.build());
                    return new AggregationNode(node.getId(), source, node.getGroupBy(), node.getAggregations(), node.getFunctions(), node.getMasks(), Optional.<Symbol>absent(), node.getConfidence());
                }
View Full Code Here

                    ImmutableMap.Builder<Symbol, Expression> projections = ImmutableMap.builder();
                    Expression sampleWeightExpr;
                    switch (node.getType()) {
                        case INNER:
                        case CROSS:
                            sampleWeightExpr = new ArithmeticExpression(ArithmeticExpression.Type.MULTIPLY, new QualifiedNameReference(leftSampleWeight.toQualifiedName()), new QualifiedNameReference(rightSampleWeight.toQualifiedName()));
                            break;
                        case LEFT:
                            sampleWeightExpr = new ArithmeticExpression(ArithmeticExpression.Type.MULTIPLY, new QualifiedNameReference(leftSampleWeight.toQualifiedName()), oneIfNull(rightSampleWeight));
                            break;
                        case RIGHT:
                            sampleWeightExpr = new ArithmeticExpression(ArithmeticExpression.Type.MULTIPLY, oneIfNull(leftSampleWeight), new QualifiedNameReference(rightSampleWeight.toQualifiedName()));
                            break;
                        default:
                            throw new AssertionError(String.format("Unknown join type: %s", node.getType()));
                    }
                    outputSampleWeight = symbolAllocator.newSymbol(sampleWeightExpr, BIGINT);
                    projections.put(outputSampleWeight, sampleWeightExpr);
                    for (Symbol symbol : Iterables.filter(node.getOutputSymbols(), not(in(ImmutableSet.of(leftSampleWeight, rightSampleWeight))))) {
                        Expression expression = new QualifiedNameReference(symbol.toQualifiedName());
                        projections.put(symbol, expression);
                    }
                    joinNode = new ProjectNode(idAllocator.getNextId(), joinNode, projections.build());
                }
                else {
                    outputSampleWeight = leftSampleWeight == null ? rightSampleWeight : leftSampleWeight;
                    if ((node.getType() == JoinNode.Type.LEFT && leftSampleWeight == null) || (node.getType() == JoinNode.Type.RIGHT && rightSampleWeight == null)) {
                        // There could be NULLs in the sample weight, so fix them with a projection
                        ImmutableMap.Builder<Symbol, Expression> projections = ImmutableMap.builder();
                        for (Symbol symbol : Iterables.filter(node.getOutputSymbols(), not(equalTo(outputSampleWeight)))) {
                            Expression expression = new QualifiedNameReference(symbol.toQualifiedName());
                            projections.put(symbol, expression);
                        }
                        Expression sampleWeightExpr = oneIfNull(outputSampleWeight);
                        outputSampleWeight = symbolAllocator.newSymbol(sampleWeightExpr, BIGINT);
                        projections.put(outputSampleWeight, sampleWeightExpr);
View Full Code Here

            return new JoinNode(node.getId(), node.getType(), leftSource, rightSource, node.getCriteria());
        }

        private Expression oneIfNull(Symbol symbol)
        {
            return new CoalesceExpression(new QualifiedNameReference(symbol.toQualifiedName()), new LongLiteral("1"));
        }
View Full Code Here

        private PlanNode addSampleWeight(PlanNode source, Symbol sampleWeightSymbol)
        {
            ImmutableMap.Builder<Symbol, Expression> projections = ImmutableMap.builder();
            for (Symbol symbol : source.getOutputSymbols()) {
                Expression expression = new QualifiedNameReference(symbol.toQualifiedName());
                projections.put(symbol, expression);
            }
            Expression one = new LongLiteral("1");
            projections.put(sampleWeightSymbol, one);
            return new ProjectNode(idAllocator.getNextId(), source, projections.build());
View Full Code Here

            {
                @Override
                public Expression rewriteQualifiedNameReference(QualifiedNameReference node, Void context, ExpressionTreeRewriter<Void> treeRewriter)
                {
                    Symbol canonical = canonicalize(Symbol.fromQualifiedName(node.getName()));
                    return new QualifiedNameReference(canonical.toQualifiedName());
                }
            }, value);
        }
View Full Code Here

        }

        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

                    .optimize(new SymbolResolver()
                    {
                        @Override
                        public Object getValue(Symbol symbol)
                        {
                            return nullSymbols.contains(symbol) ? null : new QualifiedNameReference(symbol.toQualifiedName());
                        }
                    });
        }
View Full Code Here

        return new FilterNode(newId(), source, predicate);
    }

    private static Expression symbolExpr(Symbol symbol)
    {
        return new QualifiedNameReference(symbol.toQualifiedName());
    }
View Full Code Here

TOP

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

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.