@@ -0,0 +1,3213 @@
+/*%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.facebook.presto.sql.planner;%0A%0Aimport com.facebook.presto.spi.block.SortOrder;%0Aimport com.fasterxml.jackson.annotation.JsonCreator;%0Aimport com.fasterxml.jackson.annotation.JsonProperty;%0Aimport com.google.common.collect.ImmutableList;%0Aimport com.google.common.collect.ImmutableMap;%0Aimport com.google.common.collect.ImmutableSet;%0A%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.Objects;%0A%0Aimport static com.google.common.base.MoreObjects.toStringHelper;%0Aimport static com.google.common.base.Preconditions.checkArgument;%0Aimport static com.google.common.collect.ImmutableList.toImmutableList;%0Aimport static java.lang.String.format;%0Aimport static java.util.Objects.requireNonNull;%0A%0Apublic class OrderingScheme%0A%7B%0A    private final List%3CSymbol%3E orderBy;%0A    private final Map%3CSymbol, SortOrder%3E orderings;%0A%0A    @JsonCreator%0A    public OrderingScheme(@JsonProperty(%22orderBy%22) List%3CSymbol%3E orderBy, @JsonProperty(%22orderings%22) Map%3CSymbol, SortOrder%3E orderings)%0A    %7B%0A        requireNonNull(orderBy, %22orderBy is null%22);%0A        requireNonNull(orderings, %22orderings is null%22);%0A        checkArgument(!orderBy.isEmpty(), %22orderBy is empty%22);%0A        checkArgument(orderings.keySet().equals(ImmutableSet.copyOf(orderBy)), %22orderBy keys and orderings don't match%22);%0A        this.orderBy = ImmutableList.copyOf(orderBy);%0A        this.orderings = ImmutableMap.copyOf(orderings);%0A    %7D%0A%0A    @JsonProperty%0A    public List%3CSymbol%3E getOrderBy()%0A    %7B%0A        return orderBy;%0A    %7D%0A%0A    @JsonProperty%0A    public Map%3CSymbol, SortOrder%3E getOrderings()%0A    %7B%0A        return orderings;%0A    %7D%0A%0A    public List%3CSortOrder%3E getOrderingList()%0A    %7B%0A        return orderBy.stream()%0A                .map(orderings::get)%0A                .collect(toImmutableList());%0A    %7D%0A%0A    public SortOrder getOrdering(Symbol symbol)%0A    %7B%0A        checkArgument(orderings.containsKey(symbol), format(%22No ordering for symbol: %25s%22, symbol));%0A        return orderings.get(symbol);%0A    %7D%0A%0A    @Override%0A    public boolean equals(Object o)%0A    %7B%0A        if (this == o) %7B%0A            return true;%0A        %7D%0A        if (o == null %7C%7C getClass() != o.getClass()) %7B%0A            return false;%0A        %7D%0A        OrderingScheme that = (OrderingScheme) o;%0A        return Objects.equals(orderBy, that.orderBy) &&%0A                Objects.equals(orderings, that.orderings);%0A    %7D%0A%0A    @Override%0A    public int hashCode()%0A    %7B%0A        return Objects.hash(orderBy, orderings);%0A    %7D%0A%0A    @Override%0A    public String toString()%0A    %7B%0A        return toStringHelper(this)%0A                .add(%22orderBy%22, orderBy)%0A                .add(%22orderings%22, orderings)%0A                .toString();%0A    %7D%0A%7D%0A

Introduce OrderingScheme