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.sql.gen;
 
 
 import java.util.List;
 
 import static com.facebook.presto.SessionTestUtils.TEST_SESSION;
 import static com.facebook.presto.operator.PageAssertions.assertPageEquals;
 import static com.facebook.presto.operator.SyntheticAddress.encodeSyntheticAddress;
 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.assertFalse;
 import static org.testng.Assert.assertTrue;
 
 public class TestJoinProbeCompiler
 {
     private static final JoinCompiler joinCompiler = new JoinCompiler();
     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 testSingleChannel(boolean hashEnabled)
             throws Exception
     {
         DriverContext driverContext = .addPipelineContext(truetrue).addDriverContext();
         OperatorContext operatorContext = driverContext.addOperatorContext(0, ValuesOperator.class.getSimpleName());
 
         ImmutableList<Typetypes = ImmutableList.<Type>of();
         LookupSourceFactory lookupSourceFactoryFactory = .compileLookupSourceFactory(types, Ints.asList(0));
 
         // crate hash strategy with a single channel blocks -- make sure there is some overlap in values
         List<Blockchannel = ImmutableList.of(
                 BlockAssertions.createStringSequenceBlock(10, 20),
                 BlockAssertions.createStringSequenceBlock(20, 30),
                 BlockAssertions.createStringSequenceBlock(15, 25));
         LongArrayList addresses = new LongArrayList();
         for (int blockIndex = 0; blockIndex < channel.size(); blockIndex++) {
             Block block = channel.get(blockIndex);
             for (int positionIndex = 0; positionIndex < block.getPositionCount(); positionIndex++) {
                 addresses.add(encodeSyntheticAddress(blockIndexpositionIndex));
            }
        }
        Optional<IntegerhashChannel = Optional.empty();
        List<List<Block>> channels = ImmutableList.of(channel);
        if (hashEnabled) {
            ImmutableList.Builder<BlockhashChannelBuilder = ImmutableList.builder();
            for (Block block : channel) {
                hashChannelBuilder.add(TypeUtils.getHashBlock(ImmutableList.<Type>of(), block));
            }
            types = ImmutableList.<Type>of(.);
            hashChannel = Optional.of(1);
            channels = ImmutableList.of(channelhashChannelBuilder.build());
        }
        LookupSource lookupSource = lookupSourceFactoryFactory.createLookupSource(addressestypeschannelshashChanneloperatorContext);
        JoinProbeCompiler joinProbeCompiler = new JoinProbeCompiler();
        JoinProbeFactory probeFactory = joinProbeCompiler.internalCompileJoinProbe(types, Ints.asList(0), hashChannel);
        Page page = SequencePageBuilder.createSequencePage(types, 10, 10);
        if (hashEnabled) {
            page = new Page(page.getBlock(0), TypeUtils.getHashBlock(ImmutableList.of(), page.getBlock(0)));
        }
        JoinProbe joinProbe = probeFactory.createJoinProbe(lookupSourcepage);
        // verify channel count
        assertEquals(joinProbe.getChannelCount(), types.size());
        PageBuilder pageBuilder = new PageBuilder(types);
        for (int position = 0; position < page.getPositionCount(); position++) {
            assertTrue(joinProbe.advanceNextPosition());
            pageBuilder.declarePosition();
            joinProbe.appendTo(pageBuilder);
            assertEquals(joinProbe.getCurrentJoinPosition(), lookupSource.getJoinPosition(positionpage));
        }
        assertFalse(joinProbe.advanceNextPosition());
        assertPageEquals(typespageBuilder.build(), page);
    }
New to GrepCode? Check out our FAQ X