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 2021/06/16 08:14:27 UTC
[shardingsphere] branch master updated: fix column index out of
range exception when execute subquery select (#10833)
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 fc3c590 fix column index out of range exception when execute subquery select (#10833)
fc3c590 is described below
commit fc3c59030d72cd98eea54d9fbbf6487102f16d3a
Author: Zhengqiang Duan <st...@gmail.com>
AuthorDate: Wed Jun 16 16:13:38 2021 +0800
fix column index out of range exception when execute subquery select (#10833)
* fix column index out of range exception when execute subquery select
* fix checkstyle
---
.../impl/WhereClauseShardingConditionEngine.java | 12 +-
.../ConditionValueBetweenOperatorGenerator.java | 4 +-
.../dml/ShardingDMLStatementValidator.java | 6 +-
...ConditionValueBetweenOperatorGeneratorTest.java | 6 +-
.../statement/dml/SelectStatementContext.java | 10 +-
.../resultset/ShardingSphereResultSetMetaData.java | 3 +-
.../communication/DatabaseCommunicationEngine.java | 5 +-
.../parser/sql/common/util/ExpressionBuilder.java | 2 +-
.../sql/parser/sql/common/util/SQLUtil.java | 4 +-
...tionUtils.java => SafeNumberOperationUtil.java} | 2 +-
.../sql/common/util/SubqueryExtractUtil.java | 106 ++++++++++++++++
.../parser/sql/common/util/WhereExtractUtil.java | 72 +++++++++++
.../sql/common/util/WhereSegmentExtractUtils.java | 135 ---------------------
...sTest.java => SafeNumberOperationUtilTest.java} | 62 +++++-----
14 files changed, 234 insertions(+), 195 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/WhereClauseShardingConditionEngine.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/WhereClauseShardingConditionEngine.java
index b7d8392..79747d1 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/WhereClauseShardingConditionEngine.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/WhereClauseShardingConditionEngine.java
@@ -40,8 +40,8 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.Whe
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import org.apache.shardingsphere.sql.parser.sql.common.util.ColumnExtractor;
import org.apache.shardingsphere.sql.parser.sql.common.util.ExpressionBuilder;
-import org.apache.shardingsphere.sql.parser.sql.common.util.SafeNumberOperationUtils;
-import org.apache.shardingsphere.sql.parser.sql.common.util.WhereSegmentExtractUtils;
+import org.apache.shardingsphere.sql.parser.sql.common.util.SafeNumberOperationUtil;
+import org.apache.shardingsphere.sql.parser.sql.common.util.WhereExtractUtil;
import java.util.ArrayList;
import java.util.Collection;
@@ -71,7 +71,7 @@ public final class WhereClauseShardingConditionEngine implements ShardingConditi
List<ShardingCondition> result = new ArrayList<>();
((WhereAvailable) sqlStatementContext).getWhere().ifPresent(segment -> result.addAll(createShardingConditions(sqlStatementContext, segment.getExpr(), parameters)));
Collection<WhereSegment> joinWhereSegments = sqlStatementContext.getSqlStatement() instanceof SelectStatement
- ? WhereSegmentExtractUtils.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()) : Collections.emptyList();
+ ? WhereExtractUtil.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()) : Collections.emptyList();
for (WhereSegment each : joinWhereSegments) {
Collection<ShardingCondition> joinShardingConditions = createShardingConditions(sqlStatementContext, each.getExpr(), parameters);
if (!result.containsAll(joinShardingConditions)) {
@@ -79,7 +79,7 @@ public final class WhereClauseShardingConditionEngine implements ShardingConditi
}
}
Collection<WhereSegment> subqueryWhereSegments = sqlStatementContext.getSqlStatement() instanceof SelectStatement
- ? WhereSegmentExtractUtils.getSubqueryWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()) : Collections.emptyList();
+ ? WhereExtractUtil.getSubqueryWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement()) : Collections.emptyList();
for (WhereSegment each : subqueryWhereSegments) {
Collection<ShardingCondition> subqueryShardingConditions = createShardingConditions(sqlStatementContext, each.getExpr(), parameters);
if (!result.containsAll(subqueryShardingConditions)) {
@@ -181,13 +181,13 @@ public final class WhereClauseShardingConditionEngine implements ShardingConditi
}
private Range<Comparable<?>> mergeRangeShardingValues(final Range<Comparable<?>> value1, final Range<Comparable<?>> value2) {
- return null == value2 ? value1 : SafeNumberOperationUtils.safeIntersection(value1, value2);
+ return null == value2 ? value1 : SafeNumberOperationUtil.safeIntersection(value1, value2);
}
private Collection<Comparable<?>> mergeListAndRangeShardingValues(final Collection<Comparable<?>> listValue, final Range<Comparable<?>> rangeValue) {
Collection<Comparable<?>> result = new LinkedList<>();
for (Comparable<?> each : listValue) {
- if (SafeNumberOperationUtils.safeContains(rangeValue, each)) {
+ if (SafeNumberOperationUtil.safeContains(rangeValue, each)) {
result.add(each);
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java
index f9a93dd..9291df9 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.sharding.route.engine.condition.generator.Condi
import org.apache.shardingsphere.sharding.route.engine.condition.value.RangeShardingConditionValue;
import org.apache.shardingsphere.sharding.route.engine.condition.value.ShardingConditionValue;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BetweenExpression;
-import org.apache.shardingsphere.sql.parser.sql.common.util.SafeNumberOperationUtils;
+import org.apache.shardingsphere.sql.parser.sql.common.util.SafeNumberOperationUtil;
import java.util.Date;
import java.util.List;
@@ -43,7 +43,7 @@ public final class ConditionValueBetweenOperatorGenerator implements ConditionVa
Optional<Comparable<?>> betweenConditionValue = new ConditionValue(predicate.getBetweenExpr(), parameters).getValue();
Optional<Comparable<?>> andConditionValue = new ConditionValue(predicate.getAndExpr(), parameters).getValue();
if (betweenConditionValue.isPresent() && andConditionValue.isPresent()) {
- return Optional.of(new RangeShardingConditionValue<>(column.getName(), column.getTableName(), SafeNumberOperationUtils.safeClosed(betweenConditionValue.get(), andConditionValue.get())));
+ return Optional.of(new RangeShardingConditionValue<>(column.getName(), column.getTableName(), SafeNumberOperationUtil.safeClosed(betweenConditionValue.get(), andConditionValue.get())));
}
Date datetime = RequiredSPIRegistry.getRegisteredService(DatetimeService.class).getDatetime();
if (!betweenConditionValue.isPresent() && ExpressionConditionUtils.isNowExpression(predicate.getBetweenExpr())) {
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDMLStatementValidator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDMLStatementValidator.java
index b7456ab..40874fa 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDMLStatementValidator.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDMLStatementValidator.java
@@ -38,7 +38,7 @@ import org.apache.shardingsphere.sharding.rule.TableRule;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.util.SafeNumberOperationUtils;
+import org.apache.shardingsphere.sql.parser.sql.common.util.SafeNumberOperationUtil;
import java.util.Collection;
import java.util.Collections;
@@ -132,10 +132,10 @@ public abstract class ShardingDMLStatementValidator<T extends SQLStatement> impl
@SuppressWarnings("unchecked")
private boolean isSameValue(final ShardingConditionValue shardingConditionValue1, final ShardingConditionValue shardingConditionValue2) {
if (shardingConditionValue1 instanceof ListShardingConditionValue && shardingConditionValue2 instanceof ListShardingConditionValue) {
- return SafeNumberOperationUtils.safeCollectionEquals(
+ return SafeNumberOperationUtil.safeCollectionEquals(
((ListShardingConditionValue) shardingConditionValue1).getValues(), ((ListShardingConditionValue) shardingConditionValue2).getValues());
} else if (shardingConditionValue1 instanceof RangeShardingConditionValue && shardingConditionValue2 instanceof RangeShardingConditionValue) {
- return SafeNumberOperationUtils.safeRangeEquals(
+ return SafeNumberOperationUtil.safeRangeEquals(
((RangeShardingConditionValue) shardingConditionValue1).getValueRange(), ((RangeShardingConditionValue) shardingConditionValue2).getValueRange());
}
return false;
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGeneratorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGeneratorTest.java
index 1f3499a..0893e69 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGeneratorTest.java
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BetweenE
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.complex.CommonExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.util.SafeNumberOperationUtils;
+import org.apache.shardingsphere.sql.parser.sql.common.util.SafeNumberOperationUtil;
import org.junit.Test;
import java.util.Calendar;
@@ -78,8 +78,8 @@ public final class ConditionValueBetweenOperatorGeneratorTest {
RangeShardingConditionValue<Comparable<?>> rangeShardingConditionValue = (RangeShardingConditionValue<Comparable<?>>) shardingConditionValue.get();
assertThat(rangeShardingConditionValue.getColumnName(), is(column.getName()));
assertThat(rangeShardingConditionValue.getTableName(), is(column.getTableName()));
- assertTrue(SafeNumberOperationUtils.safeContains(rangeShardingConditionValue.getValueRange(), between));
- assertTrue(SafeNumberOperationUtils.safeContains(rangeShardingConditionValue.getValueRange(), and));
+ assertTrue(SafeNumberOperationUtil.safeContains(rangeShardingConditionValue.getValueRange(), between));
+ assertTrue(SafeNumberOperationUtil.safeContains(rangeShardingConditionValue.getValueRange(), and));
}
@Test(expected = ClassCastException.class)
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
index 465ea56..55b02f4 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
@@ -50,7 +50,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.Sub
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtil;
-import org.apache.shardingsphere.sql.parser.sql.common.util.WhereSegmentExtractUtils;
+import org.apache.shardingsphere.sql.parser.sql.common.util.SubqueryExtractUtil;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import org.apache.shardingsphere.sql.parser.sql.dialect.handler.dml.SelectStatementHandler;
@@ -110,13 +110,7 @@ public final class SelectStatementContext extends CommonSQLStatementContext<Sele
}
private boolean containsSubquery() {
- Collection<WhereSegment> subqueryPredicateSegments = WhereSegmentExtractUtils.getSubqueryWhereSegments(getSqlStatement());
- for (WhereSegment each : subqueryPredicateSegments) {
- if (null != each) {
- return true;
- }
- }
- return false;
+ return !SubqueryExtractUtil.getSubquerySegments(getSqlStatement()).isEmpty();
}
private int generateOrderByStartIndex() {
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java
index e73f887..1b36f31 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java
@@ -113,7 +113,8 @@ public final class ShardingSphereResultSetMetaData extends WrapperAdapter implem
}
private boolean hasSelectExpandProjections() {
- return sqlStatementContext instanceof SelectStatementContext && !((SelectStatementContext) sqlStatementContext).getProjectionsContext().getExpandProjections().isEmpty();
+ return sqlStatementContext instanceof SelectStatementContext && !((SelectStatementContext) sqlStatementContext).getProjectionsContext().getExpandProjections().isEmpty()
+ && !((SelectStatementContext) sqlStatementContext).isContainsSubquery();
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
index c5ec642..2f1a058 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.context.kernel.KernelProcessor;
+import org.apache.shardingsphere.infra.context.metadata.refresher.MetadataRefreshEngine;
import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
@@ -30,7 +31,6 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.JDBCDriv
import org.apache.shardingsphere.infra.merge.MergeEngine;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.context.metadata.refresher.MetadataRefreshEngine;
import org.apache.shardingsphere.infra.rule.type.DataNodeContainedRule;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -131,7 +131,8 @@ public final class DatabaseCommunicationEngine {
}
private boolean hasSelectExpandProjections(final SQLStatementContext<?> sqlStatementContext) {
- return sqlStatementContext instanceof SelectStatementContext && !((SelectStatementContext) sqlStatementContext).getProjectionsContext().getExpandProjections().isEmpty();
+ return sqlStatementContext instanceof SelectStatementContext && !((SelectStatementContext) sqlStatementContext).getProjectionsContext().getExpandProjections().isEmpty()
+ && !((SelectStatementContext) sqlStatementContext).isContainsSubquery();
}
private MergedResult mergeQuery(final SQLStatementContext<?> sqlStatementContext, final List<QueryResult> queryResults) throws SQLException {
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/ExpressionBuilder.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/ExpressionBuilder.java
index b187f61..9dba409 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/ExpressionBuilder.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/ExpressionBuilder.java
@@ -37,7 +37,7 @@ public final class ExpressionBuilder {
/**
* Extract and predicates.
*
- * @return Or predicate segment.
+ * @return Or predicate segment
*/
public OrPredicateSegment extractAndPredicates() {
OrPredicateSegment result = new OrPredicateSegment();
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtil.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtil.java
index 9fe01d3..e1c2bfd 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtil.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtil.java
@@ -143,8 +143,8 @@ public final class SQLUtil {
/**
* Get subquery from tableSegment.
*
- * @param tableSegment TableSegment.
- * @return exactly SubqueryTableSegment list.
+ * @param tableSegment TableSegment
+ * @return exactly SubqueryTableSegment list
*/
public static List<SubqueryTableSegment> getSubqueryTableSegmentFromTableSegment(final TableSegment tableSegment) {
List<SubqueryTableSegment> result = new LinkedList<>();
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtils.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtil.java
similarity index 99%
rename from shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtils.java
rename to shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtil.java
index 519ab04..4539d69 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtils.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtil.java
@@ -36,7 +36,7 @@ import java.util.stream.Collectors;
* Safe number operation utility class.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class SafeNumberOperationUtils {
+public final class SafeNumberOperationUtil {
/**
* Execute range intersection method by safe mode.
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SubqueryExtractUtil.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SubqueryExtractUtil.java
new file mode 100644
index 0000000..7000cea
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SubqueryExtractUtil.java
@@ -0,0 +1,106 @@
+/*
+ * 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.common.util;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ListExpression;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubqueryExpressionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubquerySegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.SubqueryProjectionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.JoinTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SubqueryTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+
+/**
+ * Subquery extract utility class.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class SubqueryExtractUtil {
+
+ /**
+ * Get subquery segment from SelectStatement.
+ *
+ * @param selectStatement SelectStatement
+ * @return subquery segment collection
+ */
+ public static Collection<SubquerySegment> getSubquerySegments(final SelectStatement selectStatement) {
+ Collection<SubquerySegment> result = new LinkedList<>();
+ result.addAll(getSubquerySegmentsFromProjections(selectStatement.getProjections()));
+ result.addAll(getSubquerySegmentsFromTableSegment(selectStatement.getFrom()));
+ if (selectStatement.getWhere().isPresent()) {
+ result.addAll(getSubquerySegmentsFromExpression(selectStatement.getWhere().get().getExpr()));
+ }
+ return result;
+ }
+
+ private static Collection<SubquerySegment> getSubquerySegmentsFromProjections(final ProjectionsSegment projections) {
+ if (null == projections || projections.getProjections().isEmpty()) {
+ return Collections.emptyList();
+ }
+ Collection<SubquerySegment> result = new LinkedList<>();
+ for (ProjectionSegment each : projections.getProjections()) {
+ if (!(each instanceof SubqueryProjectionSegment)) {
+ continue;
+ }
+ result.add(((SubqueryProjectionSegment) each).getSubquery());
+ }
+ return result;
+ }
+
+ private static Collection<SubquerySegment> getSubquerySegmentsFromTableSegment(final TableSegment tableSegment) {
+ if (null == tableSegment) {
+ return Collections.emptyList();
+ }
+ Collection<SubquerySegment> result = new LinkedList<>();
+ if (tableSegment instanceof SubqueryTableSegment) {
+ result.add(((SubqueryTableSegment) tableSegment).getSubquery());
+ }
+ if (tableSegment instanceof JoinTableSegment) {
+ result.addAll(getSubquerySegmentsFromTableSegment(((JoinTableSegment) tableSegment).getLeft()));
+ result.addAll(getSubquerySegmentsFromTableSegment(((JoinTableSegment) tableSegment).getRight()));
+ }
+ return result;
+ }
+
+ private static Collection<SubquerySegment> getSubquerySegmentsFromExpression(final ExpressionSegment expressionSegment) {
+ Collection<SubquerySegment> result = new LinkedList<>();
+ if (expressionSegment instanceof SubqueryExpressionSegment) {
+ result.add(((SubqueryExpressionSegment) expressionSegment).getSubquery());
+ }
+ if (expressionSegment instanceof ListExpression) {
+ for (ExpressionSegment each : ((ListExpression) expressionSegment).getItems()) {
+ result.addAll(getSubquerySegmentsFromExpression(each));
+ }
+ }
+ if (expressionSegment instanceof BinaryOperationExpression) {
+ result.addAll(getSubquerySegmentsFromExpression(((BinaryOperationExpression) expressionSegment).getLeft()));
+ result.addAll(getSubquerySegmentsFromExpression(((BinaryOperationExpression) expressionSegment).getRight()));
+ }
+ return result;
+ }
+}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/WhereExtractUtil.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/WhereExtractUtil.java
new file mode 100644
index 0000000..7b8ff11
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/WhereExtractUtil.java
@@ -0,0 +1,72 @@
+/*
+ * 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.common.util;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubquerySegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.JoinTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+
+/**
+ * Where extract utility class.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class WhereExtractUtil {
+
+ /**
+ * Get join where segment from SelectStatement.
+ *
+ * @param selectStatement SelectStatement
+ * @return join where segment collection
+ */
+ public static Collection<WhereSegment> getJoinWhereSegments(final SelectStatement selectStatement) {
+ if (null == selectStatement.getFrom()) {
+ return Collections.emptyList();
+ }
+ TableSegment tableSegment = selectStatement.getFrom();
+ Collection<WhereSegment> result = new LinkedList<>();
+ if (tableSegment instanceof JoinTableSegment && null != ((JoinTableSegment) tableSegment).getCondition()) {
+ ExpressionSegment expressionSegment = ((JoinTableSegment) tableSegment).getCondition();
+ WhereSegment whereSegment = new WhereSegment(expressionSegment.getStartIndex(), expressionSegment.getStopIndex(), expressionSegment);
+ result.add(whereSegment);
+ }
+ return result;
+ }
+
+ /**
+ * Get subquery where segment from SelectStatement.
+ *
+ * @param selectStatement SelectStatement
+ * @return subquery where segment collection
+ */
+ public static Collection<WhereSegment> getSubqueryWhereSegments(final SelectStatement selectStatement) {
+ Collection<WhereSegment> result = new LinkedList<>();
+ for (SubquerySegment each : SubqueryExtractUtil.getSubquerySegments(selectStatement)) {
+ each.getSelect().getWhere().ifPresent(result::add);
+ }
+ return result;
+ }
+}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/WhereSegmentExtractUtils.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/WhereSegmentExtractUtils.java
deleted file mode 100644
index 36a7f70..0000000
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/WhereSegmentExtractUtils.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * 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.common.util;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ListExpression;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubqueryExpressionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.SubqueryProjectionSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.JoinTableSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SubqueryTableSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-
-/**
- * Where segment extract utility class.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class WhereSegmentExtractUtils {
-
- /**
- * Get join where segment from SelectStatement.
- *
- * @param selectStatement SelectStatement
- * @return join where segment collection.
- */
- public static Collection<WhereSegment> getJoinWhereSegments(final SelectStatement selectStatement) {
- if (null == selectStatement.getFrom()) {
- return Collections.emptyList();
- }
- TableSegment tableSegment = selectStatement.getFrom();
- Collection<WhereSegment> result = new LinkedList<>();
- if (tableSegment instanceof JoinTableSegment && null != ((JoinTableSegment) tableSegment).getCondition()) {
- ExpressionSegment expressionSegment = ((JoinTableSegment) tableSegment).getCondition();
- WhereSegment whereSegment = new WhereSegment(expressionSegment.getStartIndex(), expressionSegment.getStopIndex(), expressionSegment);
- result.add(whereSegment);
- }
- return result;
- }
-
- /**
- * Get subquery where segment from SelectStatement.
- *
- * @param selectStatement SelectStatement.
- * @return subquery where segment collection.
- */
- public static Collection<WhereSegment> getSubqueryWhereSegments(final SelectStatement selectStatement) {
- Collection<WhereSegment> result = new LinkedList<>();
- result.addAll(getSubqueryWhereSegmentsFromProjections(selectStatement.getProjections()));
- result.addAll(getSubqueryWhereSegmentsFromTableSegment(selectStatement.getFrom()));
- if (selectStatement.getWhere().isPresent()) {
- result.addAll(getSubqueryWhereSegmentsFromExpression(selectStatement.getWhere().get().getExpr()));
- }
- return result;
- }
-
- private static Collection<WhereSegment> getSubqueryWhereSegmentsFromProjections(final ProjectionsSegment projections) {
- if (null == projections || projections.getProjections().isEmpty()) {
- return Collections.emptyList();
- }
- Collection<WhereSegment> result = new LinkedList<>();
- for (ProjectionSegment each : projections.getProjections()) {
- if (!(each instanceof SubqueryProjectionSegment)) {
- continue;
- }
- SelectStatement subquerySelect = ((SubqueryProjectionSegment) each).getSubquery().getSelect();
- result.addAll(getSubqueryWhereSegmentsFromSubquery(subquerySelect));
- }
- return result;
- }
-
- private static Collection<WhereSegment> getSubqueryWhereSegmentsFromSubquery(final SelectStatement subquerySelect) {
- Collection<WhereSegment> result = new LinkedList<>();
- subquerySelect.getWhere().ifPresent(result::add);
- result.addAll(getSubqueryWhereSegments(subquerySelect));
- return result;
- }
-
- private static Collection<WhereSegment> getSubqueryWhereSegmentsFromTableSegment(final TableSegment tableSegment) {
- if (null == tableSegment) {
- return Collections.emptyList();
- }
- Collection<WhereSegment> result = new LinkedList<>();
- if (tableSegment instanceof SubqueryTableSegment) {
- SelectStatement subquerySelect = ((SubqueryTableSegment) tableSegment).getSubquery().getSelect();
- result.addAll(getSubqueryWhereSegmentsFromSubquery(subquerySelect));
- }
- if (tableSegment instanceof JoinTableSegment) {
- result.addAll(getSubqueryWhereSegmentsFromTableSegment(((JoinTableSegment) tableSegment).getLeft()));
- result.addAll(getSubqueryWhereSegmentsFromTableSegment(((JoinTableSegment) tableSegment).getRight()));
- }
- return result;
- }
-
- private static Collection<WhereSegment> getSubqueryWhereSegmentsFromExpression(final ExpressionSegment expressionSegment) {
- Collection<WhereSegment> result = new LinkedList<>();
- if (expressionSegment instanceof SubqueryExpressionSegment) {
- result.addAll(getSubqueryWhereSegmentsFromSubquery(((SubqueryExpressionSegment) expressionSegment).getSubquery().getSelect()));
- }
- if (expressionSegment instanceof ListExpression) {
- for (ExpressionSegment each : ((ListExpression) expressionSegment).getItems()) {
- result.addAll(getSubqueryWhereSegmentsFromExpression(each));
- }
- }
- if (expressionSegment instanceof BinaryOperationExpression) {
- result.addAll(getSubqueryWhereSegmentsFromExpression(((BinaryOperationExpression) expressionSegment).getLeft()));
- result.addAll(getSubqueryWhereSegmentsFromExpression(((BinaryOperationExpression) expressionSegment).getRight()));
- }
- return result;
- }
-}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtilsTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtilTest.java
similarity index 73%
rename from shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtilsTest.java
rename to shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtilTest.java
index 051ca29..2e50bd3 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtilsTest.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SafeNumberOperationUtilTest.java
@@ -31,13 +31,13 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-public final class SafeNumberOperationUtilsTest {
+public final class SafeNumberOperationUtilTest {
@Test
public void assertSafeIntersectionForInteger() {
Range<Comparable<?>> range = Range.closed(10, 2000);
Range<Comparable<?>> connectedRange = Range.closed(1500, 4000);
- Range<Comparable<?>> newRange = SafeNumberOperationUtils.safeIntersection(range, connectedRange);
+ Range<Comparable<?>> newRange = SafeNumberOperationUtil.safeIntersection(range, connectedRange);
assertThat(newRange.lowerEndpoint(), is(1500));
assertThat(newRange.lowerBoundType(), is(BoundType.CLOSED));
assertThat(newRange.upperEndpoint(), is(2000));
@@ -48,7 +48,7 @@ public final class SafeNumberOperationUtilsTest {
public void assertSafeIntersectionForLong() {
Range<Comparable<?>> range = Range.upTo(3147483647L, BoundType.OPEN);
Range<Comparable<?>> connectedRange = Range.downTo(3, BoundType.OPEN);
- Range<Comparable<?>> newRange = SafeNumberOperationUtils.safeIntersection(range, connectedRange);
+ Range<Comparable<?>> newRange = SafeNumberOperationUtil.safeIntersection(range, connectedRange);
assertThat(newRange.lowerEndpoint(), is(3L));
assertThat(newRange.lowerBoundType(), is(BoundType.OPEN));
assertThat(newRange.upperEndpoint(), is(3147483647L));
@@ -59,7 +59,7 @@ public final class SafeNumberOperationUtilsTest {
public void assertSafeIntersectionForBigInteger() {
Range<Comparable<?>> range = Range.upTo(new BigInteger("131323233123211"), BoundType.CLOSED);
Range<Comparable<?>> connectedRange = Range.downTo(35, BoundType.OPEN);
- Range<Comparable<?>> newRange = SafeNumberOperationUtils.safeIntersection(range, connectedRange);
+ Range<Comparable<?>> newRange = SafeNumberOperationUtil.safeIntersection(range, connectedRange);
assertThat(newRange.lowerEndpoint(), is(new BigInteger("35")));
assertThat(newRange.lowerBoundType(), is(BoundType.OPEN));
assertThat(newRange.upperEndpoint(), is(new BigInteger("131323233123211")));
@@ -70,7 +70,7 @@ public final class SafeNumberOperationUtilsTest {
public void assertSafeIntersectionForFloat() {
Range<Comparable<?>> range = Range.closed(5.5F, 13.8F);
Range<Comparable<?>> connectedRange = Range.closed(7.14F, 11.3F);
- Range<Comparable<?>> newRange = SafeNumberOperationUtils.safeIntersection(range, connectedRange);
+ Range<Comparable<?>> newRange = SafeNumberOperationUtil.safeIntersection(range, connectedRange);
assertThat(newRange.lowerEndpoint(), is(7.14F));
assertThat(newRange.lowerBoundType(), is(BoundType.CLOSED));
assertThat(newRange.upperEndpoint(), is(11.3F));
@@ -81,7 +81,7 @@ public final class SafeNumberOperationUtilsTest {
public void assertSafeIntersectionForDouble() {
Range<Comparable<?>> range = Range.closed(1242.114, 31474836.12);
Range<Comparable<?>> connectedRange = Range.downTo(567.34F, BoundType.OPEN);
- Range<Comparable<?>> newRange = SafeNumberOperationUtils.safeIntersection(range, connectedRange);
+ Range<Comparable<?>> newRange = SafeNumberOperationUtil.safeIntersection(range, connectedRange);
assertThat(newRange.lowerEndpoint(), is(1242.114));
assertThat(newRange.lowerBoundType(), is(BoundType.CLOSED));
assertThat(newRange.upperEndpoint(), is(31474836.12));
@@ -92,7 +92,7 @@ public final class SafeNumberOperationUtilsTest {
public void assertSafeIntersectionForBigDecimal() {
Range<Comparable<?>> range = Range.upTo(new BigDecimal("2331.23211"), BoundType.CLOSED);
Range<Comparable<?>> connectedRange = Range.open(135.13F, 45343.23F);
- Range<Comparable<?>> newRange = SafeNumberOperationUtils.safeIntersection(range, connectedRange);
+ Range<Comparable<?>> newRange = SafeNumberOperationUtil.safeIntersection(range, connectedRange);
assertThat(newRange.lowerEndpoint(), is(new BigDecimal("135.13")));
assertThat(newRange.lowerBoundType(), is(BoundType.OPEN));
assertThat(newRange.upperEndpoint(), is(new BigDecimal("2331.23211")));
@@ -101,42 +101,42 @@ public final class SafeNumberOperationUtilsTest {
@Test
public void assertSafeClosedForInteger() {
- Range<Comparable<?>> range = SafeNumberOperationUtils.safeClosed(12, 500);
+ Range<Comparable<?>> range = SafeNumberOperationUtil.safeClosed(12, 500);
assertThat(range.lowerEndpoint(), is(12));
assertThat(range.upperEndpoint(), is(500));
}
@Test
public void assertSafeClosedForLong() {
- Range<Comparable<?>> range = SafeNumberOperationUtils.safeClosed(12, 5001L);
+ Range<Comparable<?>> range = SafeNumberOperationUtil.safeClosed(12, 5001L);
assertThat(range.lowerEndpoint(), is(12L));
assertThat(range.upperEndpoint(), is(5001L));
}
@Test
public void assertSafeClosedForBigInteger() {
- Range<Comparable<?>> range = SafeNumberOperationUtils.safeClosed(12L, new BigInteger("12344"));
+ Range<Comparable<?>> range = SafeNumberOperationUtil.safeClosed(12L, new BigInteger("12344"));
assertThat(range.lowerEndpoint(), is(new BigInteger("12")));
assertThat(range.upperEndpoint(), is(new BigInteger("12344")));
}
@Test
public void assertSafeClosedForFloat() {
- Range<Comparable<?>> range = SafeNumberOperationUtils.safeClosed(4.5F, 11.13F);
+ Range<Comparable<?>> range = SafeNumberOperationUtil.safeClosed(4.5F, 11.13F);
assertThat(range.lowerEndpoint(), is(4.5F));
assertThat(range.upperEndpoint(), is(11.13F));
}
@Test
public void assertSafeClosedForDouble() {
- Range<Comparable<?>> range = SafeNumberOperationUtils.safeClosed(5.12F, 13.75);
+ Range<Comparable<?>> range = SafeNumberOperationUtil.safeClosed(5.12F, 13.75);
assertThat(range.lowerEndpoint(), is(5.12));
assertThat(range.upperEndpoint(), is(13.75));
}
@Test
public void assertSafeClosedForBigDecimal() {
- Range<Comparable<?>> range = SafeNumberOperationUtils.safeClosed(5.1F, new BigDecimal("17.666"));
+ Range<Comparable<?>> range = SafeNumberOperationUtil.safeClosed(5.1F, new BigDecimal("17.666"));
assertThat(range.lowerEndpoint(), is(new BigDecimal("5.1")));
assertThat(range.upperEndpoint(), is(new BigDecimal("17.666")));
}
@@ -144,108 +144,108 @@ public final class SafeNumberOperationUtilsTest {
@Test
public void assertSafeContainsForInteger() {
Range<Comparable<?>> range = Range.closed(12, 100);
- assertFalse(SafeNumberOperationUtils.safeContains(range, 500));
+ assertFalse(SafeNumberOperationUtil.safeContains(range, 500));
}
@Test
public void assertSafeContainsForLong() {
Range<Comparable<?>> range = Range.closed(12L, 1000L);
- assertTrue(SafeNumberOperationUtils.safeContains(range, 500));
+ assertTrue(SafeNumberOperationUtil.safeContains(range, 500));
}
@Test
public void assertSafeContainsForBigInteger() {
Range<Comparable<?>> range = Range.closed(new BigInteger("123"), new BigInteger("1000"));
- assertTrue(SafeNumberOperationUtils.safeContains(range, 510));
+ assertTrue(SafeNumberOperationUtil.safeContains(range, 510));
}
@Test
public void assertSafeContainsForFloat() {
Range<Comparable<?>> range = Range.closed(123.11F, 9999.123F);
- assertTrue(SafeNumberOperationUtils.safeContains(range, 510.12));
+ assertTrue(SafeNumberOperationUtil.safeContains(range, 510.12));
}
@Test
public void assertSafeContainsForDouble() {
Range<Comparable<?>> range = Range.closed(11.11, 9999.99);
- assertTrue(SafeNumberOperationUtils.safeContains(range, new BigDecimal("510.12")));
+ assertTrue(SafeNumberOperationUtil.safeContains(range, new BigDecimal("510.12")));
}
@Test
public void assertSafeContainsForBigDecimal() {
Range<Comparable<?>> range = Range.closed(new BigDecimal("123.11"), new BigDecimal("9999.123"));
- assertTrue(SafeNumberOperationUtils.safeContains(range, 510.12));
+ assertTrue(SafeNumberOperationUtil.safeContains(range, 510.12));
}
@Test
public void assertSafeCollectionEqualsForInteger() {
List<Comparable<?>> sourceCollection = Lists.newArrayList(10, 12);
List<Comparable<?>> targetCollection = Lists.newArrayList(10, 12);
- assertTrue(SafeNumberOperationUtils.safeCollectionEquals(sourceCollection, targetCollection));
+ assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sourceCollection, targetCollection));
}
@Test
public void assertSafeCollectionEqualsForLong() {
List<Comparable<?>> sourceCollection = Lists.newArrayList(10, 12);
List<Comparable<?>> targetCollection = Lists.newArrayList(10L, 12L);
- assertTrue(SafeNumberOperationUtils.safeCollectionEquals(sourceCollection, targetCollection));
+ assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sourceCollection, targetCollection));
}
@Test
public void assertSafeCollectionEqualsForBigInteger() {
List<Comparable<?>> sourceCollection = Lists.newArrayList(10, 12);
List<Comparable<?>> targetCollection = Lists.newArrayList(BigInteger.valueOf(10), BigInteger.valueOf(12L));
- assertTrue(SafeNumberOperationUtils.safeCollectionEquals(sourceCollection, targetCollection));
+ assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sourceCollection, targetCollection));
}
@Test
public void assertSafeCollectionEqualsForFloat() {
List<Comparable<?>> sourceCollection = Lists.newArrayList(10.01F, 12.01F);
List<Comparable<?>> targetCollection = Lists.newArrayList(10.01F, 12.01F);
- assertTrue(SafeNumberOperationUtils.safeCollectionEquals(sourceCollection, targetCollection));
+ assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sourceCollection, targetCollection));
}
@Test
public void assertSafeCollectionEqualsForDouble() {
List<Comparable<?>> sourceCollection = Lists.newArrayList(10.01, 12.01);
List<Comparable<?>> targetCollection = Lists.newArrayList(10.01F, 12.01);
- assertTrue(SafeNumberOperationUtils.safeCollectionEquals(sourceCollection, targetCollection));
+ assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sourceCollection, targetCollection));
}
@Test
public void assertSafeCollectionEqualsForBigDecimal() {
List<Comparable<?>> sourceCollection = Lists.newArrayList(10.01, 12.01);
List<Comparable<?>> targetCollection = Lists.newArrayList(BigDecimal.valueOf(10.01), BigDecimal.valueOf(12.01));
- assertTrue(SafeNumberOperationUtils.safeCollectionEquals(sourceCollection, targetCollection));
+ assertTrue(SafeNumberOperationUtil.safeCollectionEquals(sourceCollection, targetCollection));
}
@Test
public void assertSafeRangeEqualsForInteger() {
- assertTrue(SafeNumberOperationUtils.safeRangeEquals(Range.greaterThan(1), Range.greaterThan(1L)));
+ assertTrue(SafeNumberOperationUtil.safeRangeEquals(Range.greaterThan(1), Range.greaterThan(1L)));
}
@Test
public void assertSafeRangeEqualsForLong() {
- assertTrue(SafeNumberOperationUtils.safeRangeEquals(Range.greaterThan(1L), Range.greaterThan(BigInteger.ONE)));
+ assertTrue(SafeNumberOperationUtil.safeRangeEquals(Range.greaterThan(1L), Range.greaterThan(BigInteger.ONE)));
}
@Test
public void assertSafeRangeEqualsForBigInteger() {
- assertTrue(SafeNumberOperationUtils.safeRangeEquals(Range.greaterThan(BigInteger.ONE), Range.greaterThan(1)));
+ assertTrue(SafeNumberOperationUtil.safeRangeEquals(Range.greaterThan(BigInteger.ONE), Range.greaterThan(1)));
}
@Test
public void assertSafeRangeEqualsForFloat() {
- assertTrue(SafeNumberOperationUtils.safeRangeEquals(Range.greaterThan(1.1F), Range.greaterThan(1.1)));
+ assertTrue(SafeNumberOperationUtil.safeRangeEquals(Range.greaterThan(1.1F), Range.greaterThan(1.1)));
}
@Test
public void assertSafeRangeEqualsForDouble() {
- assertTrue(SafeNumberOperationUtils.safeRangeEquals(Range.greaterThan(1.1), Range.greaterThan(BigDecimal.valueOf(1.1))));
+ assertTrue(SafeNumberOperationUtil.safeRangeEquals(Range.greaterThan(1.1), Range.greaterThan(BigDecimal.valueOf(1.1))));
}
@Test
public void assertSafeRangeEqualsForBigDecimal() {
- assertTrue(SafeNumberOperationUtils.safeRangeEquals(Range.greaterThan(BigDecimal.valueOf(1.1)), Range.greaterThan(1.1F)));
+ assertTrue(SafeNumberOperationUtil.safeRangeEquals(Range.greaterThan(BigDecimal.valueOf(1.1)), Range.greaterThan(1.1F)));
}
}