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.planner.optimizations;
 
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
 import static java.util.Objects.requireNonNull;
 import static java.util.stream.Collectors.toList;
 import static java.util.stream.Collectors.toSet;
 
 {
     private final List<LocalProperty<Symbol>> localProperties;
 
     public PreferredProperties(
             Optional<PartitioningPreferencespartitioningRequirements,
             List<? extends LocalProperty<Symbol>> localProperties)
     {
         requireNonNull(partitioningRequirements"partitioningRequirements is null");
         requireNonNull(localProperties"localProperties is null");
 
         this. = partitioningRequirements;
         this. = ImmutableList.copyOf(localProperties);
     }
 
     public static PreferredProperties any()
     {
         return new PreferredProperties(Optional.empty(), ImmutableList.of());
     }
 
     public static PreferredProperties unpartitioned()
     {
         return new PreferredProperties(Optional.of(PartitioningPreferences.unpartitioned()), ImmutableList.of());
     }
 
     public static PreferredProperties partitioned(Set<Symbolcolumns)
     {
         return new PreferredProperties(Optional.of(PartitioningPreferences.partitioned(columns)), ImmutableList.of());
     }
 
     public static PreferredProperties partitioned()
     {
         return new PreferredProperties(Optional.of(PartitioningPreferences.partitioned()), ImmutableList.of());
     }
 
     public static PreferredProperties hashPartitioned(List<Symbolcolumns)
     {
         return new PreferredProperties(Optional.of(PartitioningPreferences.hashPartitioned(columns)), ImmutableList.of());
     }
 
     public static PreferredProperties hashPartitionedWithLocal(List<SymbolcolumnsList<? extends LocalProperty<Symbol>> localProperties)
     {
         return new PreferredProperties(Optional.of(PartitioningPreferences.hashPartitioned(columns)), ImmutableList.copyOf(localProperties));
     }
 
     public static PreferredProperties partitionedWithLocal(Set<SymbolcolumnsList<? extends LocalProperty<Symbol>> localProperties)
     {
         return new PreferredProperties(Optional.of(PartitioningPreferences.partitioned(columns)), ImmutableList.copyOf(localProperties));
     }
 
     public static PreferredProperties unpartitionedWithLocal(List<? extends LocalProperty<Symbol>> localProperties)
     {
         return new PreferredProperties(Optional.of(PartitioningPreferences.unpartitioned()), ImmutableList.copyOf(localProperties));
     }
 
     public static PreferredProperties local(List<? extends LocalProperty<Symbol>> localProperties)
     {
         return new PreferredProperties(Optional.empty(), ImmutableList.copyOf(localProperties));
     }
 
     {
         return ;
     }
 
    {
        return ;
    }

    

Parameters:
preferred PreferredProperties in terms of the parent symbols
translations output to input translations for symbols that can be translated
Returns:
translated PreferredProperties
    public static PreferredProperties translate(PreferredProperties preferredMap<SymbolSymboltranslations)
    {
        List<LocalProperty<Symbol>> localProperties = LocalProperties.translate(preferred.getLocalProperties(), column -> Optional.ofNullable(translations.get(column)));
        if (preferred.getPartitioningProperties().isPresent()) {
            PartitioningPreferences partitioning = preferred.getPartitioningProperties().get();
            if (partitioning.isHashPartitioned()) {
                List<SymbolhashingSymbols = partitioning.getHashPartitioningColumns().get();
                if (translations.keySet().containsAll(hashingSymbols)) {
                    List<Symboltranslated = partitioning.getHashPartitioningColumns().get().stream()
                            .map(translations::get)
                            .collect(toList());
                    return hashPartitionedWithLocal(translatedlocalProperties);
                }
            }
            if (partitioning.isPartitioned()) {
                // check if we can satisfy any partitioning requirements
                Set<Symbolsymbols = partitioning.getPartitioningColumns().get();
                Set<Symboltranslated = symbols.stream()
                        .filter(symbol -> translations.keySet().contains(symbol))
                        .map(translations::get)
                        .collect(toSet());
                if (!translated.isEmpty()) {
                    return partitionedWithLocal(translatedlocalProperties);
                }
            }
            else {
                return unpartitionedWithLocal(localProperties);
            }
        }
        return local(localProperties);
    }
    public static PreferredProperties derivePreferences(
            PreferredProperties parentProperties,
            Set<SymbolpartitioningColumns,
            List<LocalProperty<Symbol>> localProperties)
    {
        return derivePreferences(parentPropertiespartitioningColumns, Optional.empty(), localProperties);
    }

    
Derive current node's preferred properties based on parent's preferences

Parameters:
parentProperties Parent's preferences (translated)
partitioningColumns partitioning columns of current node
hashingColumns hashing columns of current node
localProperties local properties of current node
Returns:
PreferredProperties for current node
    public static PreferredProperties derivePreferences(
            PreferredProperties parentProperties,
            Set<SymbolpartitioningColumns,
            Optional<List<Symbol>> hashingColumns,
            List<LocalProperty<Symbol>> localProperties)
    {
        if (hashingColumns.isPresent()) {
            checkState(partitioningColumns.equals(ImmutableSet.copyOf(hashingColumns.get())), "hashingColumns and partitioningColumns must be the same");
        }
        List<LocalProperty<Symbol>> local = ImmutableList.<LocalProperty<Symbol>>builder()
                .addAll(localProperties)
                .addAll(parentProperties.getLocalProperties())
                .build();
        // Check we need to be hash partitioned
        if (hashingColumns.isPresent()) {
            return hashPartitionedWithLocal(hashingColumns.get(), local);
        }
        if (parentProperties.getPartitioningProperties().isPresent()) {
            PartitioningPreferences parentPartitioning = parentProperties.getPartitioningProperties().get();
            // If parent's hash partitioning satisfies our partitioning, use parent's hash partitioning
            if (parentPartitioning.isHashPartitioned() && partitioningColumns.equals(ImmutableSet.copyOf(parentPartitioning.getHashPartitioningColumns().get()))) {
                List<SymbolhashingSymbols = parentPartitioning.getHashPartitioningColumns().get();
                return hashPartitionedWithLocal(hashingSymbolslocal);
            }
            // if the child plan is partitioned by the common columns between our requirements and our parent's, it can satisfy both in one shot
            if (parentPartitioning.isPartitioned()) {
                Set<SymbolparentPartitioningColumns = parentPartitioning.getPartitioningColumns().get();
                Set<Symbolcommon = Sets.intersection(partitioningColumnsparentPartitioningColumns);
                // If we find common partitioning columns, use them, else use child's partitioning columns
                if (!common.isEmpty()) {
                    return partitionedWithLocal(commonlocal);
                }
                return partitionedWithLocal(partitioningColumnslocal);
            }
        }
        return partitionedWithLocal(partitioningColumnslocal);
    }
    public static class PartitioningPreferences
    {
        private final boolean partitioned;
        private final Optional<Set<Symbol>> partitioningColumns;
        private final Optional<List<Symbol>> hashingColumns;
        private PartitioningPreferences(boolean partitionedOptional<Set<Symbol>> partitioningColumnsOptional<List<Symbol>> hashingColumns)
        {
            requireNonNull(partitioningColumns"partitioningColumns is null");
            checkArgument(partitioned || (partitioningColumns.isPresent() && partitioningColumns.get().isEmpty()), "unpartitioned implies partitioned on the empty set");
            if (hashingColumns.isPresent()) {
                checkArgument(partitioningColumns.isPresent(), "partitioningColumns not present");
                checkArgument(partitioningColumns.get().containsAll(hashingColumns.get()), "partitioningColumns does not include hashingColumns");
            }
            this. = partitioned;
            this. = partitioningColumns.map(ImmutableSet::copyOf);
            this. = hashingColumns.map(ImmutableList::copyOf);
        }
        public static PartitioningPreferences unpartitioned()
        {
            return new PartitioningPreferences(false, Optional.<Set<Symbol>>of(ImmutableSet.of()), Optional.empty());
        }
        public static PartitioningPreferences partitioned(Set<Symbolcolumns)
        {
            return new PartitioningPreferences(true, Optional.of(columns), Optional.empty());
        }
        public static PartitioningPreferences partitioned()
        {
            return new PartitioningPreferences(true, Optional.empty(), Optional.empty());
        }
        public static PartitioningPreferences hashPartitioned(List<Symbolcolumns)
        {
            return new PartitioningPreferences(true, Optional.of(ImmutableSet.copyOf(columns)), Optional.of(ImmutableList.copyOf(columns)));
        }
        public boolean isPartitioned()
        {
            return ;
        }
        public Optional<Set<Symbol>> getPartitioningColumns()
        {
            return ;
        }
        public boolean isHashPartitioned()
        {
            return .isPresent();
        }
        public Optional<List<Symbol>> getHashPartitioningColumns()
        {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X