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;
public final class ProjectionFunctions
    private ProjectionFunctions() {}
    public static ProjectionFunction singleColumn(Type columnTypeint channelIndex)
    {
        return new SingleColumnProjection(columnTypechannelIndex);
    }
    private static class SingleColumnProjection
            implements ProjectionFunction
    {
        private final Type columnType;
        private final int channelIndex;
        public SingleColumnProjection(Type columnTypeint channelIndex)
        {
            Preconditions.checkNotNull(columnType"columnType is null");
            Preconditions.checkArgument(channelIndex >= 0, "channelIndex is negative");
            this. = columnType;
            this. = channelIndex;
        }
        @Override
        public Type getType()
        {
            return ;
        }
        @Override
        public void project(int positionBlock[] blocksBlockBuilder output)
        {
            if (blocks[].isNull(position)) {
                output.appendNull();
            }
            else {
                .appendTo(blocks[], positionoutput);
            }
        }
        @Override
        public void project(RecordCursor cursorBlockBuilder output)
        {
            // record cursors have each value in a separate field
            if (cursor.isNull()) {
                output.appendNull();
            }
            else {
                Class<?> javaType = .getJavaType();
                if (javaType == boolean.class) {
                    .writeBoolean(outputcursor.getBoolean());
                }
                else if (javaType == long.class) {
                    .writeLong(outputcursor.getLong());
                }
                else if (javaType == double.class) {
                    .writeDouble(outputcursor.getDouble());
                }
                else if (javaType == Slice.class) {
                    Slice slice = cursor.getSlice();
                    .writeSlice(outputslice, 0, slice.length());
                }
                else {
                    throw new UnsupportedOperationException("not yet implemented: " + javaType);
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X