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.TopNRowNumberOperator.TopNRowNumberOperatorFactory;
 import static com.facebook.presto.spi.type.BigintType.BIGINT;
 import static com.facebook.presto.spi.type.DoubleType.DOUBLE;
 import static com.facebook.presto.testing.MaterializedResult.resultBuilder;
 import static com.facebook.presto.testing.TestingTaskContext.createTaskContext;
 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"));
                 .addPipelineContext(truetrue)
                 .addDriverContext();
     }
 
     @AfterMethod
     public void tearDown()
     {
         .shutdownNow();
     }
 
     @DataProvider(name = "hashEnabledValues")
     public static Object[][] hashEnabledValuesProvider()
     {
         return new Object[][] { { true }, { false } };
     }
 
     @Test(dataProvider = "hashEnabledValues")
     public void testTopNRowNumberPartitioned(boolean hashEnabled)
             throws Exception
     {
         RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), );
         List<Pageinput = rowPagesBuilder
                 .row(1, 0.3)
                 .row(2, 0.2)
                 .row(3, 0.1)
                 .row(3, 0.91)
                 .pageBreak()
                 .row(1, 0.4)
                 .pageBreak()
                 .row(1, 0.5)
                 .row(1, 0.6)
                 .row(2, 0.7)
                 .row(2, 0.8)
                 .pageBreak()
                 .row(2, 0.9)
                 .build();
 
         TopNRowNumberOperatorFactory operatorFactory = new TopNRowNumberOperatorFactory(
                 0,
                 ImmutableList.of(),
                 Ints.asList(1, 0),
                 Ints.asList(0),
                 ImmutableList.of(),
                 Ints.asList(1),
                 ImmutableList.of(.),
                 3,
                false,
                Optional.empty(),
                10);
        Operator operator = operatorFactory.createOperator();
                .row(0.3, 1, 1)
                .row(0.4, 1, 2)
                .row(0.5, 1, 3)
                .row(0.2, 2, 1)
                .row(0.7, 2, 2)
                .row(0.8, 2, 3)
                .row(0.1, 3, 1)
                .row(0.91, 3, 2)
                .build();
        assertOperatorEquals(operatorinputexpected);
    }
    @Test
    public void testTopNRowNumberUnPartitioned()
            throws Exception
    {
        List<Pageinput = rowPagesBuilder()
                .row(1, 0.3)
                .row(2, 0.2)
                .row(3, 0.1)
                .row(3, 0.91)
                .pageBreak()
                .row(1, 0.4)
                .pageBreak()
                .row(1, 0.5)
                .row(1, 0.6)
                .row(2, 0.7)
                .row(2, 0.8)
                .pageBreak()
                .row(2, 0.9)
                .build();
        TopNRowNumberOperatorFactory operatorFactory = new TopNRowNumberOperatorFactory(
                0,
                ImmutableList.of(),
                Ints.asList(1, 0),
                Ints.asList(),
                ImmutableList.<Type>of(),
                Ints.asList(1),
                ImmutableList.of(.),
                3,
                false,
                Optional.empty(),
                10);
        Operator operator = operatorFactory.createOperator();
                .row(0.1, 3, 1)
                .row(0.2, 2, 2)
                .row(0.3, 1, 3)
                .build();
        assertOperatorEquals(operatorinputexpected);
    }
New to GrepCode? Check out our FAQ X