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
   * 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.optimizations;
 import java.util.Map;

Major HACK alert!!! This logic should be invoked on query start, not during planning. At that point, the token returned by beginCreate/beginInsert should be handed down to tasks in a mapping separate from the plan that links plan nodes to the corresponding token.
 public class BeginTableWrite
         extends PlanOptimizer
     private final Metadata metadata;
     public BeginTableWrite(Metadata metadata)
         this. = metadata;
     public PlanNode optimize(PlanNode planSession sessionMap<SymbolTypetypesSymbolAllocator symbolAllocatorPlanNodeIdAllocator idAllocator)
         return PlanRewriter.rewriteWith(new Rewriter(session), plan);
     private class Rewriter
             extends PlanRewriter<Void>
         private final Session session;
         public Rewriter(Session session)
             this. = session;
         public PlanNode visitTableWriter(TableWriterNode nodeRewriteContext<Voidcontext)
             // TODO: begin create table or insert in pre-execution step, not here
             // Part of the plan should be an Optional<StateChangeListener<QueryState>> and this
             // callback can create the table and abort the table creation if the query fails.
             return new TableWriterNode(
         public PlanNode visitTableCommit(TableCommitNode nodeRewriteContext<Voidcontext)
             PlanNode child = node.getSource().accept(thiscontext);
             TableWriterNode tableWriter = Types.checkType(childTableWriterNode.class"table commit node must be preceeded by table writer node");
             TableWriterNode.WriterTarget target = tableWriter.getTarget();
             return new TableCommitNode(node.getId(), childtargetnode.getOutputSymbols());
             if (target instanceof TableWriterNode.CreateName) {
                 TableWriterNode.CreateName create = (TableWriterNode.CreateNametarget;
                 return new TableWriterNode.CreateHandle(.beginCreateTable(create.getCatalog(), create.getTableMetadata()));
             if (target instanceof TableWriterNode.InsertReference) {
                 TableWriterNode.InsertReference insert = (TableWriterNode.InsertReferencetarget;
                 return new TableWriterNode.InsertHandle(.beginInsert(insert.getHandle()));
            throw new AssertionError("Unhandled target type: " + target.getClass().getName());
New to GrepCode? Check out our FAQ X