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.spi.type.BooleanType.BOOLEAN;
 import static com.facebook.presto.util.MoreFutures.tryGetUnchecked;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 
 public class HashSemiJoinOperator
         implements Operator
 {
     private final OperatorContext operatorContext;
 
     public static class HashSemiJoinOperatorFactory
             implements OperatorFactory
     {
         private final int operatorId;
         private final SetSupplier setSupplier;
         private final List<TypeprobeTypes;
         private final int probeJoinChannel;
         private final Optional<IntegerprobeHashChannel;
         private final List<Typetypes;
         private boolean closed;
 
         public HashSemiJoinOperatorFactory(int operatorIdSetSupplier setSupplierList<? extends TypeprobeTypesint probeJoinChannelOptional<IntegerprobeHashChannel)
         {
             this. = operatorId;
             this. = setSupplier;
             this. = ImmutableList.copyOf(probeTypes);
             checkArgument(probeJoinChannel >= 0, "probeJoinChannel is negative");
             this. = probeJoinChannel;
             this. = checkNotNull(probeHashChannel"probeHashChannel is null");
 
             this. = ImmutableList.<Type>builder()
                     .addAll(probeTypes)
                     .add()
                     .build();
         }
 
         @Override
         public List<TypegetTypes()
         {
             return ;
         }
 
         @Override
         public Operator createOperator(DriverContext driverContext)
         {
             checkState(!"Factory is already closed");
             OperatorContext operatorContext = driverContext.addOperatorContext(HashBuilderOperator.class.getSimpleName());
             return new HashSemiJoinOperator(operatorContext);
         }
 
         @Override
         public void close()
         {
              = true;
         }
     }
 
     private final int probeJoinChannel;
     private final Optional<IntegerprobeHashChannel;
     private final List<Typetypes;
     private final ListenableFuture<ChannelSetchannelSetFuture;
 
     private ChannelSet channelSet;
     private Page outputPage;
     private boolean finishing;
 
     public HashSemiJoinOperator(OperatorContext operatorContextSetSupplier channelSetFutureList<TypeprobeTypesint probeJoinChannelOptional<IntegerprobeHashChannel)
     {
         this. = checkNotNull(operatorContext"operatorContext is null");
 
         // todo pass in desired projection
         checkNotNull(channelSetFuture"hashProvider is null");
        checkNotNull(probeTypes"probeTypes is null");
        checkArgument(probeJoinChannel >= 0, "probeJoinChannel is negative");
        this. = channelSetFuture.getChannelSet();
        this. = probeJoinChannel;
        this. = probeHashChannel;
        this. = ImmutableList.<Type>builder()
                .addAll(probeTypes)
                .add()
                .build();
    }
    @Override
    {
        return ;
    }
    @Override
    public List<TypegetTypes()
    {
        return ;
    }
    @Override
    public void finish()
    {
         = true;
    }
    @Override
    public boolean isFinished()
    {
        return  &&  == null;
    }
    @Override
    public ListenableFuture<?> isBlocked()
    {
        return ;
    }
    @Override
    public boolean needsInput()
    {
        if ( ||  != null) {
            return false;
        }
        if ( == null) {
             = tryGetUnchecked();
        }
        return  != null;
    }
    @Override
    public void addInput(Page page)
    {
        checkNotNull(page"page is null");
        checkState(!"Operator is finishing");
        checkState( != null"Set has not been built yet");
        checkState( == null"Operator still has pending output");
        // create the block builder for the new boolean column
        // we know the exact size required for the block
        BlockBuilder blockBuilder = .createFixedSizeBlockBuilder(page.getPositionCount());
        Page probeJoinPage = new Page(page.getBlock());
        // update hashing strategy to use probe cursor
        for (int position = 0; position < page.getPositionCount(); position++) {
            if (probeJoinPage.getBlock(0).isNull(position)) {
                blockBuilder.appendNull();
            }
            else {
                boolean contains;
                if (.isPresent()) {
                    contains = .contains(positionprobeJoinPage,  page.getBlock(.get()));
                }
                else {
                    contains = .contains(positionprobeJoinPage);
                }
                if (!contains && .containsNull()) {
                    blockBuilder.appendNull();
                }
                else {
                    .writeBoolean(blockBuildercontains);
                }
            }
        }
        // add the new boolean column to the page
        Block[] sourceBlocks = page.getBlocks();
        Block[] outputBlocks = new Block[sourceBlocks.length + 1]; // +1 for the single boolean output channel
        System.arraycopy(sourceBlocks, 0, outputBlocks, 0, sourceBlocks.length);
        outputBlocks[sourceBlocks.length] = blockBuilder.build();
         = new Page(outputBlocks);
    }
    @Override
    public Page getOutput()
    {
        Page result = ;
         = null;
        return result;
    }
New to GrepCode? Check out our FAQ X