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.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 
 public class MarkDistinctOperator
         implements Operator
 {
     public static class MarkDistinctOperatorFactory
             implements OperatorFactory
     {
         private final int operatorId;
         private final Optional<IntegerhashChannel;
         private final int[] markDistinctChannels;
         private final List<Typetypes;
         private boolean closed;
 
         public MarkDistinctOperatorFactory(int operatorIdList<? extends TypesourceTypesCollection<IntegermarkDistinctChannelsOptional<IntegerhashChannel)
         {
             this. = operatorId;
             checkNotNull(markDistinctChannels"markDistinctChannels is null");
             checkArgument(!markDistinctChannels.isEmpty(), "markDistinctChannels is empty");
             this. = Ints.toArray(markDistinctChannels);
             this. = checkNotNull(hashChannel"hashChannel is null");
             this. = ImmutableList.<Type>builder()
                     .addAll(sourceTypes)
                     .add()
                     .build();
         }
 
         @Override
         public List<TypegetTypes()
         {
             return ;
         }
 
         @Override
         public Operator createOperator(DriverContext driverContext)
         {
             checkState(!"Factory is already closed");
             OperatorContext operatorContext = driverContext.addOperatorContext(MarkDistinctOperator.class.getSimpleName());
             return new MarkDistinctOperator(operatorContext);
         }
 
         @Override
         public void close()
         {
              = true;
         }
     }
 
     private final OperatorContext operatorContext;
     private final List<Typetypes;
     private final MarkDistinctHash markDistinctHash;
 
     private Page outputPage;
     private boolean finishing;
 
     public MarkDistinctOperator(OperatorContext operatorContextList<Typetypesint[] markDistinctChannelsOptional<IntegerhashChannel)
     {
         this. = checkNotNull(operatorContext"operatorContext is null");
 
         this. = ImmutableList.copyOf(checkNotNull(types"types is null"));
         checkArgument(markDistinctChannels.length >= 0, "markDistinctChannels is empty");
         checkNotNull(hashChannel"hashChannel is null");
 
         ImmutableList.Builder<TypedistinctTypes = ImmutableList.builder();
         for (int channel : markDistinctChannels) {
             distinctTypes.add(types.get(channel));
         }
         this. = new MarkDistinctHash(distinctTypes.build(), markDistinctChannelshashChannel);
     }
 
     @Override
    {
        return ;
    }
    @Override
    public List<TypegetTypes()
    {
        return ;
    }
    @Override
    public void finish()
    {
         = true;
    }
    @Override
    public boolean isFinished()
    {
        return  &&  == null;
    }
    @Override
    public boolean needsInput()
    {
        if ( ||  != null) {
            return false;
        }
        return true;
    }
    @Override
    public void addInput(Page page)
    {
        checkNotNull(page"page is null");
        checkState(!"Operator is finishing");
        checkState( == null"Operator still has pending output");
        Block markerBlock = .markDistinctRows(page);
        // 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] = markerBlock;
         = new Page(outputBlocks);
    }
    @Override
    public Page getOutput()
    {
        Page result = ;
         = null;
        return result;
    }
New to GrepCode? Check out our FAQ X