You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by yx...@apache.org on 2022/11/13 09:58:25 UTC
[shardingsphere] branch master updated: Use ShardingSphereMetaData#getDatabase to replace databases#get method (#22141)
This is an automated email from the ASF dual-hosted git repository.
yx9o 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 80e90180f7b Use ShardingSphereMetaData#getDatabase to replace databases#get method (#22141)
80e90180f7b is described below
commit 80e90180f7b60a793582e274f4bfe418c469f59b
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Sun Nov 13 17:58:19 2022 +0800
Use ShardingSphereMetaData#getDatabase to replace databases#get method (#22141)
* Use ShardingSphereMetaData#getDatabase to replace databases#get method
* revert config-sharding.yaml
* use ConcurrentHashMap to store databases
---
.../token/generator/EncryptGeneratorBaseTest.java | 11 ++++-
.../merge/ShardingResultMergerEngineTest.java | 10 +++-
.../common/IteratorStreamMergedResultTest.java | 9 +++-
.../merge/ddl/ShardingDDLResultMergerTest.java | 9 +++-
.../ddl/fetch/FetchStreamMergedResultTest.java | 9 +++-
.../merge/dql/ShardingDQLResultMergerTest.java | 53 +++++++++++-----------
.../dql/groupby/GroupByMemoryMergedResultTest.java | 15 ++++--
.../dql/groupby/GroupByRowComparatorTest.java | 19 +++++---
.../dql/groupby/GroupByStreamMergedResultTest.java | 8 +++-
.../dql/orderby/OrderByStreamMergedResultTest.java | 10 +++-
.../merge/dql/orderby/OrderByValueTest.java | 13 ++++--
.../pagination/LimitDecoratorMergedResultTest.java | 16 ++++---
.../RowNumberDecoratorMergedResultTest.java | 18 +++++---
.../TopAndRowNumberDecoratorMergedResultTest.java | 21 +++++----
.../token/ShardingRemoveTokenGeneratorTest.java | 13 ++++--
.../engine/type/standard/AbstractSQLRouteTest.java | 9 +++-
.../dml/ShardingInsertStatementValidatorTest.java | 6 ++-
.../checker/ShardingRouteCacheableCheckerTest.java | 8 +++-
.../infra/binder/SQLStatementContextFactory.java | 27 ++++++-----
.../statement/ddl/CursorStatementContext.java | 7 ++-
.../statement/dml/InsertStatementContext.java | 28 ++++++------
.../statement/dml/SelectStatementContext.java | 15 +++---
.../select/pagination/PaginationContextTest.java | 11 +++--
.../engine/ProjectionsContextEngineTest.java | 9 +++-
.../statement/SQLStatementContextFactoryTest.java | 22 +++++----
.../statement/impl/InsertStatementContextTest.java | 11 ++++-
.../statement/impl/SelectStatementContextTest.java | 53 ++++++++++++----------
.../infra/metadata/ShardingSphereMetaData.java | 3 +-
.../statement/ShardingSpherePreparedStatement.java | 4 +-
.../core/statement/ShardingSphereStatement.java | 4 +-
.../sqlfederation/spi/SQLFederationExecutor.java | 1 +
.../spi/SQLFederationExecutorContext.java | 5 +-
.../advanced/AdvancedSQLFederationExecutor.java | 2 +-
.../executor/FilterableTableScanExecutor.java | 12 ++---
.../executor/TranslatableTableScanExecutor.java | 12 ++---
.../original/OriginalSQLFederationExecutor.java | 2 +-
.../traffic/rule/TrafficRuleTest.java | 14 ++++--
.../jdbc/JDBCDatabaseCommunicationEngine.java | 2 +-
.../handler/ProxyBackendHandlerFactory.java | 4 +-
.../admin/mysql/MySQLSetVariableAdminExecutor.java | 2 +-
.../executor/UnicastResourceShowExecutor.java | 6 +--
.../handler/distsql/rul/sql/PreviewHandler.java | 4 +-
.../communication/ProxySQLExecutorTest.java | 12 +++--
.../prepare/MySQLComStmtPrepareExecutor.java | 9 ++--
.../fieldlist/MySQLComFieldListPacketExecutor.java | 2 +-
.../text/query/MySQLMultiStatementsHandler.java | 2 +-
.../PostgreSQLBatchedStatementsExecutor.java | 2 +-
.../describe/PostgreSQLComDescribeExecutor.java | 2 +-
.../extended/parse/PostgreSQLComParseExecutor.java | 4 +-
.../ReactiveMySQLComFieldListPacketExecutor.java | 2 +-
.../AbstractSQLRewriterParameterizedTest.java | 9 +++-
51 files changed, 351 insertions(+), 210 deletions(-)
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptGeneratorBaseTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptGeneratorBaseTest.java
index b55b429308b..a6ade264cdc 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptGeneratorBaseTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptGeneratorBaseTest.java
@@ -25,8 +25,11 @@ import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.InsertValue;
@@ -68,13 +71,17 @@ public abstract class EncryptGeneratorBaseTest {
Collections.singletonMap("test_encryptor", new AlgorithmConfiguration("CORE.QUERY_ASSISTED.FIXTURE", new Properties()))));
}
- protected static InsertStatementContext createInsertStatementContext(final List<Object> params) {
+ protected InsertStatementContext createInsertStatementContext(final List<Object> params) {
InsertStatement insertStatement = createInsertStatement();
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
when(schema.getAllColumnNames("tbl")).thenReturn(Arrays.asList("id", "name", "status", "pwd"));
- return new InsertStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), params, insertStatement, DefaultDatabase.LOGIC_NAME);
+ return new InsertStatementContext(createShardingSphereMetaData(database), params, insertStatement, DefaultDatabase.LOGIC_NAME);
+ }
+
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
}
protected static InsertStatement createInsertStatement() {
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ShardingResultMergerEngineTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ShardingResultMergerEngineTest.java
index 6fd0a0a583a..b8095a00e15 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ShardingResultMergerEngineTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ShardingResultMergerEngineTest.java
@@ -24,7 +24,9 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.merge.engine.merger.impl.TransparentResultMerger;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.sharding.merge.dal.ShardingDALResultMerger;
import org.apache.shardingsphere.sharding.merge.ddl.ShardingDDLResultMerger;
@@ -88,12 +90,16 @@ public final class ShardingResultMergerEngineTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext sqlStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database),
+ SelectStatementContext sqlStatementContext = new SelectStatementContext(createShardingSphereMetaData(database),
Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
assertThat(new ShardingResultMergerEngine().newInstance(DefaultDatabase.LOGIC_NAME, DatabaseTypeFactory.getInstance("MySQL"), null, props,
sqlStatementContext), instanceOf(ShardingDQLResultMerger.class));
}
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
@Test
public void assertNewInstanceWithDALStatement() {
ConfigurationProperties props = new ConfigurationProperties(new Properties());
@@ -117,7 +123,7 @@ public final class ShardingResultMergerEngineTest {
private InsertStatementContext createInsertStatementContext(final InsertStatement insertStatement) {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
- return new InsertStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), insertStatement, DefaultDatabase.LOGIC_NAME);
+ return new InsertStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), insertStatement, DefaultDatabase.LOGIC_NAME);
}
@Test
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/common/IteratorStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/common/IteratorStreamMergedResultTest.java
index 04976a7310e..896699a6255 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/common/IteratorStreamMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/common/IteratorStreamMergedResultTest.java
@@ -18,12 +18,15 @@
package org.apache.shardingsphere.sharding.merge.common;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
@@ -51,7 +54,11 @@ public final class IteratorStreamMergedResultTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatementContext = new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ }
+
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
}
@Test
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMergerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMergerTest.java
index 35c3f13e5a3..c9da76549d1 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMergerTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMergerTest.java
@@ -20,12 +20,15 @@ package org.apache.shardingsphere.sharding.merge.ddl;
import org.apache.shardingsphere.infra.binder.statement.ddl.CursorStatementContext;
import org.apache.shardingsphere.infra.binder.statement.ddl.FetchStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.context.cursor.CursorConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.impl.transparent.TransparentMergedResult;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.sharding.merge.common.IteratorStreamMergedResult;
import org.apache.shardingsphere.sharding.merge.ddl.fetch.FetchStreamMergedResult;
@@ -89,13 +92,17 @@ public final class ShardingDDLResultMergerTest {
CursorStatementContext result = mock(CursorStatementContext.class, RETURNS_DEEP_STUBS);
SelectStatement selectStatement = createSelectStatement();
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
when(result.getSelectStatementContext()).thenReturn(selectStatementContext);
when(result.getSqlStatement().getSelect()).thenReturn(selectStatement);
return result;
}
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
private List<QueryResult> createSingleQueryResults() throws SQLException {
List<QueryResult> result = new LinkedList<>();
QueryResult queryResult = createQueryResult();
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java
index af25b9cacc9..8fd7c5cef9f 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java
@@ -19,12 +19,15 @@ package org.apache.shardingsphere.sharding.merge.ddl.fetch;
import org.apache.shardingsphere.infra.binder.statement.ddl.CursorStatementContext;
import org.apache.shardingsphere.infra.binder.statement.ddl.FetchStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.context.cursor.CursorConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.sharding.merge.ddl.ShardingDDLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.constant.DirectionType;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.cursor.CursorNameSegment;
@@ -91,7 +94,11 @@ public final class FetchStreamMergedResultTest {
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
OpenGaussCursorStatement cursorStatement = new OpenGaussCursorStatement();
cursorStatement.setSelect(createSelectStatement());
- return new CursorStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), cursorStatement, DefaultDatabase.LOGIC_NAME);
+ return new CursorStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), cursorStatement, DefaultDatabase.LOGIC_NAME);
+ }
+
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
}
private OpenGaussSelectStatement createSelectStatement() {
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java
index 855c549ac81..f38d56601e0 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java
@@ -18,12 +18,14 @@
package org.apache.shardingsphere.sharding.merge.dql;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -84,7 +86,7 @@ public final class ShardingDQLResultMergerTest {
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
SelectStatement selectStatement = buildSelectStatement(new MySQLSelectStatement());
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class)), instanceOf(IteratorStreamMergedResult.class));
}
@@ -97,8 +99,7 @@ public final class ShardingDQLResultMergerTest {
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
- selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
assertThat(resultMerger.merge(Collections.singletonList(createQueryResult()), selectStatementContext, createDatabase(), mock(ConnectionContext.class)),
instanceOf(IteratorStreamMergedResult.class));
}
@@ -111,8 +112,7 @@ public final class ShardingDQLResultMergerTest {
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
- selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(LimitDecoratorMergedResult.class));
assertThat(((LimitDecoratorMergedResult) actual).getMergedResult(), instanceOf(IteratorStreamMergedResult.class));
@@ -142,8 +142,7 @@ public final class ShardingDQLResultMergerTest {
when(subqueryTableSegment.getSubquery()).thenReturn(subquerySegment);
selectStatement.setFrom(subqueryTableSegment);
selectStatement.setWhere(whereSegment);
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database),
- null, selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), null, selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class));
assertThat(((RowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(IteratorStreamMergedResult.class));
@@ -157,8 +156,7 @@ public final class ShardingDQLResultMergerTest {
SQLServerSelectStatement selectStatement = (SQLServerSelectStatement) buildSelectStatement(new SQLServerSelectStatement());
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
- selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class));
assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(IteratorStreamMergedResult.class));
@@ -172,7 +170,7 @@ public final class ShardingDQLResultMergerTest {
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class)), instanceOf(OrderByStreamMergedResult.class));
}
@@ -186,7 +184,7 @@ public final class ShardingDQLResultMergerTest {
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(LimitDecoratorMergedResult.class));
@@ -218,7 +216,7 @@ public final class ShardingDQLResultMergerTest {
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setFrom(subqueryTableSegment);
selectStatement.setWhere(whereSegment);
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), null,
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), null,
selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class));
@@ -234,7 +232,7 @@ public final class ShardingDQLResultMergerTest {
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 1, true), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class));
@@ -250,7 +248,7 @@ public final class ShardingDQLResultMergerTest {
selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class)), instanceOf(GroupByStreamMergedResult.class));
}
@@ -265,7 +263,7 @@ public final class ShardingDQLResultMergerTest {
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(LimitDecoratorMergedResult.class));
@@ -298,7 +296,7 @@ public final class ShardingDQLResultMergerTest {
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setFrom(subqueryTableSegment);
selectStatement.setWhere(whereSegment);
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), null,
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), null,
selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class));
@@ -315,7 +313,7 @@ public final class ShardingDQLResultMergerTest {
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 1, true), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class));
@@ -330,7 +328,7 @@ public final class ShardingDQLResultMergerTest {
MySQLSelectStatement selectStatement = (MySQLSelectStatement) buildSelectStatement(new MySQLSelectStatement());
selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class)), instanceOf(GroupByStreamMergedResult.class));
}
@@ -344,7 +342,7 @@ public final class ShardingDQLResultMergerTest {
selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(LimitDecoratorMergedResult.class));
@@ -377,8 +375,7 @@ public final class ShardingDQLResultMergerTest {
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setFrom(subqueryTableSegment);
selectStatement.setWhere(whereSegment);
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), null,
- selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), null, selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class));
assertThat(((RowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByStreamMergedResult.class));
@@ -395,7 +392,7 @@ public final class ShardingDQLResultMergerTest {
selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC))));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 1, true), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class));
@@ -411,7 +408,7 @@ public final class ShardingDQLResultMergerTest {
ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.COUNT, "(*)"));
selectStatement.setProjections(projectionsSegment);
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
assertThat(resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class)), instanceOf(GroupByMemoryMergedResult.class));
}
@@ -425,7 +422,7 @@ public final class ShardingDQLResultMergerTest {
projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.COUNT, "(*)"));
selectStatement.setProjections(projectionsSegment);
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 1), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
DatabaseType databaseType = DatabaseTypeFactory.getInstance("MySQL");
ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(databaseType);
@@ -460,7 +457,7 @@ public final class ShardingDQLResultMergerTest {
selectStatement.setProjections(projectionsSegment);
selectStatement.setFrom(subqueryTableSegment);
selectStatement.setWhere(whereSegment);
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), null,
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), null,
selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class));
@@ -477,13 +474,17 @@ public final class ShardingDQLResultMergerTest {
projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.COUNT, "(*)"));
selectStatement.setProjections(projectionsSegment);
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 1, true), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext, createDatabase(), mock(ConnectionContext.class));
assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class));
assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByMemoryMergedResult.class));
}
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
private List<QueryResult> createQueryResults() throws SQLException {
List<QueryResult> result = new LinkedList<>();
QueryResult queryResult = createQueryResult();
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java
index ee5b68544c8..2d9226f8376 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByMemoryMergedResultTest.java
@@ -18,12 +18,15 @@
package org.apache.shardingsphere.sharding.merge.dql.groupby;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
@@ -52,9 +55,9 @@ import java.util.Arrays;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -120,10 +123,10 @@ public final class GroupByMemoryMergedResultTest {
selectStatement.setProjections(projectionsSegment);
selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, OrderDirection.ASC))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, OrderDirection.ASC))));
+ selectStatement.setProjections(projectionsSegment);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
- selectStatement.setProjections(projectionsSegment);
- return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ return new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
}
private SelectStatementContext createSelectStatementContext(final ShardingSphereDatabase database) {
@@ -135,7 +138,11 @@ public final class GroupByMemoryMergedResultTest {
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
selectStatement.setProjections(projectionsSegment);
- return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ return new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ }
+
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
}
@Test
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparatorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparatorTest.java
index dce7893be78..60b028e6bc8 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparatorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByRowComparatorTest.java
@@ -18,10 +18,13 @@
package org.apache.shardingsphere.sharding.merge.dql.groupby;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryQueryResultRow;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
@@ -89,7 +92,7 @@ public final class GroupByRowComparatorTest {
new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC),
new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatementContext, caseSensitives);
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
@@ -132,7 +135,7 @@ public final class GroupByRowComparatorTest {
new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC),
new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatementContext, caseSensitives);
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
@@ -175,7 +178,7 @@ public final class GroupByRowComparatorTest {
new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC),
new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatementContext, caseSensitives);
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
@@ -216,7 +219,7 @@ public final class GroupByRowComparatorTest {
new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.emptyList()));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatementContext, caseSensitives);
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
@@ -257,7 +260,7 @@ public final class GroupByRowComparatorTest {
new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.emptyList()));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatementContext, caseSensitives);
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
@@ -265,6 +268,10 @@ public final class GroupByRowComparatorTest {
assertTrue(groupByRowComparator.compare(o1, o2) > 0);
}
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
@Test
public void assertCompareToForEqualWithGroupByItemsForMySQL() throws SQLException {
assertCompareToForEqualWithGroupByItems(new MySQLSelectStatement());
@@ -298,7 +305,7 @@ public final class GroupByRowComparatorTest {
new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.emptyList()));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
GroupByRowComparator groupByRowComparator = new GroupByRowComparator(selectStatementContext, caseSensitives);
MemoryQueryResultRow o1 = new MemoryQueryResultRow(mockQueryResult("1", "2"));
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java
index ab2ab72f0dc..f910848d67d 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/groupby/GroupByStreamMergedResultTest.java
@@ -18,11 +18,13 @@
package org.apache.shardingsphere.sharding.merge.dql.groupby;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -170,7 +172,11 @@ public final class GroupByStreamMergedResultTest {
selectStatement.setProjections(projectionsSegment);
selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, OrderDirection.ASC))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.ASC, OrderDirection.ASC))));
- return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ return new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ }
+
+ private static ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
}
private ShardingSphereDatabase createDatabase() {
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java
index ae05bcd23e3..7fc3db287a9 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByStreamMergedResultTest.java
@@ -18,12 +18,14 @@
package org.apache.shardingsphere.sharding.merge.dql.orderby;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -48,8 +50,8 @@ import java.util.Collections;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -72,7 +74,11 @@ public final class OrderByStreamMergedResultTest {
selectStatement.setProjections(new ProjectionsSegment(0, 0));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
selectStatementContext = new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ }
+
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
}
@Test
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java
index f22ead8bb45..bcb73a77535 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java
@@ -19,9 +19,12 @@ package org.apache.shardingsphere.sharding.merge.dql.orderby;
import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
@@ -86,7 +89,7 @@ public final class OrderByValueTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
selectStatement.setOrderBy(createOrderBySegment());
SelectStatementContext selectStatementContext = new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
QueryResult queryResult1 = createQueryResult("1", "2");
OrderByValue orderByValue1 = new OrderByValue(queryResult1, Arrays.asList(
@@ -108,6 +111,10 @@ public final class OrderByValueTest {
assertFalse(orderByValue2.getQueryResult().next());
}
+ private static ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
@Test
public void assertCompareToForDescForMySQL() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToForDesc(new MySQLSelectStatement());
@@ -138,7 +145,7 @@ public final class OrderByValueTest {
selectStatement.setProjections(projectionsSegment);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
selectStatement.setOrderBy(createOrderBySegment());
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database),
Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.getTable("table")).thenReturn(new ShardingSphereTable());
@@ -192,7 +199,7 @@ public final class OrderByValueTest {
selectStatement.setProjections(projectionsSegment);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
selectStatement.setOrderBy(createOrderBySegment());
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database),
Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
QueryResult queryResult1 = createQueryResult("1", "2");
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/LimitDecoratorMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/LimitDecoratorMergedResultTest.java
index ff8b6c19f0f..c633214b392 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/LimitDecoratorMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/LimitDecoratorMergedResultTest.java
@@ -18,12 +18,15 @@
package org.apache.shardingsphere.sharding.merge.dql.pagination;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.limit.LimitSegment;
@@ -49,8 +52,7 @@ public final class LimitDecoratorMergedResultTest {
MySQLSelectStatement selectStatement = new MySQLSelectStatement();
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, Integer.MAX_VALUE), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, database,
@@ -64,8 +66,7 @@ public final class LimitDecoratorMergedResultTest {
MySQLSelectStatement selectStatement = new MySQLSelectStatement();
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, database,
@@ -82,8 +83,7 @@ public final class LimitDecoratorMergedResultTest {
MySQLSelectStatement selectStatement = new MySQLSelectStatement();
selectStatement.setProjections(new ProjectionsSegment(0, 0));
selectStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2), new NumberLiteralLimitValueSegment(0, 0, 2)));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database),
- Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("MySQL"));
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, database,
@@ -93,6 +93,10 @@ public final class LimitDecoratorMergedResultTest {
assertFalse(actual.next());
}
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
private QueryResult mockQueryResult() throws SQLException {
QueryResult result = mock(QueryResult.class, RETURNS_DEEP_STUBS);
when(result.next()).thenReturn(true, true, false);
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java
index e35e3f65a8c..b5538070ab7 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java
@@ -18,12 +18,15 @@
package org.apache.shardingsphere.sharding.merge.dql.pagination;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
@@ -76,8 +79,7 @@ public final class RowNumberDecoratorMergedResultTest {
selectStatement.setWhere(whereSegment);
ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- SelectStatementContext selectStatementContext = new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), null, selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), null, selectStatement, DefaultDatabase.LOGIC_NAME);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, database,
mock(ConnectionContext.class));
@@ -90,8 +92,7 @@ public final class RowNumberDecoratorMergedResultTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
OracleSelectStatement selectStatement = new OracleSelectStatement();
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext selectStatementContext = new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), null, selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), null, selectStatement, DefaultDatabase.LOGIC_NAME);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, database,
mock(ConnectionContext.class));
@@ -126,8 +127,7 @@ public final class RowNumberDecoratorMergedResultTest {
selectStatement.setWhere(whereSegment);
ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- SelectStatementContext selectStatementContext = new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), null, selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), null, selectStatement, DefaultDatabase.LOGIC_NAME);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, database,
mock(ConnectionContext.class));
@@ -161,7 +161,7 @@ public final class RowNumberDecoratorMergedResultTest {
selectStatement.setWhere(whereSegment);
ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("Oracle"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), null, selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), null, selectStatement, DefaultDatabase.LOGIC_NAME);
when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, database,
mock(ConnectionContext.class));
@@ -171,6 +171,10 @@ public final class RowNumberDecoratorMergedResultTest {
assertFalse(actual.next());
}
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
private QueryResult mockQueryResult() throws SQLException {
QueryResult result = mock(QueryResult.class, RETURNS_DEEP_STUBS);
when(result.next()).thenReturn(true, true, false);
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java
index 5e89b976de4..7ab6dcde034 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java
@@ -18,12 +18,15 @@
package org.apache.shardingsphere.sharding.merge.dql.pagination;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
@@ -60,8 +63,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement();
sqlStatement.setProjections(new ProjectionsSegment(0, 0));
sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, Integer.MAX_VALUE, true), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database),
- Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer"));
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(),
mockQueryResult(), mockQueryResult()), selectStatementContext, mockShardingSphereDatabase(), mock(ConnectionContext.class));
@@ -76,8 +78,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement();
sqlStatement.setProjections(new ProjectionsSegment(0, 0));
sqlStatement.setLimit(new LimitSegment(0, 0, null, new NumberLiteralLimitValueSegment(0, 0, 5)));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
- sqlStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(),
mockQueryResult(), mockQueryResult()), selectStatementContext, mockShardingSphereDatabase(), mock(ConnectionContext.class));
for (int i = 0; i < 5; i++) {
@@ -93,8 +94,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement();
sqlStatement.setProjections(new ProjectionsSegment(0, 0));
sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2, true), null));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database),
- Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeFactory.getInstance("SQLServer"));
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(),
mockQueryResult(), mockQueryResult()), selectStatementContext, mockShardingSphereDatabase(), mock(ConnectionContext.class));
@@ -112,8 +112,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement();
sqlStatement.setProjections(new ProjectionsSegment(0, 0));
sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2, false), new NumberLiteralLimitValueSegment(0, 0, 4)));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database),
- Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(),
mockQueryResult(), mockQueryResult()), selectStatementContext, mockShardingSphereDatabase(), mock(ConnectionContext.class));
assertTrue(actual.next());
@@ -129,7 +128,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement();
sqlStatement.setProjections(new ProjectionsSegment(0, 0));
sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2, true), new NumberLiteralLimitValueSegment(0, 0, 4)));
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database),
Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(),
mockQueryResult(), mockQueryResult()), selectStatementContext, mockShardingSphereDatabase(), mock(ConnectionContext.class));
@@ -139,6 +138,10 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
assertFalse(actual.next());
}
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
private QueryResult mockQueryResult() throws SQLException {
QueryResult result = mock(QueryResult.class, RETURNS_DEEP_STUBS);
when(result.next()).thenReturn(true, true, false);
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ShardingRemoveTokenGeneratorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ShardingRemoveTokenGeneratorTest.java
index 930139d723c..0def1bbeaf7 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ShardingRemoveTokenGeneratorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ShardingRemoveTokenGeneratorTest.java
@@ -19,8 +19,11 @@ package org.apache.shardingsphere.sharding.rewrite.token;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.RemoveToken;
import org.apache.shardingsphere.sharding.rewrite.token.generator.impl.ShardingRemoveTokenGenerator;
@@ -41,8 +44,8 @@ import java.util.Collections;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -75,13 +78,17 @@ public final class ShardingRemoveTokenGeneratorTest {
assertThat(sqlTokens.iterator().next(), instanceOf(RemoveToken.class));
}
- private static SelectStatementContext createUpdatesStatementContext() {
+ private SelectStatementContext createUpdatesStatementContext() {
MySQLSelectStatement selectStatement = new MySQLSelectStatement();
selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_user"))));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC))));
selectStatement.setProjections(createProjectionsSegment());
return new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS)), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ createShardingSphereMetaData(mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS)), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ }
+
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
}
private static ProjectionsSegment createProjectionsSegment() {
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java
index f34882863f6..395e03712e7 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/AbstractSQLRouteTest.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.infra.context.ConnectionContext;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -64,12 +65,16 @@ public abstract class AbstractSQLRouteTest extends AbstractRoutingEngineTest {
ShardingSphereResourceMetaData resourceMetaData = mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS);
when(resourceMetaData.getStorageTypes()).thenReturn(Collections.singletonMap("ds_0", new MySQLDatabaseType()));
ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, DatabaseTypeFactory.getInstance("MySQL"), resourceMetaData, ruleMetaData, schemas);
- Map<String, ShardingSphereDatabase> databases = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database);
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(databases, params, sqlStatementParserEngine.parse(sql, false), DefaultDatabase.LOGIC_NAME);
+ SQLStatementContext<?> sqlStatementContext =
+ SQLStatementContextFactory.newInstance(createShardingSphereMetaData(database), params, sqlStatementParserEngine.parse(sql, false), DefaultDatabase.LOGIC_NAME);
QueryContext queryContext = new QueryContext(sqlStatementContext, sql, params);
return new SQLRouteEngine(Arrays.asList(shardingRule, singleTableRule), props).route(new ConnectionContext(), queryContext, database);
}
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
private Map<String, ShardingSphereSchema> buildSchemas() {
Map<String, ShardingSphereTable> tables = new HashMap<>(3, 1);
tables.put("t_order", new ShardingSphereTable("t_order", Arrays.asList(new ShardingSphereColumn("order_id", Types.INTEGER, true, false, false, true, false),
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
index fefc4e4d47f..de2db0c6b86 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
@@ -25,7 +25,9 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
@@ -97,7 +99,9 @@ public final class ShardingInsertStatementValidatorTest {
private InsertStatementContext createInsertStatementContext(final List<Object> params, final InsertStatement insertStatement) {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
- return new InsertStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), params, insertStatement, DefaultDatabase.LOGIC_NAME);
+ ShardingSphereMetaData metaData =
+ new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ return new InsertStatementContext(metaData, params, insertStatement, DefaultDatabase.LOGIC_NAME);
}
@Test(expected = MissingGenerateKeyColumnWithInsertSelectException.class)
diff --git a/features/sharding/plugin/cache/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java b/features/sharding/plugin/cache/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
index a65ae24a171..e613590b922 100644
--- a/features/sharding/plugin/cache/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
+++ b/features/sharding/plugin/cache/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
@@ -22,9 +22,11 @@ import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -169,10 +171,14 @@ public final class ShardingRouteCacheableCheckerTest {
}
private QueryContext prepareQueryContext(final ShardingSphereDatabase database, final String sql, final List<Object> params) {
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(Collections.singletonMap(DATABASE_NAME, database), params, parse(sql), DATABASE_NAME);
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(createShardingSphereMetaData(database), params, parse(sql), DATABASE_NAME);
return new QueryContext(sqlStatementContext, sql, params);
}
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DATABASE_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
private SQLStatement parse(final String sql) {
CacheOption cacheOption = new CacheOption(0, 0);
return new SQLStatementParserEngine("PostgreSQL", cacheOption, cacheOption, false).parse(sql, false);
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/SQLStatementContextFactory.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/SQLStatementContextFactory.java
index 49c4be6cce3..0d0954d8c92 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/SQLStatementContextFactory.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/SQLStatementContextFactory.java
@@ -61,7 +61,7 @@ import org.apache.shardingsphere.infra.binder.statement.dml.DoStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.UnsupportedSQLOperationException;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.AnalyzeTableStatement;
@@ -111,7 +111,6 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.dcl.
import java.util.Collections;
import java.util.List;
-import java.util.Map;
/**
* SQL statement context factory.
@@ -122,31 +121,31 @@ public final class SQLStatementContextFactory {
/**
* Create SQL statement context.
*
- * @param databases databases
+ * @param metaData metaData
* @param sqlStatement SQL statement
* @param defaultDatabaseName default database name
* @return SQL statement context
*/
- public static SQLStatementContext<?> newInstance(final Map<String, ShardingSphereDatabase> databases, final SQLStatement sqlStatement, final String defaultDatabaseName) {
- return newInstance(databases, Collections.emptyList(), sqlStatement, defaultDatabaseName);
+ public static SQLStatementContext<?> newInstance(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement, final String defaultDatabaseName) {
+ return newInstance(metaData, Collections.emptyList(), sqlStatement, defaultDatabaseName);
}
/**
* Create SQL statement context.
*
- * @param databases databases
+ * @param metaData metaData
* @param params SQL parameters
* @param sqlStatement SQL statement
* @param defaultDatabaseName default database name
* @return SQL statement context
*/
- public static SQLStatementContext<?> newInstance(final Map<String, ShardingSphereDatabase> databases,
+ public static SQLStatementContext<?> newInstance(final ShardingSphereMetaData metaData,
final List<Object> params, final SQLStatement sqlStatement, final String defaultDatabaseName) {
if (sqlStatement instanceof DMLStatement) {
- return getDMLStatementContext(databases, params, (DMLStatement) sqlStatement, defaultDatabaseName);
+ return getDMLStatementContext(metaData, params, (DMLStatement) sqlStatement, defaultDatabaseName);
}
if (sqlStatement instanceof DDLStatement) {
- return getDDLStatementContext(databases, params, (DDLStatement) sqlStatement, defaultDatabaseName);
+ return getDDLStatementContext(metaData, params, (DDLStatement) sqlStatement, defaultDatabaseName);
}
if (sqlStatement instanceof DCLStatement) {
return getDCLStatementContext((DCLStatement) sqlStatement);
@@ -157,10 +156,10 @@ public final class SQLStatementContextFactory {
return new CommonSQLStatementContext<>(sqlStatement);
}
- private static SQLStatementContext<?> getDMLStatementContext(final Map<String, ShardingSphereDatabase> databases,
+ private static SQLStatementContext<?> getDMLStatementContext(final ShardingSphereMetaData metaData,
final List<Object> params, final DMLStatement sqlStatement, final String defaultDatabaseName) {
if (sqlStatement instanceof SelectStatement) {
- return new SelectStatementContext(databases, params, (SelectStatement) sqlStatement, defaultDatabaseName);
+ return new SelectStatementContext(metaData, params, (SelectStatement) sqlStatement, defaultDatabaseName);
}
if (sqlStatement instanceof UpdateStatement) {
return new UpdateStatementContext((UpdateStatement) sqlStatement);
@@ -169,7 +168,7 @@ public final class SQLStatementContextFactory {
return new DeleteStatementContext((DeleteStatement) sqlStatement);
}
if (sqlStatement instanceof InsertStatement) {
- return new InsertStatementContext(databases, params, (InsertStatement) sqlStatement, defaultDatabaseName);
+ return new InsertStatementContext(metaData, params, (InsertStatement) sqlStatement, defaultDatabaseName);
}
if (sqlStatement instanceof CallStatement) {
return new CallStatementContext((CallStatement) sqlStatement);
@@ -183,7 +182,7 @@ public final class SQLStatementContextFactory {
throw new UnsupportedSQLOperationException(String.format("Unsupported SQL statement `%s`", sqlStatement.getClass().getSimpleName()));
}
- private static SQLStatementContext<?> getDDLStatementContext(final Map<String, ShardingSphereDatabase> databases, final List<Object> params,
+ private static SQLStatementContext<?> getDDLStatementContext(final ShardingSphereMetaData metaData, final List<Object> params,
final DDLStatement sqlStatement, final String defaultDatabaseName) {
if (sqlStatement instanceof CreateSchemaStatement) {
return new CreateSchemaStatementContext((CreateSchemaStatement) sqlStatement);
@@ -234,7 +233,7 @@ public final class SQLStatementContextFactory {
return new CommentStatementContext((CommentStatement) sqlStatement);
}
if (sqlStatement instanceof OpenGaussCursorStatement) {
- return new CursorStatementContext(databases, params, (OpenGaussCursorStatement) sqlStatement, defaultDatabaseName);
+ return new CursorStatementContext(metaData, params, (OpenGaussCursorStatement) sqlStatement, defaultDatabaseName);
}
if (sqlStatement instanceof CloseStatement) {
return new CloseStatementContext((CloseStatement) sqlStatement);
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/CursorStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/CursorStatementContext.java
index 2904a73881d..23869dfa2a9 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/CursorStatementContext.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/CursorStatementContext.java
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.binder.type.CursorAvailable;
import org.apache.shardingsphere.infra.binder.type.TableAvailable;
import org.apache.shardingsphere.infra.binder.type.WhereAvailable;
import org.apache.shardingsphere.infra.context.cursor.CursorDefinition;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.cursor.CursorNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
@@ -39,7 +39,6 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
/**
@@ -56,13 +55,13 @@ public final class CursorStatementContext extends CommonSQLStatementContext<Open
private final SelectStatementContext selectStatementContext;
- public CursorStatementContext(final Map<String, ShardingSphereDatabase> databases, final List<Object> params,
+ public CursorStatementContext(final ShardingSphereMetaData metaData, final List<Object> params,
final OpenGaussCursorStatement sqlStatement, final String defaultDatabaseName) {
super(sqlStatement);
tablesContext = new TablesContext(getSimpleTableSegments(), getDatabaseType());
extractWhereSegments(whereSegments, sqlStatement.getSelect());
ColumnExtractor.extractColumnSegments(columnSegments, whereSegments);
- selectStatementContext = new SelectStatementContext(databases, params, sqlStatement.getSelect(), defaultDatabaseName);
+ selectStatementContext = new SelectStatementContext(metaData, params, sqlStatement.getSelect(), defaultDatabaseName);
}
private Collection<SimpleTableSegment> getSimpleTableSegments() {
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
index dca2f347fd8..84273a36708 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
@@ -18,6 +18,8 @@
package org.apache.shardingsphere.infra.binder.statement.dml;
import lombok.Getter;
+import org.apache.shardingsphere.dialect.exception.syntax.database.NoDatabaseSelectedException;
+import org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDatabaseException;
import org.apache.shardingsphere.infra.binder.aware.ParameterAware;
import org.apache.shardingsphere.infra.binder.segment.insert.keygen.GeneratedKeyContext;
import org.apache.shardingsphere.infra.binder.segment.insert.keygen.engine.GeneratedKeyContextEngine;
@@ -28,8 +30,7 @@ import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.type.TableAvailable;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
-import org.apache.shardingsphere.dialect.exception.syntax.database.NoDatabaseSelectedException;
-import org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDatabaseException;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
@@ -51,7 +52,6 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
@@ -65,7 +65,7 @@ public final class InsertStatementContext extends CommonSQLStatementContext<Inse
private final List<String> columnNames;
- private final Map<String, ShardingSphereDatabase> databases;
+ private final ShardingSphereMetaData metaData;
private final String defaultDatabaseName;
@@ -81,26 +81,26 @@ public final class InsertStatementContext extends CommonSQLStatementContext<Inse
private GeneratedKeyContext generatedKeyContext;
- public InsertStatementContext(final Map<String, ShardingSphereDatabase> databases, final List<Object> params, final InsertStatement sqlStatement, final String defaultDatabaseName) {
+ public InsertStatementContext(final ShardingSphereMetaData metaData, final List<Object> params, final InsertStatement sqlStatement, final String defaultDatabaseName) {
super(sqlStatement);
- this.databases = databases;
+ this.metaData = metaData;
this.defaultDatabaseName = defaultDatabaseName;
insertColumnNames = getInsertColumnNames();
valueExpressions = getAllValueExpressions(sqlStatement);
AtomicInteger parametersOffset = new AtomicInteger(0);
insertValueContexts = getInsertValueContexts(params, parametersOffset, valueExpressions);
- insertSelectContext = getInsertSelectContext(databases, params, parametersOffset, defaultDatabaseName).orElse(null);
+ insertSelectContext = getInsertSelectContext(metaData, params, parametersOffset, defaultDatabaseName).orElse(null);
onDuplicateKeyUpdateValueContext = getOnDuplicateKeyUpdateValueContext(params, parametersOffset).orElse(null);
tablesContext = new TablesContext(getAllSimpleTableSegments(), getDatabaseType());
- ShardingSphereSchema schema = getSchema(databases, defaultDatabaseName);
+ ShardingSphereSchema schema = getSchema(metaData, defaultDatabaseName);
columnNames = containsInsertColumns() ? insertColumnNames : schema.getVisibleColumnNames(sqlStatement.getTable().getTableName().getIdentifier().getValue());
generatedKeyContext = new GeneratedKeyContextEngine(sqlStatement, schema).createGenerateKeyContext(insertColumnNames, getAllValueExpressions(sqlStatement), params).orElse(null);
}
- private ShardingSphereSchema getSchema(final Map<String, ShardingSphereDatabase> databases, final String defaultDatabaseName) {
+ private ShardingSphereSchema getSchema(final ShardingSphereMetaData metaData, final String defaultDatabaseName) {
String databaseName = tablesContext.getDatabaseName().orElse(defaultDatabaseName);
ShardingSpherePreconditions.checkNotNull(databaseName, NoDatabaseSelectedException::new);
- ShardingSphereDatabase database = databases.get(databaseName.toLowerCase());
+ ShardingSphereDatabase database = metaData.getDatabase(databaseName);
ShardingSpherePreconditions.checkNotNull(database, () -> new UnknownDatabaseException(databaseName));
String defaultSchema = DatabaseTypeEngine.getDefaultSchemaName(getDatabaseType(), databaseName);
return tablesContext.getSchemaName().map(database::getSchema).orElseGet(() -> database.getSchema(defaultSchema));
@@ -122,13 +122,13 @@ public final class InsertStatementContext extends CommonSQLStatementContext<Inse
return result;
}
- private Optional<InsertSelectContext> getInsertSelectContext(final Map<String, ShardingSphereDatabase> databases, final List<Object> params,
+ private Optional<InsertSelectContext> getInsertSelectContext(final ShardingSphereMetaData metaData, final List<Object> params,
final AtomicInteger paramsOffset, final String defaultDatabaseName) {
if (!getSqlStatement().getInsertSelect().isPresent()) {
return Optional.empty();
}
SubquerySegment insertSelectSegment = getSqlStatement().getInsertSelect().get();
- SelectStatementContext selectStatementContext = new SelectStatementContext(databases, params, insertSelectSegment.getSelect(), defaultDatabaseName);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(metaData, params, insertSelectSegment.getSelect(), defaultDatabaseName);
InsertSelectContext insertSelectContext = new InsertSelectContext(selectStatementContext, params, paramsOffset.get());
paramsOffset.addAndGet(insertSelectContext.getParameterCount());
return Optional.of(insertSelectContext);
@@ -265,9 +265,9 @@ public final class InsertStatementContext extends CommonSQLStatementContext<Inse
public void setUpParameters(final List<Object> params) {
AtomicInteger parametersOffset = new AtomicInteger(0);
insertValueContexts = getInsertValueContexts(params, parametersOffset, valueExpressions);
- insertSelectContext = getInsertSelectContext(databases, params, parametersOffset, defaultDatabaseName).orElse(null);
+ insertSelectContext = getInsertSelectContext(metaData, params, parametersOffset, defaultDatabaseName).orElse(null);
onDuplicateKeyUpdateValueContext = getOnDuplicateKeyUpdateValueContext(params, parametersOffset).orElse(null);
- ShardingSphereSchema schema = getSchema(databases, defaultDatabaseName);
+ ShardingSphereSchema schema = getSchema(metaData, defaultDatabaseName);
generatedKeyContext = new GeneratedKeyContextEngine(getSqlStatement(), schema).createGenerateKeyContext(insertColumnNames, valueExpressions, params).orElse(null);
}
}
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
index 5aecc3d0696..fda4c843521 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
@@ -41,6 +41,7 @@ import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.type.TableAvailable;
import org.apache.shardingsphere.infra.binder.type.WhereAvailable;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
@@ -104,37 +105,37 @@ public final class SelectStatementContext extends CommonSQLStatementContext<Sele
private PaginationContext paginationContext;
- public SelectStatementContext(final Map<String, ShardingSphereDatabase> databases, final List<Object> params, final SelectStatement sqlStatement, final String defaultDatabaseName) {
+ public SelectStatementContext(final ShardingSphereMetaData metaData, final List<Object> params, final SelectStatement sqlStatement, final String defaultDatabaseName) {
super(sqlStatement);
extractWhereSegments(whereSegments, sqlStatement);
ColumnExtractor.extractColumnSegments(columnSegments, whereSegments);
- subqueryContexts = createSubqueryContexts(databases, params, defaultDatabaseName);
+ subqueryContexts = createSubqueryContexts(metaData, params, defaultDatabaseName);
tablesContext = new TablesContext(getAllTableSegments(), subqueryContexts, getDatabaseType());
String databaseName = tablesContext.getDatabaseName().orElse(defaultDatabaseName);
groupByContext = new GroupByContextEngine().createGroupByContext(sqlStatement);
orderByContext = new OrderByContextEngine().createOrderBy(sqlStatement, groupByContext);
- projectionsContext = new ProjectionsContextEngine(databaseName, getSchemas(databases, databaseName), getDatabaseType())
+ projectionsContext = new ProjectionsContextEngine(databaseName, getSchemas(metaData, databaseName), getDatabaseType())
.createProjectionsContext(getSqlStatement().getFrom(), getSqlStatement().getProjections(), groupByContext, orderByContext);
paginationContext = new PaginationContextEngine().createPaginationContext(sqlStatement, projectionsContext, params, whereSegments);
}
- private Map<Integer, SelectStatementContext> createSubqueryContexts(final Map<String, ShardingSphereDatabase> databases, final List<Object> params, final String defaultDatabaseName) {
+ private Map<Integer, SelectStatementContext> createSubqueryContexts(final ShardingSphereMetaData metaData, final List<Object> params, final String defaultDatabaseName) {
Collection<SubquerySegment> subquerySegments = SubqueryExtractUtil.getSubquerySegments(getSqlStatement());
Map<Integer, SelectStatementContext> result = new HashMap<>(subquerySegments.size(), 1);
for (SubquerySegment each : subquerySegments) {
- SelectStatementContext subqueryContext = new SelectStatementContext(databases, params, each.getSelect(), defaultDatabaseName);
+ SelectStatementContext subqueryContext = new SelectStatementContext(metaData, params, each.getSelect(), defaultDatabaseName);
subqueryContext.setSubqueryType(each.getSubqueryType());
result.put(each.getStartIndex(), subqueryContext);
}
return result;
}
- private Map<String, ShardingSphereSchema> getSchemas(final Map<String, ShardingSphereDatabase> databases, final String databaseName) {
+ private Map<String, ShardingSphereSchema> getSchemas(final ShardingSphereMetaData metaData, final String databaseName) {
if (null == databaseName) {
ShardingSpherePreconditions.checkState(tablesContext.getTables().isEmpty(), NoDatabaseSelectedException::new);
return Collections.emptyMap();
}
- ShardingSphereDatabase database = databases.get(databaseName.toLowerCase());
+ ShardingSphereDatabase database = metaData.getDatabase(databaseName);
ShardingSpherePreconditions.checkNotNull(database, () -> new UnknownDatabaseException(databaseName));
return database.getSchemas();
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/PaginationContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/PaginationContextTest.java
index 556bd8021aa..6e5a97535e3 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/PaginationContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/PaginationContextTest.java
@@ -18,8 +18,11 @@
package org.apache.shardingsphere.infra.binder.segment.select.pagination;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.GroupBySegment;
@@ -42,8 +45,8 @@ import java.util.List;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
@@ -162,7 +165,8 @@ public final class PaginationContextTest {
private void getRevisedRowCount(final SelectStatement selectStatement) {
selectStatement.setProjections(new ProjectionsSegment(0, 0));
Map<String, ShardingSphereDatabase> databases = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class));
- SelectStatementContext selectStatementContext = new SelectStatementContext(databases, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ SelectStatementContext selectStatementContext = new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
assertThat(new PaginationContext(getOffsetSegment(), getRowCountSegment(), getParameters()).getRevisedRowCount(selectStatementContext), is(50L));
}
@@ -196,7 +200,8 @@ public final class PaginationContextTest {
selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.DESC))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.DESC))));
Map<String, ShardingSphereDatabase> databases = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class));
- SelectStatementContext selectStatementContext = new SelectStatementContext(databases, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ SelectStatementContext selectStatementContext = new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
assertThat(new PaginationContext(getOffsetSegment(), getRowCountSegment(), getParameters()).getRevisedRowCount(selectStatementContext), is((long) Integer.MAX_VALUE));
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngineTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngineTest.java
index d26f1cc9110..b1bc5133106 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngineTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngineTest.java
@@ -22,8 +22,11 @@ import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByCont
import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.infra.binder.segment.select.projection.ProjectionsContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
@@ -57,8 +60,8 @@ import java.util.LinkedHashMap;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNotNull;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -225,7 +228,9 @@ public final class ProjectionsContextEngineTest {
private SelectStatementContext createSelectStatementContext(final SelectStatement selectStatement) {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
when(database.getSchemas()).thenReturn(mockSchemas());
- return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ Map<String, ShardingSphereDatabase> databases = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database);
+ ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ return new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
}
private Map<String, ShardingSphereSchema> mockSchemas() {
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementContextFactoryTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementContextFactoryTest.java
index eed273fee4a..abd98f52516 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementContextFactoryTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementContextFactoryTest.java
@@ -24,8 +24,11 @@ import org.apache.shardingsphere.infra.binder.statement.ddl.FetchStatementContex
import org.apache.shardingsphere.infra.binder.statement.ddl.MoveStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.SetAssignmentSegment;
@@ -68,7 +71,7 @@ public final class SQLStatementContextFactoryTest {
MySQLSelectStatement selectStatement = new MySQLSelectStatement();
selectStatement.setLimit(new LimitSegment(0, 10, null, null));
selectStatement.setProjections(projectionsSegment);
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(mockDatabases(), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(mockMetaData(), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
assertThat(sqlStatementContext, instanceOf(SelectStatementContext.class));
}
@@ -105,13 +108,13 @@ public final class SQLStatementContextFactoryTest {
private void assertSQLStatementContextCreatedWhenSQLStatementInstanceOfInsertStatement(final InsertStatement insertStatement) {
insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl"))));
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(mockDatabases(), Collections.emptyList(), insertStatement, DefaultDatabase.LOGIC_NAME);
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(mockMetaData(), Collections.emptyList(), insertStatement, DefaultDatabase.LOGIC_NAME);
assertThat(sqlStatementContext, instanceOf(InsertStatementContext.class));
}
@Test
public void assertSQLStatementContextCreatedWhenSQLStatementNotInstanceOfSelectStatementAndInsertStatement() {
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(mockDatabases(), Collections.emptyList(), mock(MySQLStatement.class), DefaultDatabase.LOGIC_NAME);
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(mockMetaData(), Collections.emptyList(), mock(MySQLStatement.class), DefaultDatabase.LOGIC_NAME);
assertThat(sqlStatementContext, instanceOf(CommonSQLStatementContext.class));
}
@@ -121,29 +124,30 @@ public final class SQLStatementContextFactoryTest {
MySQLSelectStatement selectStatement = mock(MySQLSelectStatement.class, RETURNS_DEEP_STUBS);
when(selectStatement.getProjections().isDistinctRow()).thenReturn(false);
when(cursorStatement.getSelect()).thenReturn(selectStatement);
- SQLStatementContext<?> actual = SQLStatementContextFactory.newInstance(mockDatabases(), Collections.emptyList(), cursorStatement, DefaultDatabase.LOGIC_NAME);
+ SQLStatementContext<?> actual = SQLStatementContextFactory.newInstance(mockMetaData(), Collections.emptyList(), cursorStatement, DefaultDatabase.LOGIC_NAME);
assertThat(actual, instanceOf(CursorStatementContext.class));
}
@Test
public void assertNewInstanceForCloseStatement() {
- SQLStatementContext<?> actual = SQLStatementContextFactory.newInstance(mockDatabases(), Collections.emptyList(), mock(OpenGaussCloseStatement.class), DefaultDatabase.LOGIC_NAME);
+ SQLStatementContext<?> actual = SQLStatementContextFactory.newInstance(mockMetaData(), Collections.emptyList(), mock(OpenGaussCloseStatement.class), DefaultDatabase.LOGIC_NAME);
assertThat(actual, instanceOf(CloseStatementContext.class));
}
@Test
public void assertNewInstanceForMoveStatement() {
- SQLStatementContext<?> actual = SQLStatementContextFactory.newInstance(mockDatabases(), Collections.emptyList(), mock(OpenGaussMoveStatement.class), DefaultDatabase.LOGIC_NAME);
+ SQLStatementContext<?> actual = SQLStatementContextFactory.newInstance(mockMetaData(), Collections.emptyList(), mock(OpenGaussMoveStatement.class), DefaultDatabase.LOGIC_NAME);
assertThat(actual, instanceOf(MoveStatementContext.class));
}
@Test
public void assertNewInstanceForFetchStatement() {
- SQLStatementContext<?> actual = SQLStatementContextFactory.newInstance(mockDatabases(), Collections.emptyList(), mock(OpenGaussFetchStatement.class), DefaultDatabase.LOGIC_NAME);
+ SQLStatementContext<?> actual = SQLStatementContextFactory.newInstance(mockMetaData(), Collections.emptyList(), mock(OpenGaussFetchStatement.class), DefaultDatabase.LOGIC_NAME);
assertThat(actual, instanceOf(FetchStatementContext.class));
}
- private Map<String, ShardingSphereDatabase> mockDatabases() {
- return Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS));
+ private ShardingSphereMetaData mockMetaData() {
+ Map<String, ShardingSphereDatabase> databases = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS));
+ return new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/InsertStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/InsertStatementContextTest.java
index c0ad190a848..0832ec3eefb 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/InsertStatementContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/InsertStatementContextTest.java
@@ -18,8 +18,11 @@
package org.apache.shardingsphere.infra.binder.statement.impl;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment;
@@ -57,9 +60,9 @@ import java.util.List;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -111,7 +114,11 @@ public final class InsertStatementContextTest {
String defaultSchemaName = insertStatement instanceof PostgreSQLStatement || insertStatement instanceof OpenGaussStatement ? "public" : DefaultDatabase.LOGIC_NAME;
when(database.getSchema(defaultSchemaName)).thenReturn(schema);
when(schema.getVisibleColumnNames("tbl")).thenReturn(Arrays.asList("id", "name", "status"));
- return new InsertStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), params, insertStatement, DefaultDatabase.LOGIC_NAME);
+ return new InsertStatementContext(createShardingSphereMetaData(database), params, insertStatement, DefaultDatabase.LOGIC_NAME);
+ }
+
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
}
@Test
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java
index d08ddcbd125..0c0d8065e54 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java
@@ -18,8 +18,11 @@
package org.apache.shardingsphere.infra.binder.statement.impl;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.constant.ParameterMarkerType;
@@ -60,8 +63,8 @@ import java.util.Collections;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -106,8 +109,7 @@ public final class SelectStatementContextTest {
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(createOrderByItemSegment(INDEX_ORDER_BY))));
selectStatement.setProjections(createProjectionsSegment());
selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("table"))));
- SelectStatementContext selectStatementContext = new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
selectStatementContext.setIndexes(Collections.emptyMap());
assertThat(selectStatementContext.getOrderByContext().getItems().iterator().next().getIndex(), is(4));
}
@@ -144,8 +146,7 @@ public final class SelectStatementContextTest {
tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue(DefaultDatabase.LOGIC_NAME.toUpperCase())));
selectStatement.setFrom(tableSegment);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
- SelectStatementContext selectStatementContext = new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
selectStatementContext.setIndexes(Collections.emptyMap());
assertThat(selectStatementContext.getOrderByContext().getItems().iterator().next().getIndex(), is(1));
}
@@ -179,8 +180,7 @@ public final class SelectStatementContextTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(createOrderByItemSegment(COLUMN_ORDER_BY_WITH_ALIAS))));
selectStatement.setProjections(createProjectionsSegment());
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
- selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
selectStatementContext.setIndexes(Collections.singletonMap("n", 2));
assertThat(selectStatementContext.getOrderByContext().getItems().iterator().next().getIndex(), is(2));
}
@@ -214,8 +214,7 @@ public final class SelectStatementContextTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(createOrderByItemSegment(COLUMN_ORDER_BY_WITHOUT_OWNER_ALIAS))));
selectStatement.setProjections(createProjectionsSegment());
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
- selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
selectStatementContext.setIndexes(Collections.singletonMap("id", 3));
assertThat(selectStatementContext.getOrderByContext().getItems().iterator().next().getIndex(), is(3));
}
@@ -254,8 +253,9 @@ public final class SelectStatementContextTest {
}
private SelectStatementContext createSelectStatementContext(final SelectStatement selectStatement) {
- return new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)),
- Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), mock(ShardingSphereRuleMetaData.class),
+ mock(ConfigurationProperties.class));
+ return new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
}
@Test
@@ -355,8 +355,7 @@ public final class SelectStatementContextTest {
aggregationProjectionSegment.setAlias(new AliasSegment(0, 0, new IdentifierValue("id")));
projectionsSegment.getProjections().add(aggregationProjectionSegment);
selectStatement.setProjections(projectionsSegment);
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database),
- Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
selectStatementContext.setIndexes(Collections.singletonMap("id", 3));
assertThat(selectStatementContext.getOrderByContext().getItems().iterator().next().getIndex(), is(3));
}
@@ -391,8 +390,7 @@ public final class SelectStatementContextTest {
selectStatement.setWhere(whereSegment);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
selectStatement.setProjections(new ProjectionsSegment(0, 0));
- SelectStatementContext actual = new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ SelectStatementContext actual = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
assertThat(actual.getTablesContext().getTableNames(), is(Collections.emptySet()));
assertThat(actual.getAllTables(), is(Collections.emptyList()));
assertThat(actual.getGroupByContext().getItems(), is(Collections.emptyList()));
@@ -442,8 +440,7 @@ public final class SelectStatementContextTest {
projectionsSegment.getProjections().add(projectionSegment);
selectStatement.setProjections(projectionsSegment);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
- assertTrue(
- new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME).isContainsSubquery());
+ assertTrue(new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME).isContainsSubquery());
}
@Test
@@ -487,8 +484,9 @@ public final class SelectStatementContextTest {
ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
projectionsSegment.getProjections().add(projectionSegment);
selectStatement.setProjections(projectionsSegment);
- assertTrue(new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME).isContainsSubquery());
+ ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), mock(ShardingSphereRuleMetaData.class),
+ mock(ConfigurationProperties.class));
+ assertTrue(new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME).isContainsSubquery());
}
@Test
@@ -520,15 +518,15 @@ public final class SelectStatementContextTest {
ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
projectionsSegment.getProjections().add(new ParameterMarkerExpressionSegment(0, 0, 0, ParameterMarkerType.DOLLAR));
selectStatement.setProjections(projectionsSegment);
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), Collections.emptyList(),
- selectStatement, DefaultDatabase.LOGIC_NAME);
+ ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), mock(ShardingSphereRuleMetaData.class),
+ mock(ConfigurationProperties.class));
+ SelectStatementContext selectStatementContext = new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
assertTrue(selectStatementContext.isContainsDollarParameterMarker());
selectStatement.setProjections(new ProjectionsSegment(0, 0));
JoinTableSegment joinTableSegment = new JoinTableSegment();
joinTableSegment.setCondition(new ParameterMarkerExpressionSegment(0, 0, 0, ParameterMarkerType.DOLLAR));
selectStatement.setFrom(joinTableSegment);
- selectStatementContext = new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ selectStatementContext = new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
assertTrue(selectStatementContext.isContainsDollarParameterMarker());
}
@@ -562,11 +560,16 @@ public final class SelectStatementContextTest {
projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.COUNT, "(*)"));
projectionsSegment.getProjections().add(new AggregationDistinctProjectionSegment(0, 10, AggregationType.COUNT, "(1)", "distinctExpression"));
selectStatement.setProjections(projectionsSegment);
- SelectStatementContext selectStatementContext = new SelectStatementContext(
- Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+ ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), mock(ShardingSphereRuleMetaData.class),
+ mock(ConfigurationProperties.class));
+ SelectStatementContext selectStatementContext = new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
assertTrue(selectStatementContext.isContainsPartialDistinctAggregation());
}
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
private OrderByItemSegment createOrderByItemSegment(final String type) {
switch (type) {
case INDEX_ORDER_BY:
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
index cfc9f5e5fb1..81403e74e6d 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
@@ -30,6 +30,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Meta data contexts.
@@ -48,7 +49,7 @@ public final class ShardingSphereMetaData {
}
public ShardingSphereMetaData(final Map<String, ShardingSphereDatabase> databases, final ShardingSphereRuleMetaData globalRuleMetaData, final ConfigurationProperties props) {
- this.databases = databases;
+ this.databases = new ConcurrentHashMap<>(databases.size(), 1);
databases.forEach((key, value) -> this.databases.put(key.toLowerCase(), value));
this.globalRuleMetaData = globalRuleMetaData;
this.props = props;
diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
index a353575669d..9b8df4e199e 100644
--- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
+++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
@@ -194,7 +194,7 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
ShardingSphereSQLParserEngine sqlParserEngine = sqlParserRule.getSQLParserEngine(
DatabaseTypeEngine.getTrunkDatabaseTypeName(metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType()));
sqlStatement = sqlParserEngine.parse(sql, true);
- sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData().getDatabases(), sqlStatement, connection.getDatabaseName());
+ sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData(), sqlStatement, connection.getDatabaseName());
parameterMetaData = new ShardingSphereParameterMetaData(sqlStatement);
statementOption = returnGeneratedKeys ? new StatementOption(true, columns) : new StatementOption(resultSetType, resultSetConcurrency, resultSetHoldability);
executor = new DriverExecutor(connection);
@@ -304,7 +304,7 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
PreparedStatementExecuteQueryCallback callback = new PreparedStatementExecuteQueryCallback(metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType(),
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getResourceMetaData().getStorageTypes(), sqlStatement, SQLExecutorExceptionHandler.isExceptionThrown(),
eventBusContext);
- SQLFederationExecutorContext context = new SQLFederationExecutorContext(false, queryContext, metaDataContexts.getMetaData().getDatabases());
+ SQLFederationExecutorContext context = new SQLFederationExecutorContext(false, queryContext, metaDataContexts.getMetaData());
return executor.getFederationExecutor().executeQuery(createDriverExecutionPrepareEngine(), callback, context);
}
diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
index 5d4c692c862..faa68c222ee 100644
--- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
+++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
@@ -225,7 +225,7 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
StatementExecuteQueryCallback callback = new StatementExecuteQueryCallback(metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType(),
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getResourceMetaData().getStorageTypes(), queryContext.getSqlStatementContext().getSqlStatement(),
SQLExecutorExceptionHandler.isExceptionThrown(), eventBusContext);
- SQLFederationExecutorContext context = new SQLFederationExecutorContext(false, queryContext, metaDataContexts.getMetaData().getDatabases());
+ SQLFederationExecutorContext context = new SQLFederationExecutorContext(false, queryContext, metaDataContexts.getMetaData());
return executor.getFederationExecutor().executeQuery(createDriverExecutionPrepareEngine(), callback, context);
}
@@ -512,7 +512,7 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
SQLParserRule sqlParserRule = metaDataContexts.getMetaData().getGlobalRuleMetaData().getSingleRule(SQLParserRule.class);
SQLStatement sqlStatement = sqlParserRule.getSQLParserEngine(
DatabaseTypeEngine.getTrunkDatabaseTypeName(metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType())).parse(sql, false);
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData().getDatabases(), sqlStatement, connection.getDatabaseName());
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData(), sqlStatement, connection.getDatabaseName());
return new QueryContext(sqlStatementContext, sql, Collections.emptyList());
}
diff --git a/kernel/sql-federation/api/src/main/java/org/apache/shardingsphere/sqlfederation/spi/SQLFederationExecutor.java b/kernel/sql-federation/api/src/main/java/org/apache/shardingsphere/sqlfederation/spi/SQLFederationExecutor.java
index f295a5ad260..9442a637f14 100644
--- a/kernel/sql-federation/api/src/main/java/org/apache/shardingsphere/sqlfederation/spi/SQLFederationExecutor.java
+++ b/kernel/sql-federation/api/src/main/java/org/apache/shardingsphere/sqlfederation/spi/SQLFederationExecutor.java
@@ -39,6 +39,7 @@ public interface SQLFederationExecutor extends TypedSPI, RequiredSPI, AutoClosea
/**
* Init SQL federation executor.
+ *
* @param databaseName database name
* @param schemaName schema name
* @param metaData ShardingSphere meta data
diff --git a/kernel/sql-federation/api/src/main/java/org/apache/shardingsphere/sqlfederation/spi/SQLFederationExecutorContext.java b/kernel/sql-federation/api/src/main/java/org/apache/shardingsphere/sqlfederation/spi/SQLFederationExecutorContext.java
index 4a7abda48c7..147ec19e56a 100644
--- a/kernel/sql-federation/api/src/main/java/org/apache/shardingsphere/sqlfederation/spi/SQLFederationExecutorContext.java
+++ b/kernel/sql-federation/api/src/main/java/org/apache/shardingsphere/sqlfederation/spi/SQLFederationExecutorContext.java
@@ -21,11 +21,10 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.executor.sql.context.ExecutionUnit;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import java.util.Collection;
import java.util.LinkedList;
-import java.util.Map;
/**
* SQL federation executor context.
@@ -40,5 +39,5 @@ public final class SQLFederationExecutorContext {
private final QueryContext queryContext;
- private final Map<String, ShardingSphereDatabase> databases;
+ private final ShardingSphereMetaData metaData;
}
diff --git a/kernel/sql-federation/executor/advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/AdvancedSQLFederationExecutor.java b/kernel/sql-federation/executor/advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/AdvancedSQLFederationExecutor.java
index b6bc3b75b20..4af87e56445 100644
--- a/kernel/sql-federation/executor/advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/AdvancedSQLFederationExecutor.java
+++ b/kernel/sql-federation/executor/advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/AdvancedSQLFederationExecutor.java
@@ -111,7 +111,7 @@ public final class AdvancedSQLFederationExecutor implements SQLFederationExecuto
final JDBCExecutorCallback<? extends ExecuteResult> callback, final SQLFederationExecutorContext federationContext) {
SQLStatementContext<?> sqlStatementContext = federationContext.getQueryContext().getSqlStatementContext();
Preconditions.checkArgument(sqlStatementContext instanceof SelectStatementContext, "SQL statement context must be select statement context.");
- ShardingSphereDatabase database = federationContext.getDatabases().get(databaseName.toLowerCase());
+ ShardingSphereDatabase database = federationContext.getMetaData().getDatabase(databaseName);
ShardingSphereSchema schema = database.getSchema(schemaName);
AbstractSchema sqlFederationSchema = createSQLFederationSchema(prepareEngine, database.getProtocolType(), schema, callback, federationContext);
Map<String, Object> params = createParameters(federationContext.getQueryContext().getParameters());
diff --git a/kernel/sql-federation/executor/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/FilterableTableScanExecutor.java b/kernel/sql-federation/executor/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/FilterableTableScanExecutor.java
index e7b73082e04..f981696e37c 100644
--- a/kernel/sql-federation/executor/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/FilterableTableScanExecutor.java
+++ b/kernel/sql-federation/executor/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/FilterableTableScanExecutor.java
@@ -58,6 +58,7 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecuti
import org.apache.shardingsphere.infra.executor.sql.process.ExecuteProcessEngine;
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.metadata.data.ShardingSphereData;
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereSchemaData;
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData;
@@ -89,7 +90,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -124,8 +124,8 @@ public final class FilterableTableScanExecutor implements TableScanExecutor {
DatabaseType databaseType = DatabaseTypeEngine.getTrunkDatabaseType(optimizerContext.getParserContexts().get(databaseName).getDatabaseType().getType());
SqlString sqlString = createSQLString(table, (FilterableScanNodeExecutorContext) scanContext, SQLDialectFactory.getSQLDialect(databaseType));
SQLFederationExecutorContext federationContext = executorContext.getFederationContext();
- QueryContext queryContext = createQueryContext(federationContext.getDatabases(), sqlString, databaseType);
- ShardingSphereDatabase database = federationContext.getDatabases().get(databaseName.toLowerCase());
+ QueryContext queryContext = createQueryContext(federationContext.getMetaData(), sqlString, databaseType);
+ ShardingSphereDatabase database = federationContext.getMetaData().getDatabase(databaseName);
// TODO need to get session context
ExecutionContext context = new KernelProcessor().generateExecutionContext(queryContext, database, globalRuleMetaData, executorContext.getProps(), new ConnectionContext());
if (federationContext.isPreview()) {
@@ -221,7 +221,7 @@ public final class FilterableTableScanExecutor implements TableScanExecutor {
String databaseName = executorContext.getDatabaseName();
String schemaName = executorContext.getSchemaName();
CalciteConnectionConfig connectionConfig = new CalciteConnectionConfigImpl(optimizerContext.getParserContexts().get(databaseName).getDialectProps());
- ShardingSphereDatabase database = executorContext.getFederationContext().getDatabases().get(databaseName);
+ ShardingSphereDatabase database = executorContext.getFederationContext().getMetaData().getDatabase(databaseName);
CalciteCatalogReader catalogReader = SQLFederationPlannerUtil.createCatalogReader(schemaName,
new FilterableSchema(schemaName, database.getSchema(schemaName), database.getProtocolType(), JAVA_TYPE_FACTORY, null), JAVA_TYPE_FACTORY, connectionConfig);
RelOptCluster relOptCluster = RelOptCluster.create(SQLFederationPlannerUtil.createVolcanoPlanner(), new RexBuilder(JAVA_TYPE_FACTORY));
@@ -264,13 +264,13 @@ public final class FilterableTableScanExecutor implements TableScanExecutor {
return result;
}
- private QueryContext createQueryContext(final Map<String, ShardingSphereDatabase> databases, final SqlString sqlString, final DatabaseType databaseType) {
+ private QueryContext createQueryContext(final ShardingSphereMetaData metaData, final SqlString sqlString, final DatabaseType databaseType) {
String sql = sqlString.getSql().replace("\n", " ");
SQLStatement sqlStatement = new SQLStatementParserEngine(databaseType.getType(),
optimizerContext.getSqlParserRule().getSqlStatementCache(), optimizerContext.getSqlParserRule().getParseTreeCache(),
optimizerContext.getSqlParserRule().isSqlCommentParseEnabled()).parse(sql, false);
List<Object> params = getParameters(sqlString.getDynamicParameters());
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(databases, params, sqlStatement, executorContext.getDatabaseName());
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaData, params, sqlStatement, executorContext.getDatabaseName());
return new QueryContext(sqlStatementContext, sql, params);
}
diff --git a/kernel/sql-federation/executor/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/TranslatableTableScanExecutor.java b/kernel/sql-federation/executor/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/TranslatableTableScanExecutor.java
index f18419ef2ef..5547725b3be 100644
--- a/kernel/sql-federation/executor/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/TranslatableTableScanExecutor.java
+++ b/kernel/sql-federation/executor/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/TranslatableTableScanExecutor.java
@@ -60,6 +60,7 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecuti
import org.apache.shardingsphere.infra.executor.sql.process.ExecuteProcessEngine;
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.metadata.data.ShardingSphereData;
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereSchemaData;
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData;
@@ -92,7 +93,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -128,8 +128,8 @@ public final class TranslatableTableScanExecutor implements TableScanExecutor {
SqlString sqlString = createSQLString(table, (TranslatableScanNodeExecutorContext) scanContext, SQLDialectFactory.getSQLDialect(databaseType));
// TODO replace sql parse with sql convert
SQLFederationExecutorContext federationContext = executorContext.getFederationContext();
- QueryContext queryContext = createQueryContext(federationContext.getDatabases(), sqlString, databaseType);
- ShardingSphereDatabase database = federationContext.getDatabases().get(databaseName.toLowerCase());
+ QueryContext queryContext = createQueryContext(federationContext.getMetaData(), sqlString, databaseType);
+ ShardingSphereDatabase database = federationContext.getMetaData().getDatabase(databaseName);
ExecutionContext context = new KernelProcessor().generateExecutionContext(queryContext, database, globalRuleMetaData, executorContext.getProps(), new ConnectionContext());
if (federationContext.isPreview() || databaseType.getSystemSchemas().contains(schemaName)) {
federationContext.getExecutionUnits().addAll(context.getExecutionUnits());
@@ -223,7 +223,7 @@ public final class TranslatableTableScanExecutor implements TableScanExecutor {
String databaseName = executorContext.getDatabaseName();
String schemaName = executorContext.getSchemaName();
CalciteConnectionConfig connectionConfig = new CalciteConnectionConfigImpl(optimizerContext.getParserContexts().get(databaseName).getDialectProps());
- ShardingSphereDatabase database = executorContext.getFederationContext().getDatabases().get(databaseName);
+ ShardingSphereDatabase database = executorContext.getFederationContext().getMetaData().getDatabase(databaseName);
CalciteCatalogReader catalogReader = SQLFederationPlannerUtil.createCatalogReader(schemaName,
new FilterableSchema(schemaName, database.getSchema(schemaName), database.getProtocolType(), JAVA_TYPE_FACTORY, null), JAVA_TYPE_FACTORY, connectionConfig);
RelOptCluster relOptCluster = RelOptCluster.create(SQLFederationPlannerUtil.createVolcanoPlanner(), new RexBuilder(JAVA_TYPE_FACTORY));
@@ -281,13 +281,13 @@ public final class TranslatableTableScanExecutor implements TableScanExecutor {
return result;
}
- private QueryContext createQueryContext(final Map<String, ShardingSphereDatabase> databases, final SqlString sqlString, final DatabaseType databaseType) {
+ private QueryContext createQueryContext(final ShardingSphereMetaData metaData, final SqlString sqlString, final DatabaseType databaseType) {
String sql = sqlString.getSql().replace("\n", " ");
SQLStatement sqlStatement = new SQLStatementParserEngine(databaseType.getType(),
optimizerContext.getSqlParserRule().getSqlStatementCache(), optimizerContext.getSqlParserRule().getParseTreeCache(),
optimizerContext.getSqlParserRule().isSqlCommentParseEnabled()).parse(sql, false);
List<Object> params = getParameters(sqlString.getDynamicParameters());
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(databases, params, sqlStatement, executorContext.getDatabaseName());
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaData, params, sqlStatement, executorContext.getDatabaseName());
return new QueryContext(sqlStatementContext, sql, params);
}
diff --git a/kernel/sql-federation/executor/original/src/main/java/org/apache/shardingsphere/sqlfederation/original/OriginalSQLFederationExecutor.java b/kernel/sql-federation/executor/original/src/main/java/org/apache/shardingsphere/sqlfederation/original/OriginalSQLFederationExecutor.java
index 2e1fc25be3f..980a8b81dd2 100644
--- a/kernel/sql-federation/executor/original/src/main/java/org/apache/shardingsphere/sqlfederation/original/OriginalSQLFederationExecutor.java
+++ b/kernel/sql-federation/executor/original/src/main/java/org/apache/shardingsphere/sqlfederation/original/OriginalSQLFederationExecutor.java
@@ -123,7 +123,7 @@ public final class OriginalSQLFederationExecutor implements SQLFederationExecuto
TableScanExecutorContext executorContext = new TableScanExecutorContext(databaseName, schemaName, props, federationContext);
FilterableTableScanExecutor executor = new FilterableTableScanExecutor(prepareEngine, jdbcExecutor, callback, optimizerContext, globalRuleMetaData,
executorContext, data, eventBusContext);
- FilterableDatabase database = new FilterableDatabase(federationContext.getDatabases().get(databaseName.toLowerCase()), JAVA_TYPE_FACTORY, executor);
+ FilterableDatabase database = new FilterableDatabase(federationContext.getMetaData().getDatabase(databaseName), JAVA_TYPE_FACTORY, executor);
// TODO support database.schema.table query when switch to AdvancedFederationExecutor, calcite jdbc just support schema.table query now
connection.getRootSchema().add(schemaName, database.getSubSchema(schemaName));
connection.setSchema(schemaName);
diff --git a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java
index 6052aac1d2c..c68a5c6c01a 100644
--- a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java
+++ b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java
@@ -21,7 +21,11 @@ import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import org.apache.shardingsphere.infra.database.DefaultDatabase;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.CommentSegment;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
@@ -40,8 +44,8 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -86,12 +90,16 @@ public final class TrafficRuleTest {
MySQLSelectStatement sqlStatement = mock(MySQLSelectStatement.class);
when(sqlStatement.getCommentSegments()).thenReturn(includeComments ? Collections.singleton(new CommentSegment("/* SHARDINGSPHERE_HINT: USE_TRAFFIC=true */", 0, 0)) : Collections.emptyList());
when(sqlStatement.getProjections()).thenReturn(new ProjectionsSegment(0, 0));
- SQLStatementContext statementContext = new SelectStatementContext(
- Collections.singletonMap("sharding_db", mock(ShardingSphereDatabase.class)), Collections.emptyList(), sqlStatement, "sharding_db");
+ SQLStatementContext statementContext =
+ new SelectStatementContext(createShardingSphereMetaData(mock(ShardingSphereDatabase.class)), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
when(result.getSqlStatementContext()).thenReturn(statementContext);
return result;
}
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
private TrafficRuleConfiguration createTrafficRuleConfig() {
TrafficRuleConfiguration result = new TrafficRuleConfiguration();
result.getTrafficStrategies().add(new TrafficStrategyConfiguration("sql_hint_traffic", Arrays.asList("OLTP", "OLAP"), "sql_hint_match", "random"));
diff --git a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
index 62c14f6c7bf..ceb2ad2423e 100644
--- a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
+++ b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
@@ -160,7 +160,7 @@ public final class JDBCDatabaseCommunicationEngine extends DatabaseCommunication
ProxyJDBCExecutorCallback callback = ProxyJDBCExecutorCallbackFactory.newInstance(getDriverType(), protocolType, storageTypes,
queryContext.getSqlStatementContext().getSqlStatement(), this, isReturnGeneratedKeys, SQLExecutorExceptionHandler.isExceptionThrown(), true);
DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine = createDriverExecutionPrepareEngine(isReturnGeneratedKeys, metaDataContexts);
- SQLFederationExecutorContext context = new SQLFederationExecutorContext(false, queryContext, metaDataContexts.getMetaData().getDatabases());
+ SQLFederationExecutorContext context = new SQLFederationExecutorContext(false, queryContext, metaDataContexts.getMetaData());
return federationExecutor.executeQuery(prepareEngine, callback, context);
}
diff --git a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
index 692c2d3509c..227c5fa5981 100644
--- a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
+++ b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
@@ -45,11 +45,11 @@ import org.apache.shardingsphere.proxy.backend.handler.skip.SkipBackendHandler;
import org.apache.shardingsphere.proxy.backend.handler.transaction.TransactionBackendHandlerFactory;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.EmptyStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.FlushStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.DCLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateDatabaseStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropDatabaseStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.EmptyStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.TCLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtil;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowCreateUserStatement;
@@ -108,7 +108,7 @@ public final class ProxyBackendHandlerFactory {
checkUnsupportedDistSQLStatementInTransaction(sqlStatement, connectionSession);
return DistSQLBackendHandlerFactory.newInstance((DistSQLStatement) sqlStatement, connectionSession);
}
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabases(),
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(),
sqlStatement, connectionSession.getDefaultDatabaseName());
QueryContext queryContext = new QueryContext(sqlStatementContext, sql, Collections.emptyList());
connectionSession.setQueryContext(queryContext);
diff --git a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSetVariableAdminExecutor.java b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSetVariableAdminExecutor.java
index be841d19ad4..04925a2253a 100644
--- a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSetVariableAdminExecutor.java
+++ b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLSetVariableAdminExecutor.java
@@ -81,7 +81,7 @@ public final class MySQLSetVariableAdminExecutor implements DatabaseAdminExecuto
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
SQLParserRule sqlParserRule = metaDataContexts.getMetaData().getGlobalRuleMetaData().getSingleRule(SQLParserRule.class);
SQLStatement sqlStatement = sqlParserRule.getSQLParserEngine(DatabaseTypeFactory.getInstance("MySQL").getType()).parse(sql, false);
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabases(),
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(),
sqlStatement, connectionSession.getDefaultDatabaseName());
DatabaseBackendHandler databaseBackendHandler = DatabaseCommunicationEngineFactory.getInstance()
.newDatabaseCommunicationEngine(new QueryContext(sqlStatementContext, sql, Collections.emptyList()), connectionSession.getBackendConnection(), false);
diff --git a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/UnicastResourceShowExecutor.java b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/UnicastResourceShowExecutor.java
index f392a59e0bf..f5ce7611c65 100644
--- a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/UnicastResourceShowExecutor.java
+++ b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/UnicastResourceShowExecutor.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.proxy.backend.handler.admin.mysql.executor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.dialect.exception.syntax.database.NoDatabaseSelectedException;
import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
@@ -33,13 +34,12 @@ import org.apache.shardingsphere.infra.merge.result.impl.transparent.Transparent
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.dialect.exception.syntax.database.NoDatabaseSelectedException;
import org.apache.shardingsphere.proxy.backend.exception.RuleNotExistedException;
+import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminQueryExecutor;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminQueryExecutor;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import java.sql.SQLException;
@@ -79,7 +79,7 @@ public final class UnicastResourceShowExecutor implements DatabaseAdminQueryExec
}
try {
connectionSession.setCurrentDatabase(databaseName);
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabases(),
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(),
sqlStatement, connectionSession.getDefaultDatabaseName());
databaseCommunicationEngine = databaseCommunicationEngineFactory.newDatabaseCommunicationEngine(new QueryContext(sqlStatementContext, sql, Collections.emptyList()),
connectionSession.getBackendConnection(), false);
diff --git a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/sql/PreviewHandler.java b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/sql/PreviewHandler.java
index cb591e32f59..adac401fcc1 100644
--- a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/sql/PreviewHandler.java
+++ b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/sql/PreviewHandler.java
@@ -99,7 +99,7 @@ public final class PreviewHandler extends SQLRULBackendHandler<PreviewStatement>
ShardingSphereRuleMetaData globalRuleMetaData = metaDataContexts.getMetaData().getGlobalRuleMetaData();
SQLParserRule sqlParserRule = globalRuleMetaData.getSingleRule(SQLParserRule.class);
SQLStatement previewedStatement = sqlParserRule.getSQLParserEngine(databaseType).parse(getSqlStatement().getSql(), false);
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData().getDatabases(), previewedStatement, databaseName);
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData(), previewedStatement, databaseName);
QueryContext queryContext = new QueryContext(sqlStatementContext, getSqlStatement().getSql(), Collections.emptyList());
getConnectionSession().setQueryContext(queryContext);
if (sqlStatementContext instanceof CursorAvailable && sqlStatementContext instanceof CursorDefinitionAware) {
@@ -139,7 +139,7 @@ public final class PreviewHandler extends SQLRULBackendHandler<PreviewStatement>
SQLStatement sqlStatement = queryContext.getSqlStatementContext().getSqlStatement();
boolean isReturnGeneratedKeys = sqlStatement instanceof MySQLInsertStatement;
DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine = createDriverExecutionPrepareEngine(isReturnGeneratedKeys, metaDataContexts);
- SQLFederationExecutorContext context = new SQLFederationExecutorContext(true, queryContext, metaDataContexts.getMetaData().getDatabases());
+ SQLFederationExecutorContext context = new SQLFederationExecutorContext(true, queryContext, metaDataContexts.getMetaData());
ShardingSphereDatabase database = metaDataContexts.getMetaData().getDatabase(getDatabaseName());
String schemaName = queryContext.getSqlStatementContext().getTablesContext().getSchemaName().orElseGet(() -> DatabaseTypeEngine.getDefaultSchemaName(database.getProtocolType(), databaseName));
EventBusContext eventBusContext = ProxyContext.getInstance().getContextManager().getInstanceContext().getEventBusContext();
diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorTest.java
index 98fae15b4f0..5d79c3a7da0 100644
--- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorTest.java
+++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorTest.java
@@ -25,12 +25,14 @@ import org.apache.shardingsphere.infra.binder.statement.ddl.CursorStatementConte
import org.apache.shardingsphere.infra.binder.statement.ddl.TruncateStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.JDBCDriverType;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -206,13 +208,17 @@ public final class ProxySQLExecutorTest extends ProxyContextRestorer {
selectStatement.setProjections(new ProjectionsSegment(0, 0));
OpenGaussCursorStatement sqlStatement = new OpenGaussCursorStatement();
sqlStatement.setSelect(selectStatement);
- SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(),
+ SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(),
selectStatement, DefaultDatabase.LOGIC_NAME);
when(result.getSelectStatementContext()).thenReturn(selectStatementContext);
when(result.getSqlStatement()).thenReturn(sqlStatement);
return result;
}
+ private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
private SelectStatement createSelectStatement() {
SelectStatement result = new MySQLSelectStatement();
result.setFrom(new SimpleTableSegment(new TableNameSegment(10, 13, new IdentifierValue("tbl"))));
@@ -225,7 +231,7 @@ public final class ProxySQLExecutorTest extends ProxyContextRestorer {
sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
- return new InsertStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
+ return new InsertStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
}
private CreateTableStatementContext createPostgreSQLCreateTableStatementContext() {
@@ -239,6 +245,6 @@ public final class ProxySQLExecutorTest extends ProxyContextRestorer {
sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getSchema("public")).thenReturn(mock(ShardingSphereSchema.class));
- return new InsertStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
+ return new InsertStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, DefaultDatabase.LOGIC_NAME);
}
}
diff --git a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java b/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
index 3a7ee8e632b..a2f6362ceff 100644
--- a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
+++ b/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
@@ -31,7 +31,6 @@ import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -45,7 +44,6 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectState
import java.util.Collection;
import java.util.LinkedList;
-import java.util.Map;
/**
* COM_STMT_PREPARE command executor for MySQL.
@@ -70,7 +68,7 @@ public final class MySQLComStmtPrepareExecutor implements CommandExecutor {
}
int projectionCount = getProjectionCount(sqlStatement);
int statementId = MySQLStatementIDGenerator.getInstance().nextStatementId(connectionSession.getConnectionId());
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabases(),
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(),
sqlStatement, connectionSession.getDefaultDatabaseName());
connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, new MySQLServerPreparedStatement(packet.getSql(), sqlStatementContext));
return createPackets(statementId, projectionCount, sqlStatement.getParameterCount());
@@ -87,9 +85,8 @@ public final class MySQLComStmtPrepareExecutor implements CommandExecutor {
private int getProjectionCount(final SQLStatement sqlStatement) {
if (sqlStatement instanceof SelectStatement) {
- Map<String, ShardingSphereDatabase> databases = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabases();
- String databaseName = connectionSession.getDatabaseName();
- SelectStatementContext sqlStatementContext = (SelectStatementContext) SQLStatementContextFactory.newInstance(databases, sqlStatement, databaseName);
+ SelectStatementContext sqlStatementContext = (SelectStatementContext) SQLStatementContextFactory
+ .newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(), sqlStatement, connectionSession.getDatabaseName());
return sqlStatementContext.getProjectionsContext().getExpandProjections().size();
}
return 0;
diff --git a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java b/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
index eaabd64f9f0..3b470f10c4a 100644
--- a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
+++ b/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
@@ -67,7 +67,7 @@ public final class MySQLComFieldListPacketExecutor implements CommandExecutor {
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
SQLParserRule sqlParserRule = metaDataContexts.getMetaData().getGlobalRuleMetaData().getSingleRule(SQLParserRule.class);
SQLStatement sqlStatement = sqlParserRule.getSQLParserEngine(DatabaseTypeFactory.getInstance("MySQL").getType()).parse(sql, false);
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData().getDatabases(), sqlStatement, databaseName);
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData(), sqlStatement, databaseName);
JDBCBackendConnection backendConnection = (JDBCBackendConnection) connectionSession.getBackendConnection();
QueryContext queryContext = new QueryContext(sqlStatementContext, sql, Collections.emptyList());
databaseCommunicationEngine = DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(queryContext, backendConnection, false);
diff --git a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java b/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java
index 3380f612f33..766092f2438 100644
--- a/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java
+++ b/proxy/frontend/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java
@@ -121,7 +121,7 @@ public final class MySQLMultiStatementsHandler implements ProxyBackendHandler {
private QueryContext createQueryContext(final String sql, final SQLStatement sqlStatement) {
SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(
- metaDataContexts.getMetaData().getDatabases(), Collections.emptyList(), sqlStatement, connectionSession.getDatabaseName());
+ metaDataContexts.getMetaData(), Collections.emptyList(), sqlStatement, connectionSession.getDatabaseName());
return new QueryContext(sqlStatementContext, sql, Collections.emptyList());
}
diff --git a/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java b/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java
index 641c2264b5a..54a4eefb7b2 100644
--- a/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java
+++ b/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java
@@ -104,7 +104,7 @@ public final class PostgreSQLBatchedStatementsExecutor {
}
private SQLStatementContext<?> createSQLStatementContext(final List<Object> params) {
- return SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData().getDatabases(), params, preparedStatement.getSqlStatementContext().getSqlStatement(),
+ return SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData(), params, preparedStatement.getSqlStatementContext().getSqlStatement(),
connectionSession.getDatabaseName());
}
diff --git a/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java b/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java
index 9b36e521fea..8ac7d8e3c11 100644
--- a/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java
+++ b/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java
@@ -191,7 +191,7 @@ public final class PostgreSQLComDescribeExecutor implements CommandExecutor {
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
String databaseName = connectionSession.getDatabaseName();
SQLStatementContext<?> sqlStatementContext =
- SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData().getDatabases(), logicPreparedStatement.getSqlStatementContext().getSqlStatement(), databaseName);
+ SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData(), logicPreparedStatement.getSqlStatementContext().getSqlStatement(), databaseName);
QueryContext queryContext = new QueryContext(sqlStatementContext, logicPreparedStatement.getSql(), Collections.emptyList());
ShardingSphereDatabase database = ProxyContext.getInstance().getDatabase(databaseName);
ExecutionContext executionContext = new KernelProcessor().generateExecutionContext(
diff --git a/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java b/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java
index b8cf9991f3a..a0802e26e9e 100644
--- a/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java
+++ b/proxy/frontend/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java
@@ -25,12 +25,12 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.ext
import org.apache.shardingsphere.distsql.parser.statement.DistSQLStatement;
import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.proxy.backend.distsql.DistSQLStatementContext;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.distsql.DistSQLStatementContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.PostgreSQLServerPreparedStatement;
@@ -67,7 +67,7 @@ public final class PostgreSQLComParseExecutor implements CommandExecutor {
}
List<PostgreSQLColumnType> paddedColumnTypes = paddingColumnTypes(sqlStatement.getParameterCount(), packet.readParameterTypes());
SQLStatementContext<?> sqlStatementContext = sqlStatement instanceof DistSQLStatement ? new DistSQLStatementContext((DistSQLStatement) sqlStatement)
- : SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabases(),
+ : SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(),
sqlStatement, connectionSession.getDefaultDatabaseName());
PostgreSQLServerPreparedStatement serverPreparedStatement = new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, paddedColumnTypes);
connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(packet.getStatementId(), serverPreparedStatement);
diff --git a/proxy/frontend/reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/text/fieldlist/ReactiveMySQLComFieldListPacketExecutor.java b/proxy/frontend/reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/text/fieldlist/ReactiveMySQLComFieldListPacketExecutor.java
index 50176706f06..e73ea08f60a 100644
--- a/proxy/frontend/reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/text/fieldlist/ReactiveMySQLComFieldListPacketExecutor.java
+++ b/proxy/frontend/reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/text/fieldlist/ReactiveMySQLComFieldListPacketExecutor.java
@@ -70,7 +70,7 @@ public final class ReactiveMySQLComFieldListPacketExecutor implements ReactiveCo
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
SQLParserRule sqlParserRule = metaDataContexts.getMetaData().getGlobalRuleMetaData().getSingleRule(SQLParserRule.class);
SQLStatement sqlStatement = sqlParserRule.getSQLParserEngine(DatabaseTypeFactory.getInstance("MySQL").getType()).parse(sql, false);
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData().getDatabases(), sqlStatement, databaseName);
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData(), sqlStatement, databaseName);
databaseCommunicationEngine = DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(new QueryContext(sqlStatementContext, sql, Collections.emptyList()),
connectionSession.getBackendConnection(), false);
characterSet = connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get().getId();
diff --git a/test/rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/engine/AbstractSQLRewriterParameterizedTest.java b/test/rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/engine/AbstractSQLRewriterParameterizedTest.java
index 7e55d67840e..1263f890b71 100644
--- a/test/rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/engine/AbstractSQLRewriterParameterizedTest.java
+++ b/test/rewrite/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/engine/AbstractSQLRewriterParameterizedTest.java
@@ -35,6 +35,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -123,7 +124,7 @@ public abstract class AbstractSQLRewriterParameterizedTest {
ShardingSphereDatabase database = new ShardingSphereDatabase(schemaName, databaseType, resourceMetaData, new ShardingSphereRuleMetaData(databaseRules), schemas);
Map<String, ShardingSphereDatabase> databases = new HashMap<>(2, 1);
databases.put(schemaName, database);
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(databases, sqlStatement, schemaName);
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(createShardingSphereMetaData(databases), sqlStatement, schemaName);
if (sqlStatementContext instanceof ParameterAware) {
((ParameterAware) sqlStatementContext).setUpParameters(getTestParameters().getInputParameters());
}
@@ -142,6 +143,10 @@ public abstract class AbstractSQLRewriterParameterizedTest {
: (((RouteSQLRewriteResult) sqlRewriteResult).getSqlRewriteUnits()).values();
}
+ private ShardingSphereMetaData createShardingSphereMetaData(final Map<String, ShardingSphereDatabase> databases) {
+ return new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
+ }
+
private static Map<String, DatabaseType> createStorageTypes(final DatabaseConfiguration databaseConfig, final DatabaseType databaseType) {
Map<String, DatabaseType> result = new LinkedHashMap<>(databaseConfig.getDataSources().size(), 1);
for (Entry<String, DataSource> entry : databaseConfig.getDataSources().entrySet()) {
@@ -152,7 +157,7 @@ public abstract class AbstractSQLRewriterParameterizedTest {
private CursorStatementContext createCursorDefinition(final String schemaName, final Map<String, ShardingSphereDatabase> databases, final SQLStatementParserEngine sqlStatementParserEngine) {
return (CursorStatementContext) SQLStatementContextFactory.newInstance(
- databases, sqlStatementParserEngine.parse("CURSOR t_account_cursor FOR SELECT * FROM t_account WHERE account_id = 100", false), schemaName);
+ createShardingSphereMetaData(databases), sqlStatementParserEngine.parse("CURSOR t_account_cursor FOR SELECT * FROM t_account WHERE account_id = 100", false), schemaName);
}
protected abstract void mockDataSource(Map<String, DataSource> dataSources) throws SQLException;