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.RowPagesBuilder.rowPagesBuilder;
 import static com.facebook.presto.SessionTestUtils.TEST_SESSION;
 import static com.facebook.presto.operator.OperatorAssertion.assertOperatorEquals;
 import static com.facebook.presto.operator.ProjectionFunctions.singleColumn;
 import static com.facebook.presto.spi.type.BigintType.BIGINT;
 import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
 import static io.airlift.concurrent.Threads.daemonThreadsNamed;
 import static java.util.concurrent.Executors.newCachedThreadPool;
 
 @Test(singleThreaded = true)
 {
     private ExecutorService executor;
     private DriverContext driverContext;
 
     @BeforeMethod
     public void setUp()
     {
          = newCachedThreadPool(daemonThreadsNamed("test-%s"));
 
          = new TaskContext(new TaskId("query""stage""task"), )
                 .addPipelineContext(truetrue)
                 .addDriverContext();
     }
 
     @AfterMethod
     public void tearDown()
     {
         .shutdownNow();
     }
 
     @Test
     public void test()
             throws Exception
     {
         List<Pageinput = rowPagesBuilder()
                 .addSequencePage(100, 0, 0)
                 .build();
 
         FilterFunction filter = new FilterFunction()
         {
             @Override
             public boolean filter(int positionBlock... blocks)
             {
                 long value = .getLong(blocks[1], position);
                 return 10 <= value && value < 20;
             }
 
             @Override
             public boolean filter(RecordCursor cursor)
             {
                 long value = cursor.getLong(0);
                 return 10 <= value && value < 20;
             }
         };
                 0,
                 new GenericPageProcessor(filter, ImmutableList.of(singleColumn(, 0), new Add5Projection(1))),
                 ImmutableList.<Type>of());
 
         Operator operator = operatorFactory.createOperator();
 
         MaterializedResult expected = MaterializedResult.resultBuilder(.getSession(), )
                 .row("10", 15)
                 .row("11", 16)
                 .row("12", 17)
                 .row("13", 18)
                 .row("14", 19)
                 .row("15", 20)
                .row("16", 21)
                .row("17", 22)
                .row("18", 23)
                .row("19", 24)
                .build();
        assertOperatorEquals(operatorinputexpected);
    }
    private static class Add5Projection
            implements ProjectionFunction
    {
        private final int channelIndex;
        public Add5Projection(int channelIndex)
        {
            this. = channelIndex;
        }
        @Override
        public Type getType()
        {
            return ;
        }
        @Override
        public void project(int positionBlock[] blocksBlockBuilder output)
        {
            if (blocks[].isNull(position)) {
                output.appendNull();
            }
            else {
                .writeLong(output.getLong(blocks[], position) + 5);
            }
        }
        @Override
        public void project(RecordCursor cursorBlockBuilder output)
        {
            if (cursor.isNull()) {
                output.appendNull();
            }
            else {
                .writeLong(outputcursor.getLong() + 5);
            }
        }
    }
New to GrepCode? Check out our FAQ X