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.facebook.presto.util.ImmutableCollectors.toImmutableSet;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.collect.Iterables.transform;
 import static java.util.Objects.requireNonNull;
 
 {
     private final Optional<Set<Symbol>> partitioningColumns// if missing => partitioned with some unknown scheme
     private final Optional<List<Symbol>> hashingColumns// if present => hash partitioned on the given columns. partitioningColumns and hashingColumns must contain the same columns
     private final boolean partitioned// true if executing on multiple instances; false if executing on a single instance, which implies partitioned on the empty set of columns
     private final boolean coordinatorOnly;
     private final List<LocalProperty<Symbol>> localProperties;
     private final Map<SymbolObjectconstants;
 
     private ActualProperties(
             Optional<Set<Symbol>> partitioningColumns,
             Optional<List<Symbol>> hashingColumns,
             List<? extends LocalProperty<Symbol>> localProperties,
             boolean partitioned,
             boolean coordinatorOnly,
             Map<SymbolObjectconstants)
     {
         requireNonNull(partitioningColumns"partitioningColumns is null");
         requireNonNull(hashingColumns"hashingColumns is null");
         checkArgument(!hashingColumns.isPresent() || hashingColumns.map(ImmutableSet::copyOf).equals(partitioningColumns), "hashColumns must contain the columns as partitioningColumns if present");
         checkArgument(partitioned || partitioningColumns.isPresent() && partitioningColumns.get().isEmpty(), "partitioningColumns must contain the empty set when unpartitioned");
         checkArgument(!coordinatorOnly || !partitioned"must not be partitioned when running as coordinatorOnly");
         requireNonNull(localProperties"localProperties is null");
         requireNonNull(constants"constants is null");
 
         this. = partitioningColumns.map(ImmutableSet::copyOf);
         this. = hashingColumns.map(ImmutableList::copyOf);
         this. = partitioned;
         this. = coordinatorOnly;
 
         // There is some overlap between the localProperties (ConstantProperty) and constants fields.
         // Let's normalize both of those structures here so that they are consistent with each other
         Set<SymbolpropertyConstants = LocalProperties.extractLeadingConstants(localProperties);
         localProperties = LocalProperties.stripLeadingConstants(localProperties);
 
         Map<SymbolObjectupdatedConstants = new HashMap<>();
         propertyConstants.stream()
                 .forEach(symbol -> updatedConstants.put(symbolnew Object()));
         updatedConstants.putAll(constants);
 
         List<LocalProperty<Symbol>> updatedLocalProperties = LocalProperties.normalizeAndPrune(ImmutableList.<LocalProperty<Symbol>>builder()
                 .addAll(transform(updatedConstants.keySet(), ConstantProperty::new))
                 .addAll(localProperties)
                 .build());
 
         this. = ImmutableList.copyOf(updatedLocalProperties);
         this. = ImmutableMap.copyOf(updatedConstants);
     }
 
     public static ActualProperties unpartitioned()
     {
         return new ActualProperties(Optional.of(ImmutableSet.of()), Optional.empty(), ImmutableList.of(), falsefalse, ImmutableMap.of());
     }
 
     public static ActualProperties hashPartitioned(List<Symbolcolumns)
     {
         return new ActualProperties(
                 Optional.of(ImmutableSet.copyOf(columns)),
                 Optional.of(ImmutableList.copyOf(columns)),
                 ImmutableList.of(),
                 true,
                 false,
                 ImmutableMap.of());
    }
    public static ActualProperties partitioned()
    {
        return new ActualProperties(Optional.<Set<Symbol>>empty(), Optional.<List<Symbol>>empty(), ImmutableList.of(), truefalse, ImmutableMap.of());
    }
    public static ActualProperties partitioned(Collection<Symbolcolumns)
    {
        return new ActualProperties(Optional.<Set<Symbol>>of(ImmutableSet.copyOf(columns)), Optional.<List<Symbol>>empty(), ImmutableList.of(), truefalse, ImmutableMap.of());
    }
    public static ActualProperties partitioned(ActualProperties other)
    {
        return new ActualProperties(other.partitioningColumnsother.hashingColumns, ImmutableList.of(), other.partitionedfalse, ImmutableMap.of());
    }
    public boolean isCoordinatorOnly()
    {
        return ;
    }
    public boolean isPartitioned()
    {
        return ;
    }
    public boolean isPartitionedOn(Collection<Symbolcolumns)
    {
        // partitioned on (k_1, k_2, ..., k_n) => partitioned on (k_1, k_2, ..., k_n, k_n+1, ...)
        // can safely ignore all constant columns when comparing partition properties
        return .isPresent() && ImmutableSet.copyOf(columns).containsAll(getPartitioningColumnsWithoutConstants().get());
    }

    

Returns:
true if all the data will effectively land in a single stream
    public boolean isSingleStream()
    {
        Optional<Set<Symbol>> partitioningWithoutConstants = getPartitioningColumnsWithoutConstants();
        return partitioningWithoutConstants.isPresent() && partitioningWithoutConstants.get().isEmpty();
    }

    

Returns:
true if repartitioning on the keys will yield some difference
    public boolean isRepartitionEffective(Collection<Symbolkeys)
    {
        Optional<Set<Symbol>> partitioningWithoutConstants = getPartitioningColumnsWithoutConstants();
        if (!partitioningWithoutConstants.isPresent()) {
            return true;
        }
        Set<SymbolkeysWithoutConstants = keys.stream()
                .filter(symbol -> !.containsKey(symbol))
                .collect(toImmutableSet());
        return !partitioningWithoutConstants.get().equals(keysWithoutConstants);
    }
    public boolean hasKnownPartitioningScheme()
    {
        return .isPresent();
    }
    {
        // can safely ignore all constant columns when comparing partition properties
    }
    {
        return .map(symbols -> {
                    return symbols.stream()
                            .filter(symbol -> !.containsKey(symbol))
                            .collect(toImmutableSet());
                }
        );
    }
    public boolean isHashPartitionedOn(List<Symbolcolumns)
    {
        return .isPresent() && .get().equals(columns);
    }
    public boolean isHashPartitioned()
    {
        return .isPresent();
    }
    {
        return ;
    }
    public Map<SymbolObjectgetConstants()
    {
        return ;
    }
    {
        return ;
    }
    public static Builder builder()
    {
        return new Builder();
    }
    public static class Builder
    {
        private Optional<Set<Symbol>> partitioningColumns// if missing => partitioned with some unknown scheme
        private Optional<List<Symbol>> hashingColumns// if present => hash partitioned on the given columns. partitioningColumns and hashingColumns must contain the same columns
        private boolean partitioned// true if executing on multiple instances; false if executing on a single instance, which implies partitioned on the empty set of columns
        private boolean coordinatorOnly;
        private List<LocalProperty<Symbol>> localProperties = ImmutableList.of();
        private Map<SymbolObjectconstants = ImmutableMap.of();
        public Builder unpartitioned()
        {
             = Optional.of(ImmutableSet.of());
             = Optional.empty();
             = false;
            return this;
        }
        public Builder partitioned(ActualProperties other)
        {
             = other.partitioningColumns;
             = other.hashingColumns;
             = other.partitioned;
            return this;
        }
        public Builder partitioned()
        {
             = Optional.empty();
             = Optional.empty();
             = true;
            return this;
        }
        public Builder coordinatorOnly(ActualProperties other)
        {
             = other.coordinatorOnly;
            return this;
        }
        public Builder partitioned(Set<Symbolcolumns)
        {
             = Optional.of(ImmutableSet.copyOf(columns));
             = Optional.empty();
             = true;
            return this;
        }
        public Builder hashPartitioned(List<Symbolcolumns)
        {
             = Optional.of(ImmutableSet.copyOf(columns));
             = Optional.of(ImmutableList.copyOf(columns));
             = true;
            return this;
        }
        public Builder local(List<? extends LocalProperty<Symbol>> localProperties)
        {
            this. = ImmutableList.copyOf(localProperties);
            return this;
        }
        public Builder local(ActualProperties other)
        {
            this. = ImmutableList.copyOf(other.localProperties);
            return this;
        }
        public Builder constants(Map<SymbolObjectconstants)
        {
            this. = ImmutableMap.copyOf(constants);
            return this;
        }
        public Builder constants(ActualProperties other)
        {
            this. = ImmutableMap.copyOf(other.constants);
            return this;
        }
        public ActualProperties build()
        {
        }
    }
    @Override
    public String toString()
    {
        return MoreObjects.toStringHelper(this)
                .add("partitioningColumns")
                .add("hashingColumns")
                .add("partitioned")
                .add("coordinatorOnly")
                .add("localProperties")
                .add("constants")
                .toString();
    }
    @Override
    public int hashCode()
    {
    }
    @Override
    public boolean equals(Object obj)
    {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        final ActualProperties other = (ActualPropertiesobj;
        return Objects.equals(this.other.partitioningColumns)
                && Objects.equals(this.other.hashingColumns)
                && Objects.equals(this.other.partitioned)
                && Objects.equals(this.other.coordinatorOnly)
                && Objects.equals(this.other.localProperties)
                && Objects.equals(this..keySet(), other.constants.keySet());
    }
New to GrepCode? Check out our FAQ X