You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2020/08/04 05:49:07 UTC
[shardingsphere] branch master updated: Add generic for comparable
(#6609)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 9b5a3a0 Add generic for comparable (#6609)
9b5a3a0 is described below
commit 9b5a3a0dc92402a437fd7276ad57a214fdd92da8
Author: Liang Zhang <te...@163.com>
AuthorDate: Tue Aug 4 13:48:49 2020 +0800
Add generic for comparable (#6609)
* Add generic for comparable
* Fix test case
---
.../dql/groupby/aggregation/ComparableAggregationUnit.java | 2 +-
.../sharding/merge/dql/orderby/CompareUtil.java | 2 +-
.../route/engine/condition/generator/ConditionValue.java | 14 +++++++-------
.../impl/ConditionValueBetweenOperatorGenerator.java | 4 ++--
.../impl/ConditionValueCompareOperatorGenerator.java | 11 ++++++-----
.../generator/impl/ConditionValueInOperatorGenerator.java | 4 ++--
6 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/aggregation/ComparableAggregationUnit.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/aggregation/ComparableAggregationUnit.java
index c509d10..2262a2a 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/aggregation/ComparableAggregationUnit.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dql/groupby/aggregation/ComparableAggregationUnit.java
@@ -31,7 +31,7 @@ public final class ComparableAggregationUnit implements AggregationUnit {
private Comparable<?> result;
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void merge(final List<Comparable<?>> values) {
if (null == values || null == values.get(0)) {
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/CompareUtil.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/CompareUtil.java
index fb56464..e3caac1 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/CompareUtil.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dql/orderby/CompareUtil.java
@@ -37,7 +37,7 @@ public final class CompareUtil {
* @param caseSensitive case sensitive
* @return compare result
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "rawtypes"})
public static int compareTo(final Comparable thisValue, final Comparable otherValue, final OrderDirection orderDirection, final OrderDirection nullOrderDirection, final boolean caseSensitive) {
if (null == thisValue && null == otherValue) {
return 0;
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/ConditionValue.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/ConditionValue.java
index 912deae..6677acc 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/ConditionValue.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/ConditionValue.java
@@ -30,13 +30,13 @@ import java.util.Optional;
*/
public final class ConditionValue {
- private final Comparable value;
+ private final Comparable<?> value;
public ConditionValue(final ExpressionSegment expressionSegment, final List<Object> parameters) {
value = getValue(expressionSegment, parameters);
}
- private Comparable getValue(final ExpressionSegment expressionSegment, final List<Object> parameters) {
+ private Comparable<?> getValue(final ExpressionSegment expressionSegment, final List<Object> parameters) {
if (expressionSegment instanceof ParameterMarkerExpressionSegment) {
return getValue((ParameterMarkerExpressionSegment) expressionSegment, parameters);
}
@@ -46,16 +46,16 @@ public final class ConditionValue {
return null;
}
- private Comparable getValue(final ParameterMarkerExpressionSegment expressionSegment, final List<Object> parameters) {
+ private Comparable<?> getValue(final ParameterMarkerExpressionSegment expressionSegment, final List<Object> parameters) {
Object result = parameters.get(expressionSegment.getParameterMarkerIndex());
Preconditions.checkArgument(result instanceof Comparable, "Sharding value must implements Comparable.");
- return (Comparable) result;
+ return (Comparable<?>) result;
}
- private Comparable getValue(final LiteralExpressionSegment expressionSegment) {
+ private Comparable<?> getValue(final LiteralExpressionSegment expressionSegment) {
Object result = expressionSegment.getLiterals();
Preconditions.checkArgument(result instanceof Comparable, "Sharding value must implements Comparable.");
- return (Comparable) result;
+ return (Comparable<?>) result;
}
/**
@@ -63,7 +63,7 @@ public final class ConditionValue {
*
* @return condition value
*/
- public Optional<Comparable> getValue() {
+ public Optional<Comparable<?>> getValue() {
return Optional.ofNullable(value);
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java
index 424f6a1..cb25672 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java
@@ -39,8 +39,8 @@ public final class ConditionValueBetweenOperatorGenerator implements ConditionVa
@Override
public Optional<RouteValue> generate(final PredicateBetweenRightValue predicateRightValue, final Column column, final List<Object> parameters) {
- Optional<Comparable> betweenRouteValue = new ConditionValue(predicateRightValue.getBetweenExpression(), parameters).getValue();
- Optional<Comparable> andRouteValue = new ConditionValue(predicateRightValue.getAndExpression(), parameters).getValue();
+ Optional<Comparable<?>> betweenRouteValue = new ConditionValue(predicateRightValue.getBetweenExpression(), parameters).getValue();
+ Optional<Comparable<?>> andRouteValue = new ConditionValue(predicateRightValue.getAndExpression(), parameters).getValue();
if (betweenRouteValue.isPresent() && andRouteValue.isPresent()) {
return Optional.of(new RangeRouteValue<>(column.getName(), column.getTableName(), SafeRangeOperationUtils.safeClosed(betweenRouteValue.get(), andRouteValue.get())));
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java
index b963556..5ae3d50 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java
@@ -19,17 +19,18 @@ package org.apache.shardingsphere.sharding.route.engine.condition.generator.impl
import com.google.common.collect.Lists;
import com.google.common.collect.Range;
-import org.apache.shardingsphere.sharding.strategy.value.ListRouteValue;
-import org.apache.shardingsphere.sharding.strategy.value.RangeRouteValue;
-import org.apache.shardingsphere.sharding.strategy.value.RouteValue;
import org.apache.shardingsphere.sharding.route.engine.condition.Column;
import org.apache.shardingsphere.sharding.route.engine.condition.ExpressionConditionUtils;
import org.apache.shardingsphere.sharding.route.engine.condition.generator.ConditionValue;
import org.apache.shardingsphere.sharding.route.engine.condition.generator.ConditionValueGenerator;
import org.apache.shardingsphere.sharding.route.spi.SPITimeService;
+import org.apache.shardingsphere.sharding.strategy.value.ListRouteValue;
+import org.apache.shardingsphere.sharding.strategy.value.RangeRouteValue;
+import org.apache.shardingsphere.sharding.strategy.value.RouteValue;
import org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.value.PredicateCompareRightValue;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Optional;
@@ -56,7 +57,7 @@ public final class ConditionValueCompareOperatorGenerator implements ConditionVa
if (!isSupportedOperator(operator)) {
return Optional.empty();
}
- Optional<Comparable> routeValue = new ConditionValue(predicateRightValue.getExpression(), parameters).getValue();
+ Optional<Comparable<?>> routeValue = new ConditionValue(predicateRightValue.getExpression(), parameters).getValue();
if (routeValue.isPresent()) {
return generate(routeValue.get(), column, operator);
}
@@ -66,7 +67,7 @@ public final class ConditionValueCompareOperatorGenerator implements ConditionVa
return Optional.empty();
}
- private Optional<RouteValue> generate(final Comparable comparable, final Column column, final String operator) {
+ private Optional<RouteValue> generate(final Comparable<?> comparable, final Column column, final String operator) {
String columnName = column.getName();
String tableName = column.getTableName();
switch (operator) {
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java
index 7b568ce..aabecfd 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java
@@ -38,10 +38,10 @@ public final class ConditionValueInOperatorGenerator implements ConditionValueGe
@Override
public Optional<RouteValue> generate(final PredicateInRightValue predicateRightValue, final Column column, final List<Object> parameters) {
- List<Comparable> routeValues = new LinkedList<>();
+ List<Comparable<?>> routeValues = new LinkedList<>();
SPITimeService timeService = new SPITimeService();
for (ExpressionSegment each : predicateRightValue.getSqlExpressions()) {
- Optional<Comparable> routeValue = new ConditionValue(each, parameters).getValue();
+ Optional<Comparable<?>> routeValue = new ConditionValue(each, parameters).getValue();
if (routeValue.isPresent()) {
routeValues.add(routeValue.get());
continue;