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.google.common.base.Preconditions.checkNotNull;
 
 public class RecordProjectOperator
         implements OperatorCloseable
 {
     private static final int ROWS_PER_REQUEST = 4096;
     private final OperatorContext operatorContext;
     private final RecordCursor cursor;
     private final List<Typetypes;
     private final PageBuilder pageBuilder;
     private boolean finishing;
     private long completedBytes;
     private long readTimeNanos;
 
     public RecordProjectOperator(OperatorContext operatorContextRecordSet recordSet)
     {
         this(operatorContextrecordSet.getColumnTypes(), recordSet.cursor());
     }
 
     public RecordProjectOperator(OperatorContext operatorContextList<TypecolumnTypesRecordCursor cursor)
     {
         this. = checkNotNull(operatorContext"operatorContext is null");
         this. = checkNotNull(cursor"cursor is null");
 
         ImmutableList.Builder<Typetypes = ImmutableList.builder();
         for (Type columnType : columnTypes) {
             types.add(columnType);
         }
         this. = types.build();
 
          = new PageBuilder(getTypes());
     }
 
     @Override
     {
         return ;
     }
 
     public RecordCursor getCursor()
     {
         return ;
     }
 
     @Override
     public List<TypegetTypes()
     {
         return ;
     }
 
     @Override
     public void finish()
     {
         close();
     }
 
     @Override
     public void close()
     {
          = true;
         .close();
     }
 
     @Override
     public boolean isFinished()
     {
         return  && .isEmpty();
     }
 
     @Override
     public boolean needsInput()
     {
        return false;
    }
    @Override
    public void addInput(Page page)
    {
        throw new UnsupportedOperationException(getClass().getName() + " can not take input");
    }
    @Override
    public Page getOutput()
    {
        if (!) {
            int i;
            for (i = 0; i < i++) {
                if (.isFull()) {
                    break;
                }
                if (!.advanceNextPosition()) {
                     = true;
                    break;
                }
                .declarePosition();
                for (int column = 0; column < .size(); column++) {
                    BlockBuilder output = .getBlockBuilder(column);
                    if (.isNull(column)) {
                        output.appendNull();
                    }
                    else {
                        Type type = getTypes().get(column);
                        Class<?> javaType = type.getJavaType();
                        if (javaType == boolean.class) {
                            type.writeBoolean(output.getBoolean(column));
                        }
                        else if (javaType == long.class) {
                            type.writeLong(output.getLong(column));
                        }
                        else if (javaType == double.class) {
                            type.writeDouble(output.getDouble(column));
                        }
                        else if (javaType == Slice.class) {
                            Slice slice = .getSlice(column);
                            type.writeSlice(outputslice, 0, slice.length());
                        }
                        else {
                            throw new AssertionError("Unimplemented type: " + javaType.getName());
                        }
                    }
                }
            }
            long endCompletedBytes = .getCompletedBytes();
            long endReadTimeNanos = .getReadTimeNanos();
            .recordGeneratedInput(endCompletedBytes - iendReadTimeNanos - );
             = endCompletedBytes;
             = endReadTimeNanos;
        }
        // only return a full page is buffer is full or we are finishing
        if (.isEmpty() || (! && !.isFull())) {
            return null;
        }
        Page page = .build();
        .reset();
        return page;
    }
New to GrepCode? Check out our FAQ X