Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.sql.planner;
 
 
 import java.util.Set;

Computes all symbols declared by a logical plan
 
 public final class SymbolExtractor
 {
     private SymbolExtractor() {}
 
     public static Set<Symbolextract(PlanNode node)
     {
         ImmutableSet.Builder<Symbolbuilder = ImmutableSet.builder();
 
         node.accept(new Visitor(builder), null);
 
         return builder.build();
     }
 
     private static class Visitor
             extends PlanVisitor<VoidVoid>
     {
         private final ImmutableSet.Builder<Symbolbuilder;
 
         public Visitor(ImmutableSet.Builder<Symbolbuilder)
         {
             this. = builder;
         }
 
         @Override
         public Void visitRemoteSource(RemoteSourceNode nodeVoid context)
         {
             .addAll(node.getOutputSymbols());
 
             return null;
         }
 
         @Override
         public Void visitAggregation(AggregationNode nodeVoid context)
         {
             // visit child
             node.getSource().accept(thiscontext);
 
             .addAll(node.getAggregations().keySet());
 
             return null;
         }
 
         @Override
         public Void visitMarkDistinct(MarkDistinctNode nodeVoid context)
         {
             node.getSource().accept(thiscontext);
 
             .add(node.getMarkerSymbol());
            return null;
        }
        @Override
        public Void visitWindow(WindowNode nodeVoid context)
        {
            // visit child
            node.getSource().accept(thiscontext);
            .addAll(node.getWindowFunctions().keySet());
            return null;
        }
        @Override
        public Void visitTopNRowNumber(TopNRowNumberNode nodeVoid context)
        {
            // visit child
            node.getSource().accept(thiscontext);
            .add(node.getRowNumberSymbol());
            return null;
        }
        @Override
        public Void visitRowNumber(RowNumberNode nodeVoid context)
        {
            // visit child
            node.getSource().accept(thiscontext);
            .add(node.getRowNumberSymbol());
            return null;
        }
        @Override
        public Void visitFilter(FilterNode nodeVoid context)
        {
            // visit child
            node.getSource().accept(thiscontext);
            return null;
        }
        @Override
        public Void visitProject(ProjectNode nodeVoid context)
        {
            // visit child
            node.getSource().accept(thiscontext);
            .addAll(node.getOutputSymbols());
            return null;
        }
        @Override
        public Void visitUnnest(UnnestNode nodeVoid context)
        {
            node.getSource().accept(thiscontext);
            .addAll(Iterables.concat(node.getUnnestSymbols().values()));
            node.getOrdinalitySymbol().ifPresent(::add);
            return null;
        }
        @Override
        public Void visitTopN(TopNNode nodeVoid context)
        {
            node.getSource().accept(thiscontext);
            return null;
        }
        @Override
        public Void visitSort(SortNode nodeVoid context)
        {
            node.getSource().accept(thiscontext);
            return null;
        }
        @Override
        public Void visitOutput(OutputNode nodeVoid context)
        {
            node.getSource().accept(thiscontext);
            .addAll(node.getOutputSymbols());
            return null;
        }
        @Override
        public Void visitLimit(LimitNode nodeVoid context)
        {
            node.getSource().accept(thiscontext);
            return null;
        }
        @Override
        public Void visitDistinctLimit(DistinctLimitNode nodeVoid context)
        {
            node.getSource().accept(thiscontext);
            return null;
        }
        @Override
        public Void visitSample(SampleNode nodeVoid context)
        {
            node.getSource().accept(thiscontext);
            Optional<SymbolsampleWeightSymbol = node.getSampleWeightSymbol();
            if (sampleWeightSymbol.isPresent()) {
                .add(sampleWeightSymbol.get());
            }
            return null;
        }
        @Override
        public Void visitTableScan(TableScanNode nodeVoid context)
        {
            .addAll(node.getAssignments().keySet());
            return null;
        }
        @Override
        public Void visitValues(ValuesNode nodeVoid context)
        {
            .addAll(node.getOutputSymbols());
            return null;
        }
        @Override
        public Void visitTableWriter(TableWriterNode nodeVoid context)
        {
            node.getSource().accept(thiscontext);
            .addAll(node.getOutputSymbols());
            return null;
        }
        @Override
        public Void visitTableCommit(TableCommitNode nodeVoid context)
        {
            node.getSource().accept(thiscontext);
            .addAll(node.getOutputSymbols());
            return null;
        }
        @Override
        public Void visitIndexSource(IndexSourceNode nodeVoid context)
        {
            .addAll(node.getAssignments().keySet());
            return null;
        }
        @Override
        public Void visitJoin(JoinNode nodeVoid context)
        {
            node.getLeft().accept(thiscontext);
            node.getRight().accept(thiscontext);
            return null;
        }
        @Override
        public Void visitSemiJoin(SemiJoinNode nodeVoid context)
        {
            .add(node.getSemiJoinOutput());
            node.getSource().accept(thiscontext);
            node.getFilteringSource().accept(thiscontext);
            return null;
        }
        @Override
        public Void visitIndexJoin(IndexJoinNode nodeVoid context)
        {
            node.getProbeSource().accept(thiscontext);
            node.getIndexSource().accept(thiscontext);
            return null;
        }
        @Override
        public Void visitUnion(UnionNode nodeVoid context)
        {
            for (PlanNode subPlanNode : node.getSources()) {
                subPlanNode.accept(thiscontext);
            }
            .addAll(node.getOutputSymbols());
            return null;
        }
        @Override
        public Void visitExchange(ExchangeNode nodeVoid context)
        {
            .addAll(node.getOutputSymbols());
            return null;
        }
        @Override
        protected Void visitPlan(PlanNode nodeVoid context)
        {
            throw new UnsupportedOperationException("not yet implemented: " + node.getClass().getName());
        }
    }
New to GrepCode? Check out our FAQ X