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;
 
 
 import java.util.List;
 
 import static com.google.common.base.MoreObjects.toStringHelper;
 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 final class HashPagePartitionFunction
         implements PagePartitionFunction
 {
     private final int partition;
     private final int partitionCount;
     private final List<IntegerpartitioningChannels;
     private final List<Typetypes;
     private final HashGenerator hashGenerator;
     private final Optional<IntegerhashChannel;
 
     @JsonCreator
     public HashPagePartitionFunction(
             @JsonProperty("partition"int partition,
             @JsonProperty("partitionCount"int partitionCount,
             @JsonProperty("partitioningChannels"List<IntegerpartitioningChannels,
             @JsonProperty("hashChannel"Optional<IntegerhashChannel,
             @JsonProperty("types"List<Typetypes)
     {
         checkNotNull(partitioningChannels"partitioningChannels is null");
         checkArgument(!partitioningChannels.isEmpty(), "partitioningChannels is empty");
         this. = checkNotNull(hashChannel"hashChannel is null");
         checkArgument(!hashChannelisPresent() || hashChannel.get() < types.size(), "invalid hashChannel");
 
         this. = partition;
         this. = partitionCount;
         this. = ImmutableList.copyOf(partitioningChannels);
         this. = createHashGenerator(hashChannelpartitioningChannelstypes);
         this. = ImmutableList.copyOf(types);
     }
 
     @JsonProperty
     public int getPartition()
     {
         return ;
     }
 
     @JsonProperty
     public int getPartitionCount()
     {
         return ;
     }
 
     @JsonProperty
     public List<IntegergetPartitioningChannels()
     {
         return ;
     }
 
     @JsonProperty
     public List<TypegetTypes()
     {
         return ;
     }
 
     @JsonProperty
     public Optional<IntegergetHashChannel()
     {
         return ;
     }
 
     @Override
     public List<Pagepartition(List<Pagepages)
     {
         if (pages.isEmpty()) {
             return pages;
        }
        PageBuilder pageBuilder = new PageBuilder();
        ImmutableList.Builder<PagepartitionedPages = ImmutableList.builder();
        for (Page page : pages) {
            for (int position = 0; position < page.getPositionCount(); position++) {
                // if hash is not in range skip
                int partitionHashBucket = getPartitionHashBucket(positionpage);
                if (partitionHashBucket != ) {
                    continue;
                }
                pageBuilder.declarePosition();
                for (int channel = 0; channel < .size(); channel++) {
                    Type type = .get(channel);
                    type.appendTo(page.getBlock(channel), positionpageBuilder.getBlockBuilder(channel));
                }
                // if page is full, flush
                if (pageBuilder.isFull()) {
                    partitionedPages.add(pageBuilder.build());
                    pageBuilder.reset();
                }
            }
        }
        if (!pageBuilder.isEmpty()) {
            partitionedPages.add(pageBuilder.build());
        }
        return partitionedPages.build();
    }
    private int getPartitionHashBucket(int positionPage page)
    {
        int rawHash = .hashPosition(positionpage);
         // clear the sign bit
        rawHash &= 0x7fff_ffffL;
        int bucket = rawHash % ;
        checkState(bucket >= 0 && bucket < );
        return bucket;
    }
    @Override
    public int hashCode()
    {
        return Objects.hash();
    }
    @Override
    public boolean equals(Object obj)
    {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        HashPagePartitionFunction other = (HashPagePartitionFunctionobj;
        return Objects.equals(this.other.partition) &&
                Objects.equals(this.other.partitionCount) &&
                Objects.equals(this.other.partitioningChannels) &&
                Objects.equals(other.hashChannel);
    }
    @Override
    public String toString()
    {
        return toStringHelper(this)
                .add("partition")
                .add("partitionCount")
                .add("partitioningChannels")
                .add("hashChannel")
                .toString();
    }
    private static HashGenerator createHashGenerator(Optional<IntegerhashChannelList<IntegerpartitioningChannelsList<Typetypes)
    {
        if (hashChannel.isPresent()) {
            return new PrecomputedHashGenerator(hashChannel.get());
        }
        ImmutableList.Builder<TypehashTypes = ImmutableList.builder();
        int[] hashChannels = new int[partitioningChannels.size()];
        for (int i = 0; i < partitioningChannels.size(); i++) {
            int channel = partitioningChannels.get(i);
            hashTypes.add(types.get(channel));
            hashChannels[i] = channel;
        }
        return new InterpretedHashGenerator(hashTypes.build(), hashChannels);
    }
New to GrepCode? Check out our FAQ X