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.operator;
 
 
 import java.util.List;
 
 import static com.facebook.presto.spi.type.BigintType.BIGINT;
 import static com.facebook.presto.spi.type.VarbinaryType.VARBINARY;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 
 public class TableCommitOperator
         implements Operator
 {
     public static final List<TypeTYPES = ImmutableList.<Type>of();
 
     public static class TableCommitOperatorFactory
             implements OperatorFactory
     {
         private final int operatorId;
         private final TableCommitter tableCommitter;
         private boolean closed;
 
         public TableCommitOperatorFactory(int operatorIdTableCommitter tableCommitter)
         {
             this. = operatorId;
             this. = checkNotNull(tableCommitter"tableCommitter is null");
         }
 
         @Override
         public List<TypegetTypes()
         {
             return ;
         }
 
         @Override
         public Operator createOperator(DriverContext driverContext)
         {
             checkState(!"Factory is already closed");
             OperatorContext context = driverContext.addOperatorContext(TableCommitOperator.class.getSimpleName());
             return new TableCommitOperator(context);
         }
 
         @Override
         public void close()
         {
              = true;
         }
     }
 
     private enum State
     {
         RUNNING, FINISHING, FINISHED
     }
 
     private final OperatorContext operatorContext;
     private final TableCommitter tableCommitter;
 
     private State state = .;
     private long rowCount;
     private final ImmutableList.Builder<SlicefragmentBuilder = ImmutableList.builder();
 
     public TableCommitOperator(OperatorContext operatorContextTableCommitter tableCommitter)
     {
         this. = checkNotNull(operatorContext"operatorContext is null");
         this. = checkNotNull(tableCommitter"tableCommitter is null");
     }
 
     @Override
     {
         return ;
     }
 
     @Override
     public List<TypegetTypes()
     {
         return ;
     }
 
    @Override
    public void finish()
    {
        if ( == .) {
             = .;
        }
    }
    @Override
    public boolean isFinished()
    {
        return  == .;
    }
    @Override
    public boolean needsInput()
    {
        return  == .;
    }
    @Override
    public void addInput(Page page)
    {
        checkNotNull(page"page is null");
        checkState( == ."Operator is %s");
        Block rowCountBlock = page.getBlock(0);
        Block fragmentBlock = page.getBlock(1);
        for (int position = 0; position < page.getPositionCount(); position++) {
            if (!rowCountBlock.isNull(position)) {
                 += .getLong(rowCountBlockposition);
            }
            if (!fragmentBlock.isNull(position)) {
                .add(.getSlice(fragmentBlockposition));
            }
        }
    }
    @Override
    public Page getOutput()
    {
        if ( != .) {
            return null;
        }
         = .;
        PageBuilder page = new PageBuilder(getTypes());
        page.declarePosition();
        .writeLong(page.getBlockBuilder(0), );
        return page.build();
    }
    public interface TableCommitter
    {
        void commitTable(Collection<Slicefragments);
    }
New to GrepCode? Check out our FAQ X