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.Map;
 import java.util.Set;
 
 import static com.facebook.presto.operator.DistinctLimitOperator.DistinctLimitOperatorFactory;
 import static com.facebook.presto.operator.TableCommitOperator.TableCommitOperatorFactory;
 import static com.facebook.presto.operator.TableCommitOperator.TableCommitter;
 import static com.facebook.presto.operator.TableWriterOperator.TableWriterOperatorFactory;
 import static com.facebook.presto.operator.UnnestOperator.UnnestOperatorFactory;
 import static com.facebook.presto.spi.StandardErrorCode.COMPILER_ERROR;
 import static com.facebook.presto.sql.analyzer.ExpressionAnalyzer.getExpressionTypes;
 import static com.facebook.presto.sql.analyzer.ExpressionAnalyzer.getExpressionTypesFromInput;
 import static com.facebook.presto.sql.planner.plan.TableWriterNode.CreateHandle;
 import static com.facebook.presto.sql.planner.plan.TableWriterNode.InsertHandle;
 import static com.facebook.presto.sql.planner.plan.TableWriterNode.WriterTarget;
 import static com.facebook.presto.util.ImmutableCollectors.toImmutableList;
 import static com.google.common.base.Functions.forMap;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.base.Predicates.in;
 import static com.google.common.base.Predicates.not;
 import static com.google.common.collect.Iterables.concat;
 import static java.util.Collections.singleton;
 
 public class LocalExecutionPlanner
 {
     private static final Logger log = Logger.get(LocalExecutionPlanner.class);
 
     private final Metadata metadata;
     private final SqlParser sqlParser;
 
     private final PageSourceProvider pageSourceProvider;
     private final IndexManager indexManager;
     private final PageSinkManager pageSinkManager;
     private final ExpressionCompiler compiler;
     private final boolean interpreterEnabled;
     private final DataSize maxIndexMemorySize;
     private final IndexJoinLookupStats indexJoinLookupStats;
     private final DataSize maxPartialAggregationMemorySize;
     private final int writerCount;
 
     @Inject
     public LocalExecutionPlanner(
             Metadata metadata,
             SqlParser sqlParser,
             PageSourceProvider pageSourceProvider,
             IndexManager indexManager,
             PageSinkManager pageSinkManager,
             Supplier<ExchangeClientexchangeClientSupplier,
             ExpressionCompiler compiler,
             IndexJoinLookupStats indexJoinLookupStats,
             CompilerConfig compilerConfig,
             TaskManagerConfig taskManagerConfig)
     {
         checkNotNull(compilerConfig"compilerConfig is null");
         this. = checkNotNull(pageSourceProvider"pageSourceProvider is null");
         this. = checkNotNull(indexManager"indexManager is null");
         this. = exchangeClientSupplier;
         this. = checkNotNull(metadata"metadata is null");
         this. = checkNotNull(sqlParser"sqlParser is null");
         this. = checkNotNull(pageSinkManager"pageSinkManager is null");
         this. = checkNotNull(compiler"compiler is null");
         this. = checkNotNull(indexJoinLookupStats"indexJoinLookupStats is null");
         this. = checkNotNull(taskManagerConfig"taskManagerConfig is null").getMaxTaskIndexMemoryUsage();
         this. = taskManagerConfig.getMaxPartialAggregationMemoryUsage();
         this. = taskManagerConfig.getWriterCount();
 
          = compilerConfig.isInterpreterEnabled();
     }
 
     public LocalExecutionPlan plan(Session session,
             PlanNode plan,
             List<SymboloutputLayout,
             Map<SymbolTypetypes,
             OutputFactory outputOperatorFactory)
     {
         LocalExecutionPlanContext context = new LocalExecutionPlanContext(sessiontypes);
 
         PhysicalOperation physicalOperation = enforceLayout(outputLayoutcontextplan.accept(new Visitor(session), context));
 
         DriverFactory driverFactory = new DriverFactory(
                 context.isInputDriver(),
                 true,
                 ImmutableList.<OperatorFactory>builder()
                         .addAll(physicalOperation.getOperatorFactories())
                         .add(outputOperatorFactory.createOutputOperator(context.getNextOperatorId(), physicalOperation.getTypes()))
                         .build(),
                 context.getDriverInstanceCount());
         context.addDriverFactory(driverFactory);
 
         return new LocalExecutionPlan(context.getDriverFactories());
     }
 
     private PhysicalOperation enforceLayout(List<SymboloutputLayoutLocalExecutionPlanContext contextPhysicalOperation physicalOperation)
     {
         // are the symbols of the source in the same order as the sink expects?
         boolean projectionMatchesOutput = physicalOperation.getLayout()
                 .entrySet().stream()
                 .sorted(Ordering.<Integer>natural().onResultOf(Map.Entry::getValue))
                 .map(Map.Entry::getKey)
                 .collect(toImmutableList())
                 .equals(outputLayout);
 
         if (!projectionMatchesOutput) {
             IdentityProjectionInfo mappings = computeIdentityMapping(outputLayoutphysicalOperation.getLayout(), context.getTypes());
             OperatorFactory operatorFactory = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(
                     context.getNextOperatorId(),
                     new GenericPageProcessor(.mappings.getProjections()),
                     toTypes(mappings.getProjections()));
             // NOTE: the generated output layout may not be completely accurate if the same field was projected as multiple inputs.
             // However, this should not affect the operation of the sink.
             physicalOperation = new PhysicalOperation(operatorFactorymappings.getOutputLayout(), physicalOperation);
         }
 
         return physicalOperation;
     }
 
     private static class LocalExecutionPlanContext
     {
         private final Session session;
         private final Map<SymbolTypetypes;
         private final List<DriverFactorydriverFactories;
         private final Optional<IndexSourceContextindexSourceContext;
 
         private int nextOperatorId;
         private boolean inputDriver = true;
         private int driverInstanceCount = 1;
 
         public LocalExecutionPlanContext(Session sessionMap<SymbolTypetypes)
         {
             this(sessiontypesnew ArrayList<>(), Optional.empty());
         }
 
         private LocalExecutionPlanContext(Session sessionMap<SymbolTypetypesList<DriverFactorydriverFactoriesOptional<IndexSourceContextindexSourceContext)
         {
             this. = session;
             this. = types;
             this. = driverFactories;
             this. = indexSourceContext;
         }
 
         public void addDriverFactory(DriverFactory driverFactory)
         {
             .add(checkNotNull(driverFactory"driverFactory is null"));
         }
 
         private List<DriverFactorygetDriverFactories()
         {
             return ImmutableList.copyOf();
         }
 
         public Session getSession()
         {
             return ;
         }
 
         public Map<SymbolTypegetTypes()
         {
             return ;
         }
 
         {
             return ;
         }
 
         private int getNextOperatorId()
         {
             return ++;
         }
 
         private boolean isInputDriver()
         {
             return ;
         }
 
         private void setInputDriver(boolean inputDriver)
         {
             this. = inputDriver;
         }
 
         public LocalExecutionPlanContext createSubContext()
         {
             checkState(!.isPresent(), "index build plan can not have sub-contexts");
             return new LocalExecutionPlanContext();
         }
 
         public LocalExecutionPlanContext createIndexSourceSubContext(IndexSourceContext indexSourceContext)
         {
             return new LocalExecutionPlanContext(, Optional.of(indexSourceContext));
         }
 
         public int getDriverInstanceCount()
         {
             return ;
         }
 
         public void setDriverInstanceCount(int driverInstanceCount)
         {
             checkArgument(driverInstanceCount > 0, "driverInstanceCount must be > 0");
             this. = driverInstanceCount;
         }
     }
 
     private static class IndexSourceContext
     {
         private final SetMultimap<SymbolIntegerindexLookupToProbeInput;
 
         public IndexSourceContext(SetMultimap<SymbolIntegerindexLookupToProbeInput)
         {
             this. = ImmutableSetMultimap.copyOf(checkNotNull(indexLookupToProbeInput"indexLookupToProbeInput is null"));
         }
 
         private SetMultimap<SymbolIntegergetIndexLookupToProbeInput()
         {
             return ;
         }
     }
 
     public static class LocalExecutionPlan
     {
         private final List<DriverFactorydriverFactories;
 
         public LocalExecutionPlan(List<DriverFactorydriverFactories)
         {
             this. = ImmutableList.copyOf(checkNotNull(driverFactories"driverFactories is null"));
         }
 
         public List<DriverFactorygetDriverFactories()
         {
             return ;
         }
     }
 
     private class Visitor
             extends PlanVisitor<LocalExecutionPlanContextPhysicalOperation>
     {
         private final Session session;
 
         private Visitor(Session session)
         {
             this. = session;
         }
 
         @Override
         {
             List<Typetypes = getSourceOperatorTypes(nodecontext.getTypes());
 
             OperatorFactory operatorFactory = new ExchangeOperatorFactory(context.getNextOperatorId(), node.getId(), types);
 
             return new PhysicalOperation(operatorFactorymakeLayout(node));
         }
 
         @Override
         public PhysicalOperation visitOutput(OutputNode nodeLocalExecutionPlanContext context)
         {
             return node.getSource().accept(thiscontext);
         }
 
         @Override
         public PhysicalOperation visitRowNumber(RowNumberNode nodeLocalExecutionPlanContext context)
         {
             final PhysicalOperation source = node.getSource().accept(thiscontext);
 
             List<SymbolpartitionBySymbols = node.getPartitionBy();
             List<IntegerpartitionChannels = getChannelsForSymbols(partitionBySymbolssource.getLayout());
 
             List<TypepartitionTypes = partitionChannels.stream()
                     .map(channel -> source.getTypes().get(channel))
                     .collect(toImmutableList());
 
             ImmutableList.Builder<IntegeroutputChannels = ImmutableList.builder();
             for (int i = 0; i < source.getTypes().size(); i++) {
                 outputChannels.add(i);
             }
 
             // compute the layout of the output from the window operator
             ImmutableMap.Builder<SymbolIntegeroutputMappings = ImmutableMap.builder();
             outputMappings.putAll(source.getLayout());
 
             // row number function goes in the last channel
             int channel = source.getTypes().size();
             outputMappings.put(node.getRowNumberSymbol(), channel);
 
             Optional<IntegerhashChannel = node.getHashSymbol().map(channelGetter(source));
             OperatorFactory operatorFactory = new RowNumberOperator.RowNumberOperatorFactory(
                     context.getNextOperatorId(),
                     source.getTypes(),
                     outputChannels.build(),
                     partitionChannels,
                     partitionTypes,
                     node.getMaxRowCountPerPartition(),
                     hashChannel,
                     1_000_000);
             return new PhysicalOperation(operatorFactoryoutputMappings.build(), source);
         }
 
         @Override
         public PhysicalOperation visitTopNRowNumber(final TopNRowNumberNode nodeLocalExecutionPlanContext context)
         {
             final PhysicalOperation source = node.getSource().accept(thiscontext);
 
             List<SymbolpartitionBySymbols = node.getPartitionBy();
             List<IntegerpartitionChannels = getChannelsForSymbols(partitionBySymbolssource.getLayout());
             List<TypepartitionTypes = partitionChannels.stream()
                     .map(channel -> source.getTypes().get(channel))
                     .collect(toImmutableList());
 
             List<SymbolorderBySymbols = node.getOrderBy();
             List<IntegersortChannels = getChannelsForSymbols(orderBySymbolssource.getLayout());
             List<SortOrdersortOrder = orderBySymbols.stream()
                     .map(symbol -> node.getOrderings().get(symbol))
                     .collect(toImmutableList());
 
             ImmutableList.Builder<IntegeroutputChannels = ImmutableList.builder();
             for (int i = 0; i < source.getTypes().size(); i++) {
                 outputChannels.add(i);
             }
 
             // compute the layout of the output from the window operator
             ImmutableMap.Builder<SymbolIntegeroutputMappings = ImmutableMap.builder();
             outputMappings.putAll(source.getLayout());
 
             if (!node.isPartial() || !partitionChannels.isEmpty()) {
                 // row number function goes in the last channel
                 int channel = source.getTypes().size();
                 outputMappings.put(node.getRowNumberSymbol(), channel);
             }
 
             Optional<IntegerhashChannel = node.getHashSymbol().map(channelGetter(source));
             OperatorFactory operatorFactory = new TopNRowNumberOperator.TopNRowNumberOperatorFactory(
                     context.getNextOperatorId(),
                     source.getTypes(),
                     outputChannels.build(),
                     partitionChannels,
                     partitionTypes,
                     sortChannels,
                     sortOrder,
                     node.getMaxRowCountPerPartition(),
                     node.isPartial(),
                     hashChannel,
                     1_000_000);
 
             return new PhysicalOperation(operatorFactorymakeLayout(node), source);
         }
 
         @Override
         public PhysicalOperation visitWindow(final WindowNode nodeLocalExecutionPlanContext context)
         {
             final PhysicalOperation source = node.getSource().accept(thiscontext);
 
             List<SymbolpartitionBySymbols = node.getPartitionBy();
             List<SymbolorderBySymbols = node.getOrderBy();
             List<IntegerpartitionChannels = ImmutableList.copyOf(getChannelsForSymbols(partitionBySymbolssource.getLayout()));
 
             List<IntegersortChannels = getChannelsForSymbols(orderBySymbolssource.getLayout());
             List<SortOrdersortOrder = orderBySymbols.stream()
                     .map(symbol -> node.getOrderings().get(symbol))
                     .collect(toImmutableList());
 
             Optional<IntegerframeStartChannel = Optional.empty();
             Optional<IntegerframeEndChannel = Optional.empty();
             if (node.getFrame().getStartValue().isPresent()) {
                 frameStartChannel = Optional.of(source.getLayout().get(node.getFrame().getStartValue().get()));
             }
             if (node.getFrame().getEndValue().isPresent()) {
                 frameEndChannel = Optional.of(source.getLayout().get(node.getFrame().getEndValue().get()));
             }
 
             ImmutableList.Builder<IntegeroutputChannels = ImmutableList.builder();
             for (int i = 0; i < source.getTypes().size(); i++) {
                 outputChannels.add(i);
             }
 
             ImmutableList.Builder<WindowFunctionDefinitionwindowFunctionsBuilder = ImmutableList.builder();
             ImmutableList.Builder<SymbolwindowFunctionOutputSymbolsBuilder = ImmutableList.builder();
             for (Map.Entry<SymbolFunctionCallentry : node.getWindowFunctions().entrySet()) {
                 ImmutableList.Builder<Integerarguments = ImmutableList.builder();
                 for (Expression argument : entry.getValue().getArguments()) {
                     Symbol argumentSymbol = Symbol.fromQualifiedName(((QualifiedNameReferenceargument).getName());
                     arguments.add(source.getLayout().get(argumentSymbol));
                 }
                 Symbol symbol = entry.getKey();
                 Signature signature = node.getSignatures().get(symbol);
                 windowFunctionsBuilder.add(.getExactFunction(signature).bindWindowFunction(arguments.build()));
                 windowFunctionOutputSymbolsBuilder.add(symbol);
             }
 
             List<SymbolwindowFunctionOutputSymbols = windowFunctionOutputSymbolsBuilder.build();
             List<WindowFunctionDefinitionwindowFunctions = windowFunctionsBuilder.build();
 
             // compute the layout of the output from the window operator
             ImmutableMap.Builder<SymbolIntegeroutputMappings = ImmutableMap.builder();
             for (Symbol symbol : node.getSource().getOutputSymbols()) {
                 outputMappings.put(symbolsource.getLayout().get(symbol));
             }
 
             // window functions go in remaining channels starting after the last channel from the source operator, one per channel
             int channel = source.getTypes().size();
             for (Symbol symbol : windowFunctionOutputSymbols) {
                 outputMappings.put(symbolchannel);
                 channel++;
             }
 
             OperatorFactory operatorFactory = new WindowOperatorFactory(
                     context.getNextOperatorId(),
                     source.getTypes(),
                     outputChannels.build(),
                     windowFunctions,
                     partitionChannels,
                     sortChannels,
                     sortOrder,
                     node.getFrame().getType(),
                     node.getFrame().getStartType(), frameStartChannel,
                     node.getFrame().getEndType(), frameEndChannel,
                     1_000_000);
 
             return new PhysicalOperation(operatorFactoryoutputMappings.build(), source);
         }
 
         @Override
         public PhysicalOperation visitTopN(TopNNode nodeLocalExecutionPlanContext context)
         {
             PhysicalOperation source = node.getSource().accept(thiscontext);
 
             List<SymbolorderBySymbols = node.getOrderBy();
 
             List<IntegersortChannels = new ArrayList<>();
             List<SortOrdersortOrders = new ArrayList<>();
             for (Symbol symbol : orderBySymbols) {
                 sortChannels.add(source.getLayout().get(symbol));
                 sortOrders.add(node.getOrderings().get(symbol));
             }
 
             OperatorFactory operator = new TopNOperatorFactory(
                     context.getNextOperatorId(),
                     source.getTypes(),
                     (intnode.getCount(),
                     sortChannels,
                     sortOrders,
                     node.isPartial());
 
             return new PhysicalOperation(operatorsource.getLayout(), source);
         }
 
         @Override
         public PhysicalOperation visitSort(SortNode nodeLocalExecutionPlanContext context)
         {
             PhysicalOperation source = node.getSource().accept(thiscontext);
 
             List<SymbolorderBySymbols = node.getOrderBy();
 
             List<IntegerorderByChannels = getChannelsForSymbols(orderBySymbolssource.getLayout());
 
             ImmutableList.Builder<SortOrdersortOrder = ImmutableList.builder();
             for (Symbol symbol : orderBySymbols) {
                 sortOrder.add(node.getOrderings().get(symbol));
             }
 
             ImmutableList.Builder<IntegeroutputChannels = ImmutableList.builder();
             for (int i = 0; i < source.getTypes().size(); i++) {
                 outputChannels.add(i);
             }
 
             OperatorFactory operator = new OrderByOperatorFactory(
                     context.getNextOperatorId(),
                     source.getTypes(),
                     outputChannels.build(),
                     10_000,
                     orderByChannels,
                     sortOrder.build());
 
             return new PhysicalOperation(operatorsource.getLayout(), source);
         }
 
         @Override
         public PhysicalOperation visitLimit(LimitNode nodeLocalExecutionPlanContext context)
         {
             PhysicalOperation source = node.getSource().accept(thiscontext);
 
             OperatorFactory operatorFactory = new LimitOperatorFactory(context.getNextOperatorId(), source.getTypes(), node.getCount());
             return new PhysicalOperation(operatorFactorysource.getLayout(), source);
         }
 
         @Override
         {
             PhysicalOperation source = node.getSource().accept(thiscontext);
 
             Optional<IntegerhashChannel = node.getHashSymbol().map(channelGetter(source));
             List<IntegerdistinctChannels = getChannelsForSymbols(node.getDistinctSymbols(), source.getLayout());
 
             OperatorFactory operatorFactory = new DistinctLimitOperatorFactory(
                     context.getNextOperatorId(),
                     source.getTypes(),
                     distinctChannels,
                     node.getLimit(),
                     hashChannel);
             return new PhysicalOperation(operatorFactorysource.getLayout(), source);
         }
 
         @Override
         {
             PhysicalOperation source = node.getSource().accept(thiscontext);
 
             if (node.getGroupBy().isEmpty()) {
                 return planGlobalAggregation(context.getNextOperatorId(), nodesource);
             }
 
             return planGroupByAggregation(nodesourcecontext);
         }
 
         @Override
         {
             PhysicalOperation source = node.getSource().accept(thiscontext);
 
             List<Integerchannels = getChannelsForSymbols(node.getDistinctSymbols(), source.getLayout());
             Optional<IntegerhashChannel = node.getHashSymbol().map(channelGetter(source));
             MarkDistinctOperatorFactory operator = new MarkDistinctOperatorFactory(context.getNextOperatorId(), source.getTypes(), channelshashChannel);
             return new PhysicalOperation(operatormakeLayout(node), source);
         }
 
         @Override
         public PhysicalOperation visitSample(SampleNode nodeLocalExecutionPlanContext context)
         {
             // For system sample, the splits are already filtered out, so no specific action needs to be taken here
             if (node.getSampleType() == ..) {
                 return node.getSource().accept(thiscontext);
             }
 
             if (node.getSampleType() == ..) {
                 PhysicalOperation source = node.getSource().accept(thiscontext);
                 OperatorFactory operatorFactory = new SampleOperatorFactory(context.getNextOperatorId(), node.getSampleRatio(), node.isRescaled(), source.getTypes());
                 checkState(node.getSampleWeightSymbol().isPresent(), "sample weight symbol missing");
                 return new PhysicalOperation(operatorFactorymakeLayout(node), source);
             }
 
             throw new UnsupportedOperationException("not yet implemented: " + node);
         }
 
         @Override
         public PhysicalOperation visitFilter(FilterNode nodeLocalExecutionPlanContext context)
         {
             PlanNode sourceNode = node.getSource();
 
             Expression filterExpression = node.getPredicate();
 
             List<ExpressionprojectionExpressions = new ArrayList<>();
             for (int i = 0; i < node.getOutputSymbols().size(); i++) {
                 Symbol symbol = node.getOutputSymbols().get(i);
                 projectionExpressions.add(new QualifiedNameReference(symbol.toQualifiedName()));
             }
 
             List<SymboloutputSymbols = node.getOutputSymbols();
 
             return visitScanFilterAndProject(contextsourceNodefilterExpressionprojectionExpressionsoutputSymbols);
         }
 
         @Override
         public PhysicalOperation visitProject(ProjectNode nodeLocalExecutionPlanContext context)
         {
             PlanNode sourceNode;
             Expression filterExpression;
             if (node.getSource() instanceof FilterNode) {
                 FilterNode filterNode = (FilterNodenode.getSource();
                 sourceNode = filterNode.getSource();
                 filterExpression = filterNode.getPredicate();
             }
             else {
                 sourceNode = node.getSource();
                 filterExpression = .;
             }
 
             List<ExpressionprojectionExpressions = node.getExpressions();
 
             List<SymboloutputSymbols = node.getOutputSymbols();
 
             return visitScanFilterAndProject(contextsourceNodefilterExpressionprojectionExpressionsoutputSymbols);
         }
 
         private PhysicalOperation visitScanFilterAndProject(
                 LocalExecutionPlanContext context,
                 PlanNode sourceNode,
                 Expression filterExpression,
                 List<ExpressionprojectionExpressions,
                 List<SymboloutputSymbols)
         {
             // if source is a table scan we fold it directly into the filter and project
             // otherwise we plan it as a normal operator
             Map<SymbolIntegersourceLayout;
             Map<IntegerTypesourceTypes;
             List<ColumnHandlecolumns = null;
             PhysicalOperation source = null;
             if (sourceNode instanceof TableScanNode) {
                 TableScanNode tableScanNode = (TableScanNodesourceNode;
 
                 // extract the column handles and channel to type mapping
                 sourceLayout = new LinkedHashMap<>();
                 sourceTypes = new LinkedHashMap<>();
                 columns = new ArrayList<>();
                 int channel = 0;
                 for (Symbol symbol : tableScanNode.getOutputSymbols()) {
                     columns.add(tableScanNode.getAssignments().get(symbol));
 
                     Integer input = channel;
                     sourceLayout.put(symbolinput);
 
                     Type type = checkNotNull(context.getTypes().get(symbol), "No type for symbol %s"symbol);
                     sourceTypes.put(inputtype);
 
                     channel++;
                 }
             }
             else {
                 // plan source
                 source = sourceNode.accept(thiscontext);
                 sourceLayout = source.getLayout();
                 sourceTypes = getInputTypes(source.getLayout(), source.getTypes());
             }
 
             // build output mapping
             ImmutableMap.Builder<SymbolIntegeroutputMappingsBuilder = ImmutableMap.builder();
             for (int i = 0; i < outputSymbols.size(); i++) {
                 Symbol symbol = outputSymbols.get(i);
                 outputMappingsBuilder.put(symboli);
             }
             Map<SymbolIntegeroutputMappings = outputMappingsBuilder.build();
 
             // compiler uses inputs instead of symbols, so rewrite the expressions first
             SymbolToInputRewriter symbolToInputRewriter = new SymbolToInputRewriter(sourceLayout);
             Expression rewrittenFilter = ExpressionTreeRewriter.rewriteWith(symbolToInputRewriterfilterExpression);
 
             List<ExpressionrewrittenProjections = new ArrayList<>();
             for (Expression projection : projectionExpressions) {
                 rewrittenProjections.add(ExpressionTreeRewriter.rewriteWith(symbolToInputRewriterprojection));
             }
 
             IdentityHashMap<ExpressionTypeexpressionTypes = getExpressionTypesFromInput(
                     context.getSession(),
                     ,
                     ,
                     sourceTypes,
                     concat(singleton(rewrittenFilter), rewrittenProjections));
 
             RowExpression translatedFilter = SqlToRowExpressionTranslator.translate(rewrittenFilterexpressionTypestrue);
             List<RowExpressiontranslatedProjections = SqlToRowExpressionTranslator.translate(rewrittenProjectionsexpressionTypestrue);
 
             try {
                 if (columns != null) {
                     CursorProcessor cursorProcessor = .compileCursorProcessor(translatedFiltertranslatedProjectionssourceNode.getId());
                     PageProcessor pageProcessor = .compilePageProcessor(translatedFiltertranslatedProjections);
 
                     SourceOperatorFactory operatorFactory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(
                             context.getNextOperatorId(),
                             sourceNode.getId(),
                             ,
                             cursorProcessor,
                             pageProcessor,
                             columns,
                             Lists.transform(rewrittenProjectionsforMap(expressionTypes)));
 
                     return new PhysicalOperation(operatorFactoryoutputMappings);
                 }
                 else {
                     PageProcessor processor = .compilePageProcessor(translatedFiltertranslatedProjections);
 
                     OperatorFactory operatorFactory = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(
                             context.getNextOperatorId(),
                             processor,
                             Lists.transform(rewrittenProjectionsforMap(expressionTypes)));
 
                     return new PhysicalOperation(operatorFactoryoutputMappingssource);
                 }
             }
             catch (RuntimeException e) {
                 if (!) {
                     throw new PrestoException("Compiler failed and interpreter is disabled"e);
                 }
 
                 // compilation failed, use interpreter
                 .error(e"Compile failed for filter=%s projections=%s sourceTypes=%s error=%s"filterExpressionprojectionExpressionssourceTypese);
             }
 
             FilterFunction filterFunction;
             if (filterExpression != .) {
                 filterFunction = new InterpretedFilterFunction(filterExpressioncontext.getTypes(), sourceLayoutcontext.getSession());
             }
             else {
                 filterFunction = .;
             }
 
             List<ProjectionFunctionprojectionFunctions = new ArrayList<>();
             for (Expression expression : projectionExpressions) {
                 ProjectionFunction function;
                 if (expression instanceof QualifiedNameReference) {
                     // fast path when we know it's a direct symbol reference
                     Symbol reference = Symbol.fromQualifiedName(((QualifiedNameReferenceexpression).getName());
                     function = ProjectionFunctions.singleColumn(context.getTypes().get(reference), sourceLayout.get(reference));
                 }
                 else {
                     function = new InterpretedProjectionFunction(
                             expression,
                             context.getTypes(),
                             sourceLayout,
                             ,
                             ,
                             context.getSession()
                     );
                 }
                 projectionFunctions.add(function);
             }
 
             if (columns != null) {
                 OperatorFactory operatorFactory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(
                         context.getNextOperatorId(),
                         sourceNode.getId(),
                         ,
                         new GenericCursorProcessor(filterFunctionprojectionFunctions),
                         new GenericPageProcessor(filterFunctionprojectionFunctions),
                         columns,
                         toTypes(projectionFunctions));
 
                 return new PhysicalOperation(operatorFactoryoutputMappings);
             }
             else {
                 OperatorFactory operatorFactory = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(
                         context.getNextOperatorId(),
                         new GenericPageProcessor(filterFunctionprojectionFunctions),
                         toTypes(projectionFunctions));
                 return new PhysicalOperation(operatorFactoryoutputMappingssource);
             }
         }
 
         private Map<IntegerTypegetInputTypes(Map<SymbolIntegerlayoutList<Typetypes)
         {
             Builder<IntegerTypeinputTypes = ImmutableMap.builder();
             for (Integer input : ImmutableSet.copyOf(layout.values())) {
                 Type type = types.get(input);
                 inputTypes.put(inputtype);
             }
             return inputTypes.build();
         }
 
         @Override
         public PhysicalOperation visitTableScan(TableScanNode nodeLocalExecutionPlanContext context)
         {
             List<ColumnHandlecolumns = new ArrayList<>();
             for (Symbol symbol : node.getOutputSymbols()) {
                 columns.add(node.getAssignments().get(symbol));
             }
 
             List<Typetypes = getSourceOperatorTypes(nodecontext.getTypes());
             OperatorFactory operatorFactory = new TableScanOperatorFactory(context.getNextOperatorId(), node.getId(), typescolumns);
             return new PhysicalOperation(operatorFactorymakeLayout(node));
         }
 
         @Override
         public PhysicalOperation visitValues(ValuesNode nodeLocalExecutionPlanContext context)
         {
             List<TypeoutputTypes = new ArrayList<>();
 
             for (Symbol symbol : node.getOutputSymbols()) {
                 Type type = checkNotNull(context.getTypes().get(symbol), "No type for symbol %s"symbol);
                 outputTypes.add(type);
             }
 
             if (node.getRows().size() == 0) {
            &n