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.spi.type.BigintType.BIGINT;
 import static com.facebook.presto.spi.type.BooleanType.BOOLEAN;
 import static com.facebook.presto.testing.MaterializedResult.resultBuilder;
 import static com.google.common.collect.Iterables.concat;
 import static io.airlift.concurrent.Threads.daemonThreadsNamed;
 import static io.airlift.units.DataSize.Unit.BYTE;
 import static java.util.concurrent.Executors.newCachedThreadPool;
 
 @Test(singleThreaded = true)
 {
     private ExecutorService executor;
     private TaskContext taskContext;
 
     @BeforeMethod
     public void setUp()
     {
          = newCachedThreadPool(daemonThreadsNamed("test-%s"));
          = new TaskContext(new TaskId("query""stage""task"), );
     }
 
     @AfterMethod
     public void tearDown()
     {
         .shutdownNow();
     }
 
     @DataProvider(name = "hashEnabledValues")
     public static Object[][] hashEnabledValuesProvider()
     {
         return new Object[][] { { true }, { false } };
     }
 
     @Test(dataProvider = "hashEnabledValues")
     public void testSemiJoin(boolean hashEnabled)
             throws Exception
     {
         DriverContext driverContext = .addPipelineContext(truetrue).addDriverContext();
 
         // build
         OperatorContext operatorContext = driverContext.addOperatorContext(0, ValuesOperator.class.getSimpleName());
         RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), );
         Operator buildOperator = new ValuesOperator(operatorContextrowPagesBuilder.getTypes(), rowPagesBuilder
                 .row(10)
                 .row(30)
                 .row(30)
                 .row(35)
                 .row(36)
                 .row(37)
                 .row(50)
                 .build());
         SetBuilderOperatorFactory setBuilderOperatorFactory = new SetBuilderOperatorFactory(1, buildOperator.getTypes(), 0, rowPagesBuilder.getHashChannel(), 10);
         Operator setBuilderOperator = setBuilderOperatorFactory.createOperator(driverContext);
 
         Driver driver = new Driver(driverContextbuildOperatorsetBuilderOperator);
         while (!driver.isFinished()) {
             driver.process();
         }
 
         // probe
         List<TypeprobeTypes = ImmutableList.<Type>of();
         RowPagesBuilder rowPagesBuilderProbe = rowPagesBuilder(hashEnabled, Ints.asList(0), );
         List<PageprobeInput = rowPagesBuilderProbe
                .addSequencePage(10, 30, 0)
                .build();
        HashSemiJoinOperatorFactory joinOperatorFactory = new HashSemiJoinOperatorFactory(
                2,
                setBuilderOperatorFactory.getSetProvider(),
                rowPagesBuilderProbe.getTypes(),
                0,
                rowPagesBuilderProbe.getHashChannel());
        Operator joinOperator = joinOperatorFactory.createOperator(driverContext);
        // expected
        MaterializedResult expected = resultBuilder(driverContext.getSession(), concat(probeTypes, ImmutableList.of()))
                .row(30, 0, true)
                .row(31, 1, false)
                .row(32, 2, false)
                .row(33, 3, false)
                .row(34, 4, false)
                .row(35, 5, true)
                .row(36, 6, true)
                .row(37, 7, true)
                .row(38, 8, false)
                .row(39, 9, false)
                .build();
        OperatorAssertion.assertOperatorEquals(joinOperatorprobeInputexpectedhashEnabled, ImmutableList.of(probeTypes.size()));
    }
    @Test(dataProvider = "hashEnabledValues")
    public void testBuildSideNulls(boolean hashEnabled)
            throws Exception
    {
        DriverContext driverContext = .addPipelineContext(truetrue).addDriverContext();
        // build
        OperatorContext operatorContext = driverContext.addOperatorContext(0, ValuesOperator.class.getSimpleName());
        List<TypebuildTypes = ImmutableList.<Type>of();
        RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), buildTypes);
        Operator buildOperator = new ValuesOperator(operatorContextbuildTypesrowPagesBuilder
                .row(0)
                .row(1)
                .row(2)
                .row(2)
                .row(3)
                .row((Objectnull)
                .build());
        SetBuilderOperatorFactory setBuilderOperatorFactory = new SetBuilderOperatorFactory(1, buildOperator.getTypes(), 0, rowPagesBuilder.getHashChannel(), 10);
        Operator setBuilderOperator = setBuilderOperatorFactory.createOperator(driverContext);
        Driver driver = new Driver(driverContextbuildOperatorsetBuilderOperator);
        while (!driver.isFinished()) {
            driver.process();
        }
        // probe
        List<TypeprobeTypes = ImmutableList.<Type>of();
        RowPagesBuilder rowPagesBuilderProbe = rowPagesBuilder(hashEnabled, Ints.asList(0), probeTypes);
        List<PageprobeInput = rowPagesBuilderProbe
                .addSequencePage(4, 1)
                .build();
        HashSemiJoinOperatorFactory joinOperatorFactory = new HashSemiJoinOperatorFactory(
                2,
                setBuilderOperatorFactory.getSetProvider(),
                rowPagesBuilderProbe.getTypes(),
                0,
                rowPagesBuilderProbe.getHashChannel());
        Operator joinOperator = joinOperatorFactory.createOperator(driverContext);
        // expected
        MaterializedResult expected = resultBuilder(driverContext.getSession(), concat(probeTypes, ImmutableList.of()))
                .row(1, true)
                .row(2, true)
                .row(3, true)
                .row(4, null)
                .build();
        OperatorAssertion.assertOperatorEquals(joinOperatorprobeInputexpectedhashEnabled, ImmutableList.of(probeTypes.size()));
    }
    @Test(dataProvider = "hashEnabledValues")
    public void testProbeSideNulls(boolean hashEnabled)
            throws Exception
    {
        DriverContext driverContext = .addPipelineContext(truetrue).addDriverContext();
        // build
        OperatorContext operatorContext = driverContext.addOperatorContext(0, ValuesOperator.class.getSimpleName());
        List<TypebuildTypes = ImmutableList.<Type>of();
        RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), buildTypes);
        Operator buildOperator = new ValuesOperator(operatorContextbuildTypesrowPagesBuilder
                .row(0)
                .row(1)
                .row(3)
                .build());
        SetBuilderOperatorFactory setBuilderOperatorFactory = new SetBuilderOperatorFactory(1, buildOperator.getTypes(), 0, rowPagesBuilder.getHashChannel(), 10);
        Operator setBuilderOperator = setBuilderOperatorFactory.createOperator(driverContext);
        Driver driver = new Driver(driverContextbuildOperatorsetBuilderOperator);
        while (!driver.isFinished()) {
            driver.process();
        }
        // probe
        List<TypeprobeTypes = ImmutableList.<Type>of();
        RowPagesBuilder rowPagesBuilderProbe = rowPagesBuilder(hashEnabled, Ints.asList(0), probeTypes);
        List<PageprobeInput = rowPagesBuilderProbe
                .row(0)
                .row((Objectnull)
                .row(1)
                .row(2)
                .build();
        HashSemiJoinOperatorFactory joinOperatorFactory = new HashSemiJoinOperatorFactory(
                2,
                setBuilderOperatorFactory.getSetProvider(),
                rowPagesBuilderProbe.getTypes(),
                0,
                rowPagesBuilderProbe.getHashChannel());
        Operator joinOperator = joinOperatorFactory.createOperator(driverContext);
        // expected
        MaterializedResult expected = resultBuilder(driverContext.getSession(), concat(probeTypes, ImmutableList.of()))
                .row(0, true)
                .row(nullnull)
                .row(1, true)
                .row(2, false)
                .build();
        OperatorAssertion.assertOperatorEquals(joinOperatorprobeInputexpectedhashEnabled, ImmutableList.of(probeTypes.size()));
    }
    @Test(dataProvider = "hashEnabledValues")
    public void testProbeAndBuildNulls(boolean hashEnabled)
            throws Exception
    {
        DriverContext driverContext = .addPipelineContext(truetrue).addDriverContext();
        // build
        OperatorContext operatorContext = driverContext.addOperatorContext(0, ValuesOperator.class.getSimpleName());
        List<TypebuildTypes = ImmutableList.<Type>of();
        RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), buildTypes);
        Operator buildOperator = new ValuesOperator(operatorContextbuildTypesrowPagesBuilder
                .row(0)
                .row(1)
                .row((Objectnull)
                .row(3)
                .build());
        SetBuilderOperatorFactory setBuilderOperatorFactory = new SetBuilderOperatorFactory(1, buildOperator.getTypes(), 0, rowPagesBuilder.getHashChannel(), 10);
        Operator setBuilderOperator = setBuilderOperatorFactory.createOperator(driverContext);
        Driver driver = new Driver(driverContextbuildOperatorsetBuilderOperator);
        while (!driver.isFinished()) {
            driver.process();
        }
        // probe
        List<TypeprobeTypes = ImmutableList.<Type>of();
        RowPagesBuilder rowPagesBuilderProbe = rowPagesBuilder(hashEnabled, Ints.asList(0), probeTypes);
        List<PageprobeInput = rowPagesBuilderProbe
                .row(0)
                .row((Objectnull)
                .row(1)
                .row(2)
                .build();
        HashSemiJoinOperatorFactory joinOperatorFactory = new HashSemiJoinOperatorFactory(
                2,
                setBuilderOperatorFactory.getSetProvider(),
                rowPagesBuilderProbe.getTypes(),
                0,
                rowPagesBuilderProbe.getHashChannel());
        Operator joinOperator = joinOperatorFactory.createOperator(driverContext);
        // expected
        MaterializedResult expected = resultBuilder(driverContext.getSession(), concat(probeTypes, ImmutableList.of()))
                .row(0, true)
                .row(nullnull)
                .row(1, true)
                .row(2, null)
                .build();
        OperatorAssertion.assertOperatorEquals(joinOperatorprobeInputexpectedhashEnabled, ImmutableList.of(probeTypes.size()));
    }
    @Test(dataProvider = "hashEnabledValues", expectedExceptions = ExceededMemoryLimitException.class, expectedExceptionsMessageRegExp = "Task exceeded max memory size.*")
    public void testMemoryLimit(boolean hashEnabled)
            throws Exception
    {
        DriverContext driverContext = new TaskContext(new TaskId("query""stage""task"), new DataSize(100, ))
                .addPipelineContext(truetrue)
                .addDriverContext();
        OperatorContext operatorContext = driverContext.addOperatorContext(0, ValuesOperator.class.getSimpleName());
        List<TypebuildTypes = ImmutableList.<Type>of();
        RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), buildTypes);
        Operator buildOperator = new ValuesOperator(operatorContextbuildTypesrowPagesBuilder
                .addSequencePage(10000, 20)
                .build());
        SetBuilderOperatorFactory setBuilderOperatorFactory = new SetBuilderOperatorFactory(1, buildOperator.getTypes(), 0, rowPagesBuilder.getHashChannel(), 10);
        Operator setBuilderOperator = setBuilderOperatorFactory.createOperator(driverContext);
        Driver driver = new Driver(driverContextbuildOperatorsetBuilderOperator);
        while (!driver.isFinished()) {
            driver.process();
        }
    }
New to GrepCode? Check out our FAQ X