morningman commented on a change in pull request #2828: [Temp Partition] Support add/drop/replace temp partitions URL: https://github.com/apache/incubator-doris/pull/2828#discussion_r386069567
########## File path: fe/src/main/java/org/apache/doris/common/util/RangeUtils.java ########## @@ -0,0 +1,210 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 org.apache.doris.common.util; + +import org.apache.doris.catalog.PartitionKey; +import org.apache.doris.common.DdlException; + +import com.google.common.collect.BoundType; +import com.google.common.collect.Range; +import com.google.common.collect.RangeMap; +import com.google.common.collect.TreeRangeMap; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; + +public class RangeUtils { + + public static final Comparator<Map.Entry<Long, Range<PartitionKey>>> RANGE_MAP_ENTRY_COMPARATOR = + Comparator.comparing(o -> o.getValue().lowerEndpoint()); + + public static final Comparator<Range<PartitionKey>> RANGE_COMPARATOR = + Comparator.comparing(o -> o.lowerEndpoint()); + + public static void checkRangeIntersect(Range<PartitionKey> range1, Range<PartitionKey> range2) throws DdlException { + if (range2.isConnected(range1)) { + if (!range2.intersection(range1).isEmpty()) { + throw new DdlException("Range " + range1 + " is intersected with range: " + range2); + } + } + } + + /* + * Pass only if the 2 range lists are exactly same + * What is "exactly same"? + * 1. {[0, 10), [10, 20)} exactly same as {[0, 20)} + * 2. {[0, 10), [15, 20)} exactly same as {[0, 10), [15, 18), [18, 20)} + * 3. {[0, 10), [15, 20)} exactly same as {[0, 10), [15, 20)} + * 4. {[0, 10), [15, 20)} NOT exactly same as {[0, 20)} + * + * Here I will use an example to explain the algorithm: + * list1: {[0, 10), [15, 20)} + * list2: {[0, 10), [15, 18), [18, 20)} + * + * 1. sort 2 lists first (the above 2 lists are already sorted) + * 2. Begin to compare ranges from index 0: [0, 10) and [0, 10) + * 2.1 lower bounds (0 and 0) are equal. + * 2.2 upper bounds (10 and 10) are equal. + * 3. Begin to compare next 2 ranges [15, 20) and [15, 18) + * 3.1 lower bounds (15 and 15) are equal. + * 3.2 upper bounds (20 and 18) are not equal. and 20 > 18 + * 3.3 Split range [15, 20) to [15, 18) and [18, 20) + * 4. Begin to compare next 2 ranges [18, 20) and [18, 20), the first [18, 20) is the splitted range + * 4.1 lower bounds (18 and 18) are equal. + * 4.2 upper bounds (20 and 20) are equal. + * 5. Not more next ranges, so 2 lists are equal. + */ + public static void checkRangeListsMatch(List<Range<PartitionKey>> list1, List<Range<PartitionKey>> list2) throws DdlException { Review comment: An exception can bring some detail error msgs. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org