You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/05/24 02:54:22 UTC

[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #5770: fix bug for ClassCastException when execute range query in numeric type

strongduanmu commented on a change in pull request #5770:
URL: https://github.com/apache/shardingsphere/pull/5770#discussion_r429594269



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/util/SafeRangeOperationUtils.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.shardingsphere.sql.parser.sql.util;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Range;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.SneakyThrows;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Safe range operation utility class.
+ */
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+public final class SafeRangeOperationUtils {
+
+    /**
+     * Execute intersection method by safe mode.
+     *
+     * @param range          range
+     * @param connectedRange connected range

Review comment:
       > What's mean of variable name `connectedRange`?
   
   In order to consistent with the intersection method in Guava Range. The following is the definition of the intersection method:
   
   ```java
   /**
   * Returns the maximal range {@linkplain #encloses enclosed} by both this range and {@code
   * connectedRange}, if such a range exists.
   *
   * <p>For example, the intersection of {@code [1..5]} and {@code (3..7)} is {@code (3..5]}. The
   * resulting range may be empty; for example, {@code [1..5)} intersected with {@code [5..7)}
   * yields the empty range {@code [5..5)}.
   *
   * <p>The intersection exists if and only if the two ranges are {@linkplain #isConnected
   * connected}.
   *
   * <p>The intersection operation is commutative, associative and idempotent, and its identity
   * element is {@link Range#all}).
   *
   * @throws IllegalArgumentException if {@code isConnected(connectedRange)} is {@code false}
   */
   public Range<C> intersection(Range<C> connectedRange) {
       int lowerCmp = lowerBound.compareTo(connectedRange.lowerBound);
       int upperCmp = upperBound.compareTo(connectedRange.upperBound);
       if (lowerCmp >= 0 && upperCmp <= 0) {
           return this;
       } else if (lowerCmp <= 0 && upperCmp >= 0) {
           return connectedRange;
       } else {
           Cut<C> newLower = (lowerCmp >= 0) ? lowerBound : connectedRange.lowerBound;
           Cut<C> newUpper = (upperCmp <= 0) ? upperBound : connectedRange.upperBound;
           return create(newLower, newUpper);
       }
   }
   ```




----------------------------------------------------------------
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:
users@infra.apache.org