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.SessionTestUtils.TEST_SESSION;
 import static com.facebook.presto.operator.OperatorAssertion.toMaterializedResult;
 import static com.facebook.presto.operator.ProjectionFunctions.singleColumn;
 import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
 import static io.airlift.concurrent.Threads.daemonThreadsNamed;
 import static java.util.concurrent.Executors.newCachedThreadPool;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 
 {
     private final ExecutorService executor;
 
     {
          = newCachedThreadPool(daemonThreadsNamed("test"));
     }
 
     @Test
     public void testPageSource()
             throws Exception
     {
         final Page input = SequencePageBuilder.createSequencePage(ImmutableList.of(), 10_000, 0);
         DriverContext driverContext = newDriverContext();
 
                 0,
                 new PlanNodeId("0"),
                 new PageSourceProvider() {
                     @Override
                     public ConnectorPageSource createPageSource(Split splitList<ColumnHandlecolumns)
                     {
                         return new FixedPageSource(ImmutableList.of(input));
                     }
                 },
                 new GenericCursorProcessor(., ImmutableList.of(singleColumn(, 0))),
                 new GenericPageProcessor(., ImmutableList.of(singleColumn(, 0))),
                 ImmutableList.<ColumnHandle>of(),
                 ImmutableList.<Type>of());
 
         SourceOperator operator = factory.createOperator(driverContext);
         operator.addSplit(new Split("test", TestingSplit.createLocalSplit()));
         operator.noMoreSplits();
 
         MaterializedResult expected = toMaterializedResult(driverContext.getSession(), ImmutableList.<Type>of(), ImmutableList.of(input));
         MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.<Type>of(), toPages(operator));
 
         assertEquals(actual.getRowCount(), expected.getRowCount());
         assertEquals(actualexpected);
     }
 
     @Test
     public void testRecordCursorSource()
             throws Exception
     {
         final Page input = SequencePageBuilder.createSequencePage(ImmutableList.of(), 10_000, 0);
         DriverContext driverContext = newDriverContext();
 
                 0,
                 new PlanNodeId("0"),
                 new PageSourceProvider() {
                     @Override
                     public ConnectorPageSource createPageSource(Split splitList<ColumnHandlecolumns)
                    {
                        return new RecordPageSource(new PageRecordSet(ImmutableList.<Type>of(), input));
                    }
                },
                new GenericCursorProcessor(., ImmutableList.of(singleColumn(, 0))),
                new GenericPageProcessor(., ImmutableList.of(singleColumn(, 0))),
                ImmutableList.<ColumnHandle>of(),
                ImmutableList.<Type>of());
        SourceOperator operator = factory.createOperator(driverContext);
        operator.addSplit(new Split("test", TestingSplit.createLocalSplit()));
        operator.noMoreSplits();
        MaterializedResult expected = toMaterializedResult(driverContext.getSession(), ImmutableList.<Type>of(), ImmutableList.of(input));
        MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.<Type>of(), toPages(operator));
        assertEquals(actual.getRowCount(), expected.getRowCount());
        assertEquals(actualexpected);
    }
    public static List<PagetoPages(Operator operator)
    {
        ImmutableList.Builder<PageoutputPages = ImmutableList.builder();
        // read output until input is needed or operator is finished
        int nullPages = 0;
        while (!operator.isFinished()) {
            Page outputPage = operator.getOutput();
            if (outputPage == null) {
                // break infinite loop due to null pages
                assertTrue(nullPages < 1_000_000, "Too many null pages; infinite loop?");
                nullPages++;
            }
            else {
                outputPages.add(outputPage);
                nullPages = 0;
            }
        }
        return outputPages.build();
    }
    {
        return new TaskContext(new TaskId("query""stage""task"), )
                .addPipelineContext(truetrue)
                .addDriverContext();
    }
New to GrepCode? Check out our FAQ X