This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 db6b5e14cf3 Support all query sql use sql federation (#29472)
db6b5e14cf3 is described below
commit db6b5e14cf3ef176c68061eab36eaf705b54d0e0
Author: niu niu <[email protected]>
AuthorDate: Thu Dec 21 11:26:05 2023 +0800
Support all query sql use sql federation (#29472)
* Add sql federation conf
* Add sql federation dist sql
* Support all query sql use sql federation
* Improve sql federation test
* Format code
---
.../api/config/SQLFederationRuleConfiguration.java | 2 ++
.../sqlfederation/engine/SQLFederationEngine.java | 4 ++++
...faultSQLFederationRuleConfigurationBuilder.java | 2 +-
.../config/YamlSQLFederationRuleConfiguration.java | 2 ++
...wYamlSQLFederationRuleConfigurationSwapper.java | 3 ++-
.../YamlSQLFederationRuleConfigurationSwapper.java | 3 ++-
.../engine/SQLFederationEngineTest.java | 27 +++++++++++++++++-----
.../rule/SQLFederationDeciderRuleMatchFixture.java | 2 +-
.../SQLFederationDeciderRuleNotMatchFixture.java | 2 +-
...lSQLFederationRuleConfigurationSwapperTest.java | 2 +-
.../query/ShowSQLFederationRuleExecutor.java | 5 ++--
.../AlterSQLFederationRuleStatementUpdater.java | 3 ++-
.../query/ShowSQLFederationRuleExecutorTest.java | 8 ++++---
...AlterSQLFederationRuleStatementUpdaterTest.java | 3 ++-
.../main/antlr4/imports/sql-federation/Keyword.g4 | 4 ++++
.../antlr4/imports/sql-federation/RALStatement.g4 | 6 ++++-
.../core/SQLFederationDistSQLStatementVisitor.java | 4 ++--
.../updatable/AlterSQLFederationRuleStatement.java | 2 ++
...enGaussSystemCatalogAdminQueryExecutorTest.java | 8 +++----
.../test/it/rewrite/engine/SQLRewriterIT.java | 2 +-
20 files changed, 67 insertions(+), 27 deletions(-)
diff --git
a/kernel/sql-federation/api/src/main/java/org/apache/shardingsphere/sqlfederation/api/config/SQLFederationRuleConfiguration.java
b/kernel/sql-federation/api/src/main/java/org/apache/shardingsphere/sqlfederation/api/config/SQLFederationRuleConfiguration.java
index 757f982f08c..3839344d3d9 100644
---
a/kernel/sql-federation/api/src/main/java/org/apache/shardingsphere/sqlfederation/api/config/SQLFederationRuleConfiguration.java
+++
b/kernel/sql-federation/api/src/main/java/org/apache/shardingsphere/sqlfederation/api/config/SQLFederationRuleConfiguration.java
@@ -33,5 +33,7 @@ public final class SQLFederationRuleConfiguration implements
GlobalRuleConfigura
private final boolean sqlFederationEnabled;
+ private final boolean allQueryUseSQLFederation;
+
private final CacheOption executionPlanCache;
}
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
index 6af50bf6d2e..1e0cdfd114b 100644
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
+++
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
@@ -125,6 +125,10 @@ public final class SQLFederationEngine implements
AutoCloseable {
if (!sqlFederationEnabled || !(sqlStatementContext instanceof
SelectStatementContext)) {
return false;
}
+ boolean allQueryUseSQLFederation =
sqlFederationRule.getConfiguration().isAllQueryUseSQLFederation();
+ if (allQueryUseSQLFederation) {
+ return true;
+ }
Collection<DataNode> includedDataNodes = new HashSet<>();
for (Entry<ShardingSphereRule, SQLFederationDecider> entry :
deciders.entrySet()) {
boolean isUseSQLFederation =
entry.getValue().decide((SelectStatementContext) sqlStatementContext,
parameters, globalRuleMetaData, database, entry.getKey(), includedDataNodes);
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/DefaultSQLFederationRuleConfigurationBuilder.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/DefaultSQLFederationRuleConfigurationBuilder.java
index 0aa2ceb669e..e04e24b4900 100644
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/DefaultSQLFederationRuleConfigurationBuilder.java
+++
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/DefaultSQLFederationRuleConfigurationBuilder.java
@@ -31,7 +31,7 @@ public final class
DefaultSQLFederationRuleConfigurationBuilder implements Defau
@Override
public SQLFederationRuleConfiguration build() {
- return new SQLFederationRuleConfiguration(false,
DEFAULT_EXECUTION_PLAN_CACHE_OPTION);
+ return new SQLFederationRuleConfiguration(false, false,
DEFAULT_EXECUTION_PLAN_CACHE_OPTION);
}
@Override
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/config/YamlSQLFederationRuleConfiguration.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/config/YamlSQLFederationRuleConfiguration.java
index be390571b3c..a8f52bf1b06 100644
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/config/YamlSQLFederationRuleConfiguration.java
+++
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/config/YamlSQLFederationRuleConfiguration.java
@@ -31,6 +31,8 @@ public final class YamlSQLFederationRuleConfiguration
implements YamlGlobalRuleC
private boolean sqlFederationEnabled;
+ private boolean allQueryUseSQLFederation;
+
private YamlSQLFederationExecutionPlanCacheRuleConfiguration
executionPlanCache;
@Override
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapper.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapper.java
index bfcbfe56053..30a7159a03e 100644
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapper.java
+++
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapper.java
@@ -46,6 +46,7 @@ public final class
NewYamlSQLFederationRuleConfigurationSwapper implements NewYa
private YamlSQLFederationRuleConfiguration swapToYamlConfiguration(final
SQLFederationRuleConfiguration data) {
YamlSQLFederationRuleConfiguration result = new
YamlSQLFederationRuleConfiguration();
result.setSqlFederationEnabled(data.isSqlFederationEnabled());
+ result.setAllQueryUseSQLFederation(data.isAllQueryUseSQLFederation());
result.setExecutionPlanCache(executionPlanCacheConfigSwapper.swapToYamlConfiguration(data.getExecutionPlanCache()));
return result;
}
@@ -64,7 +65,7 @@ public final class
NewYamlSQLFederationRuleConfigurationSwapper implements NewYa
private SQLFederationRuleConfiguration swapToObject(final
YamlSQLFederationRuleConfiguration yamlConfig) {
CacheOption executionPlanCacheConfig =
executionPlanCacheConfigSwapper.swapToObject(yamlConfig.getExecutionPlanCache());
- return new
SQLFederationRuleConfiguration(yamlConfig.isSqlFederationEnabled(),
executionPlanCacheConfig);
+ return new
SQLFederationRuleConfiguration(yamlConfig.isSqlFederationEnabled(),
yamlConfig.isAllQueryUseSQLFederation(), executionPlanCacheConfig);
}
@Override
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/YamlSQLFederationRuleConfigurationSwapper.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/YamlSQLFederationRuleConfigurationSwapper.java
index d1439c6d619..3660bd80694 100644
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/YamlSQLFederationRuleConfigurationSwapper.java
+++
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/YamlSQLFederationRuleConfigurationSwapper.java
@@ -34,6 +34,7 @@ public final class YamlSQLFederationRuleConfigurationSwapper
implements YamlRule
public YamlSQLFederationRuleConfiguration swapToYamlConfiguration(final
SQLFederationRuleConfiguration data) {
YamlSQLFederationRuleConfiguration result = new
YamlSQLFederationRuleConfiguration();
result.setSqlFederationEnabled(data.isSqlFederationEnabled());
+ result.setAllQueryUseSQLFederation(data.isAllQueryUseSQLFederation());
result.setExecutionPlanCache(executionPlanCacheConfigSwapper.swapToYamlConfiguration(data.getExecutionPlanCache()));
return result;
}
@@ -41,7 +42,7 @@ public final class YamlSQLFederationRuleConfigurationSwapper
implements YamlRule
@Override
public SQLFederationRuleConfiguration swapToObject(final
YamlSQLFederationRuleConfiguration yamlConfig) {
CacheOption executionPlanCacheConfig =
executionPlanCacheConfigSwapper.swapToObject(yamlConfig.getExecutionPlanCache());
- return new
SQLFederationRuleConfiguration(yamlConfig.isSqlFederationEnabled(),
executionPlanCacheConfig);
+ return new
SQLFederationRuleConfiguration(yamlConfig.isSqlFederationEnabled(),
yamlConfig.isAllQueryUseSQLFederation(), executionPlanCacheConfig);
}
@Override
diff --git
a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngineTest.java
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngineTest.java
index 8fada6cf8a1..8acd110e70c 100644
---
a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngineTest.java
+++
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngineTest.java
@@ -63,7 +63,7 @@ class SQLFederationEngineTest {
@Test
void assertDecideWhenSelectStatementContainsSystemSchema() throws
SQLException {
Collection<ShardingSphereRule> globalRules =
- Collections.singleton(new SQLFederationRule(new
SQLFederationRuleConfiguration(false, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
+ Collections.singleton(new SQLFederationRule(new
SQLFederationRuleConfiguration(false, false, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
SQLFederationEngine engine = createSQLFederationEngine(globalRules,
Collections.emptyList());
SelectStatementContext sqlStatementContext =
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
@@ -83,7 +83,8 @@ class SQLFederationEngineTest {
@Test
void assertDecideWhenNotConfigSqlFederationEnabled() throws SQLException {
Collection<ShardingSphereRule> globalRules =
- Collections.singletonList(new SQLFederationRule(new
SQLFederationRuleConfiguration(false, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
+ Collections
+ .singletonList(new SQLFederationRule(new
SQLFederationRuleConfiguration(false, false, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
SQLFederationEngine engine = createSQLFederationEngine(globalRules,
Collections.emptyList());
ShardingSphereDatabase database = new
ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
databaseType, mock(ResourceMetaData.class,
RETURNS_DEEP_STUBS), new RuleMetaData(globalRules), Collections.emptyMap());
@@ -92,10 +93,24 @@ class SQLFederationEngineTest {
engine.close();
}
+ @Test
+ void assertDecideWhenConfigAllQueryUseSQLFederation() throws SQLException {
+ Collection<ShardingSphereRule> globalRules =
+ Collections.singletonList(new SQLFederationRule(new
SQLFederationRuleConfiguration(true, true, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
+ SQLFederationEngine engine = createSQLFederationEngine(globalRules,
Collections.emptyList());
+ ShardingSphereDatabase database = new
ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
+ databaseType, mock(ResourceMetaData.class,
RETURNS_DEEP_STUBS), new RuleMetaData(globalRules), Collections.emptyMap());
+ RuleMetaData globalRuleMetaData = new RuleMetaData(globalRules);
+ SelectStatementContext selectStatementContext =
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
+
when(selectStatementContext.getDatabaseType()).thenReturn(databaseType);
+ assertTrue(engine.decide(selectStatementContext,
Collections.emptyList(), database, globalRuleMetaData));
+ engine.close();
+ }
+
@Test
void assertDecideWhenExecuteNotSelectStatement() throws SQLException {
Collection<ShardingSphereRule> globalRules =
- Collections.singletonList(new SQLFederationRule(new
SQLFederationRuleConfiguration(true, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
+ Collections.singletonList(new SQLFederationRule(new
SQLFederationRuleConfiguration(true, false, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
SQLFederationEngine engine = createSQLFederationEngine(globalRules,
Collections.emptyList());
ShardingSphereDatabase database = new
ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
databaseType, mock(ResourceMetaData.class,
RETURNS_DEEP_STUBS), new RuleMetaData(globalRules), Collections.emptyMap());
@@ -107,7 +122,7 @@ class SQLFederationEngineTest {
@Test
void assertDecideWhenConfigSingleMatchedRule() throws SQLException {
Collection<ShardingSphereRule> globalRules =
- Collections.singletonList(new SQLFederationRule(new
SQLFederationRuleConfiguration(true, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
+ Collections.singletonList(new SQLFederationRule(new
SQLFederationRuleConfiguration(true, false, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
Collection<ShardingSphereRule> databaseRules =
Collections.singletonList(new SQLFederationDeciderRuleMatchFixture());
SQLFederationEngine engine = createSQLFederationEngine(globalRules,
databaseRules);
ShardingSphereDatabase database = new
ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
@@ -122,7 +137,7 @@ class SQLFederationEngineTest {
@Test
void assertDecideWhenConfigSingleNotMatchedRule() throws SQLException {
Collection<ShardingSphereRule> globalRules =
- Collections.singletonList(new SQLFederationRule(new
SQLFederationRuleConfiguration(true, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
+ Collections.singletonList(new SQLFederationRule(new
SQLFederationRuleConfiguration(true, false, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
Collection<ShardingSphereRule> databaseRules =
Collections.singletonList(new SQLFederationDeciderRuleNotMatchFixture());
SQLFederationEngine engine = createSQLFederationEngine(globalRules,
databaseRules);
ShardingSphereDatabase database = new
ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME,
@@ -136,7 +151,7 @@ class SQLFederationEngineTest {
@Test
void assertDecideWhenConfigMultiRule() throws SQLException {
Collection<ShardingSphereRule> globalRules =
- Collections.singletonList(new SQLFederationRule(new
SQLFederationRuleConfiguration(true, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
+ Collections.singletonList(new SQLFederationRule(new
SQLFederationRuleConfiguration(true, false, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
Collection<ShardingSphereRule> databaseRules = Arrays.asList(new
SQLFederationDeciderRuleNotMatchFixture(),
new SQLFederationDeciderRuleMatchFixture());
SQLFederationEngine engine = createSQLFederationEngine(globalRules,
databaseRules);
diff --git
a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleMatchFixture.java
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleMatchFixture.java
index fdbce39cfc6..f2b93e1548c 100644
---
a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleMatchFixture.java
+++
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleMatchFixture.java
@@ -28,6 +28,6 @@ public final class SQLFederationDeciderRuleMatchFixture
implements ShardingSpher
@Override
public RuleConfiguration getConfiguration() {
- return new SQLFederationRuleConfiguration(true,
mock(CacheOption.class));
+ return new SQLFederationRuleConfiguration(true, false,
mock(CacheOption.class));
}
}
diff --git
a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleNotMatchFixture.java
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleNotMatchFixture.java
index e32f797264a..6fff1d1a902 100644
---
a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleNotMatchFixture.java
+++
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleNotMatchFixture.java
@@ -28,6 +28,6 @@ public final class SQLFederationDeciderRuleNotMatchFixture
implements ShardingSp
@Override
public RuleConfiguration getConfiguration() {
- return new SQLFederationRuleConfiguration(false,
mock(CacheOption.class));
+ return new SQLFederationRuleConfiguration(false, false,
mock(CacheOption.class));
}
}
diff --git
a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapperTest.java
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapperTest.java
index eaaab18ed7a..4d63ccb3d3b 100644
---
a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapperTest.java
+++
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapperTest.java
@@ -31,6 +31,6 @@ class NewYamlSQLFederationRuleConfigurationSwapperTest {
@Test
void assertSwapToDataNodes() {
- assertThat(swapper.swapToDataNodes(new
SQLFederationRuleConfiguration(false, new CacheOption(0,
0))).iterator().next().getKey(), is("sql_federation"));
+ assertThat(swapper.swapToDataNodes(new
SQLFederationRuleConfiguration(false, false, new CacheOption(0,
0))).iterator().next().getKey(), is("sql_federation"));
}
}
diff --git
a/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutor.java
b/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutor.java
index f91ae15b29a..8ce03f8f060 100644
---
a/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutor.java
+++
b/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutor.java
@@ -37,14 +37,15 @@ public final class ShowSQLFederationRuleExecutor implements
MetaDataRequiredQuer
public Collection<LocalDataQueryResultRow> getRows(final
ShardingSphereMetaData metaData, final ShowSQLFederationRuleStatement
sqlStatement) {
SQLFederationRuleConfiguration ruleConfig =
metaData.getGlobalRuleMetaData().getSingleRule(SQLFederationRule.class).getConfiguration();
String sqlFederationEnabled =
String.valueOf(ruleConfig.isSqlFederationEnabled());
+ String allQueryUseSQLFederation =
String.valueOf(ruleConfig.isAllQueryUseSQLFederation());
String executionPlanCache = null != ruleConfig.getExecutionPlanCache()
? ruleConfig.getExecutionPlanCache().toString() : "";
- LocalDataQueryResultRow row = new
LocalDataQueryResultRow(sqlFederationEnabled, executionPlanCache);
+ LocalDataQueryResultRow row = new
LocalDataQueryResultRow(sqlFederationEnabled, allQueryUseSQLFederation,
executionPlanCache);
return Collections.singleton(row);
}
@Override
public Collection<String> getColumnNames() {
- return Arrays.asList("sql_federation_enabled", "execution_plan_cache");
+ return Arrays.asList("sql_federation_enabled",
"all_query_use_sql_federation", "execution_plan_cache");
}
@Override
diff --git
a/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleStatementUpdater.java
b/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleStatementUpdater.java
index 8d0728934fc..ec499189669 100644
---
a/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleStatementUpdater.java
+++
b/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleStatementUpdater.java
@@ -35,10 +35,11 @@ public final class AlterSQLFederationRuleStatementUpdater
implements GlobalRuleR
@Override
public SQLFederationRuleConfiguration buildAlteredRuleConfiguration(final
SQLFederationRuleConfiguration currentRuleConfig, final
AlterSQLFederationRuleStatement sqlStatement) {
boolean sqlFederationEnabled = null ==
sqlStatement.getSqlFederationEnabled() ?
currentRuleConfig.isSqlFederationEnabled() :
sqlStatement.getSqlFederationEnabled();
+ boolean allQueryUseSQLFederation = null ==
sqlStatement.getAllQueryUseSQLFederation() ?
currentRuleConfig.isAllQueryUseSQLFederation() :
sqlStatement.getAllQueryUseSQLFederation();
CacheOption executionPlanCache = null ==
sqlStatement.getExecutionPlanCache()
? currentRuleConfig.getExecutionPlanCache()
: createCacheOption(currentRuleConfig.getExecutionPlanCache(),
sqlStatement.getExecutionPlanCache());
- return new SQLFederationRuleConfiguration(sqlFederationEnabled,
executionPlanCache);
+ return new SQLFederationRuleConfiguration(sqlFederationEnabled,
allQueryUseSQLFederation, executionPlanCache);
}
private CacheOption createCacheOption(final CacheOption cacheOption, final
CacheOptionSegment segment) {
diff --git
a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
index 07168ce8336..6d3c7b9f3bf 100644
---
a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
+++
b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
@@ -50,22 +50,24 @@ class ShowSQLFederationRuleExecutorTest {
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
LocalDataQueryResultRow row = iterator.next();
assertThat(row.getCell(1), is("true"));
- assertThat(row.getCell(2), is("initialCapacity: 2000, maximumSize:
65535"));
+ assertThat(row.getCell(2), is("true"));
+ assertThat(row.getCell(3), is("initialCapacity: 2000, maximumSize:
65535"));
}
@Test
void assertGetColumnNames() {
ShowSQLFederationRuleExecutor executor = new
ShowSQLFederationRuleExecutor();
Collection<String> columns = executor.getColumnNames();
- assertThat(columns.size(), is(2));
+ assertThat(columns.size(), is(3));
Iterator<String> iterator = columns.iterator();
assertThat(iterator.next(), is("sql_federation_enabled"));
+ assertThat(iterator.next(), is("all_query_use_sql_federation"));
assertThat(iterator.next(), is("execution_plan_cache"));
}
private ShardingSphereMetaData mockMetaData() {
SQLFederationRule sqlFederationRule = mock(SQLFederationRule.class);
- when(sqlFederationRule.getConfiguration()).thenReturn(new
SQLFederationRuleConfiguration(true, new CacheOption(2000, 65535L)));
+ when(sqlFederationRule.getConfiguration()).thenReturn(new
SQLFederationRuleConfiguration(true, true, new CacheOption(2000, 65535L)));
return new ShardingSphereMetaData(new LinkedHashMap<>(),
mock(ResourceMetaData.class),
new RuleMetaData(Collections.singleton(sqlFederationRule)),
new ConfigurationProperties(new Properties()));
}
diff --git
a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleStatementUpdaterTest.java
b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleStatementUpdaterTest.java
index 93d092e4195..16db4ecae35 100644
---
a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleStatementUpdaterTest.java
+++
b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleStatementUpdaterTest.java
@@ -32,9 +32,10 @@ class AlterSQLFederationRuleStatementUpdaterTest {
@Test
void assertExecute() {
AlterSQLFederationRuleStatementUpdater updater = new
AlterSQLFederationRuleStatementUpdater();
- AlterSQLFederationRuleStatement sqlStatement = new
AlterSQLFederationRuleStatement(true, new CacheOptionSegment(64, 512L));
+ AlterSQLFederationRuleStatement sqlStatement = new
AlterSQLFederationRuleStatement(true, true, new CacheOptionSegment(64, 512L));
SQLFederationRuleConfiguration actual =
updater.buildAlteredRuleConfiguration(getSQLFederationRuleConfiguration(),
sqlStatement);
assertTrue(actual.isSqlFederationEnabled());
+ assertTrue(actual.isAllQueryUseSQLFederation());
assertThat(actual.getExecutionPlanCache().getInitialCapacity(),
is(64));
assertThat(actual.getExecutionPlanCache().getMaximumSize(), is(512L));
}
diff --git
a/kernel/sql-federation/distsql/parser/src/main/antlr4/imports/sql-federation/Keyword.g4
b/kernel/sql-federation/distsql/parser/src/main/antlr4/imports/sql-federation/Keyword.g4
index 3c99fc9a5d0..bbd70eb7a78 100644
---
a/kernel/sql-federation/distsql/parser/src/main/antlr4/imports/sql-federation/Keyword.g4
+++
b/kernel/sql-federation/distsql/parser/src/main/antlr4/imports/sql-federation/Keyword.g4
@@ -43,6 +43,10 @@ SQL_FEDERATION_ENABLED
: S Q L UL_ F E D E R A T I O N UL_ E N A B L E D
;
+ALL_QUERY_USE_SQL_FEDERATION
+ : A L L UL_ Q U E R Y UL_ U S E UL_ S Q L UL_ F E D E R A T I O N
+ ;
+
EXECUTION_PLAN_CACHE
: E X E C U T I O N UL_ P L A N UL_ C A C H E
;
diff --git
a/kernel/sql-federation/distsql/parser/src/main/antlr4/imports/sql-federation/RALStatement.g4
b/kernel/sql-federation/distsql/parser/src/main/antlr4/imports/sql-federation/RALStatement.g4
index 88a916f0aa6..f8e96723b32 100644
---
a/kernel/sql-federation/distsql/parser/src/main/antlr4/imports/sql-federation/RALStatement.g4
+++
b/kernel/sql-federation/distsql/parser/src/main/antlr4/imports/sql-federation/RALStatement.g4
@@ -28,13 +28,17 @@ alterSQLFederationRule
;
sqlFederationRuleDefinition
- : LP_ sqlFederationEnabled? (COMMA_? executionPlanCache)? RP_
+ : LP_ sqlFederationEnabled? allQueryUseSQLFederation? (COMMA_?
executionPlanCache)? RP_
;
sqlFederationEnabled
: SQL_FEDERATION_ENABLED EQ_ boolean_
;
+allQueryUseSQLFederation
+ : ALL_QUERY_USE_SQL_FEDERATION EQ_ boolean_
+ ;
+
executionPlanCache
: EXECUTION_PLAN_CACHE LP_ cacheOption RP_
;
diff --git
a/kernel/sql-federation/distsql/parser/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/parser/core/SQLFederationDistSQLStatementVisitor.java
b/kernel/sql-federation/distsql/parser/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/parser/core/SQLFederationDistSQLStatementVisitor.java
index adfd60efab8..5909767f1cf 100644
---
a/kernel/sql-federation/distsql/parser/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/parser/core/SQLFederationDistSQLStatementVisitor.java
+++
b/kernel/sql-federation/distsql/parser/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/parser/core/SQLFederationDistSQLStatementVisitor.java
@@ -48,8 +48,9 @@ public final class SQLFederationDistSQLStatementVisitor
extends SQLFederationDis
@Override
public ASTNode visitSqlFederationRuleDefinition(final
SqlFederationRuleDefinitionContext ctx) {
Boolean sqlFederationEnabled = null == ctx.sqlFederationEnabled() ?
null :
Boolean.parseBoolean(getIdentifierValue(ctx.sqlFederationEnabled().boolean_()));
+ Boolean allQueryUseSQLFederation = null ==
ctx.allQueryUseSQLFederation() ? null :
Boolean.parseBoolean(getIdentifierValue(ctx.allQueryUseSQLFederation().boolean_()));
CacheOptionSegment executionPlanCache = null ==
ctx.executionPlanCache() ? null :
visitCacheOption(ctx.executionPlanCache().cacheOption());
- return new AlterSQLFederationRuleStatement(sqlFederationEnabled,
executionPlanCache);
+ return new AlterSQLFederationRuleStatement(sqlFederationEnabled,
allQueryUseSQLFederation, executionPlanCache);
}
@Override
@@ -62,5 +63,4 @@ public final class SQLFederationDistSQLStatementVisitor
extends SQLFederationDis
private String getIdentifierValue(final ParseTree context) {
return null == context ? null : new
IdentifierValue(context.getText()).getValue();
}
-
}
diff --git
a/kernel/sql-federation/distsql/statement/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/statement/updatable/AlterSQLFederationRuleStatement.java
b/kernel/sql-federation/distsql/statement/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/statement/updatable/AlterSQLFederationRuleStatement.java
index 780e801f338..2cb743a5bd8 100644
---
a/kernel/sql-federation/distsql/statement/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/statement/updatable/AlterSQLFederationRuleStatement.java
+++
b/kernel/sql-federation/distsql/statement/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/statement/updatable/AlterSQLFederationRuleStatement.java
@@ -31,5 +31,7 @@ public final class AlterSQLFederationRuleStatement extends
UpdatableGlobalRuleRA
private final Boolean sqlFederationEnabled;
+ private final Boolean allQueryUseSQLFederation;
+
private final CacheOptionSegment executionPlanCache;
}
diff --git
a/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutorTest.java
b/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutorTest.java
index 4a5749b1734..b8e9927ca34 100644
---
a/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutorTest.java
+++
b/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutorTest.java
@@ -82,7 +82,7 @@ class OpenGaussSystemCatalogAdminQueryExecutorTest {
ConnectionSession connectionSession = mock(ConnectionSession.class);
when(connectionSession.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
"openGauss"));
Map<String, ShardingSphereDatabase> databases =
createShardingSphereDatabaseMap();
- SQLFederationRule sqlFederationRule = new SQLFederationRule(new
SQLFederationRuleConfiguration(false, new CacheOption(1, 1)), databases, props);
+ SQLFederationRule sqlFederationRule = new SQLFederationRule(new
SQLFederationRuleConfiguration(false, false, new CacheOption(1, 1)), databases,
props);
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(mock(RuleMetaData.class));
OpenGaussSelectStatement sqlStatement =
createSelectStatementForPgDatabase();
ShardingSphereMetaData metaData =
@@ -146,7 +146,7 @@ class OpenGaussSystemCatalogAdminQueryExecutorTest {
ConfigurationProperties props = new ConfigurationProperties(new
Properties());
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps()).thenReturn(props);
Map<String, ShardingSphereDatabase> databases =
createShardingSphereDatabaseMap();
- SQLFederationRule sqlFederationRule = new SQLFederationRule(new
SQLFederationRuleConfiguration(false, new CacheOption(1, 1)), databases, props);
+ SQLFederationRule sqlFederationRule = new SQLFederationRule(new
SQLFederationRuleConfiguration(false, false, new CacheOption(1, 1)), databases,
props);
OpenGaussSelectStatement sqlStatement =
createSelectStatementForVersion();
ShardingSphereMetaData metaData =
new ShardingSphereMetaData(databases,
mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new
RuleMetaData(Collections.singletonList(sqlFederationRule)), props);
@@ -180,7 +180,7 @@ class OpenGaussSystemCatalogAdminQueryExecutorTest {
ConfigurationProperties props = new ConfigurationProperties(new
Properties());
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps()).thenReturn(props);
Map<String, ShardingSphereDatabase> databases =
createShardingSphereDatabaseMap();
- SQLFederationRule sqlFederationRule = new SQLFederationRule(new
SQLFederationRuleConfiguration(false, new CacheOption(1, 1)), databases, props);
+ SQLFederationRule sqlFederationRule = new SQLFederationRule(new
SQLFederationRuleConfiguration(false, false, new CacheOption(1, 1)), databases,
props);
OpenGaussSelectStatement sqlStatement =
createSelectStatementForGsPasswordDeadlineAndIntervalToNum();
ShardingSphereMetaData metaData =
new ShardingSphereMetaData(databases,
mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new
RuleMetaData(Collections.singletonList(sqlFederationRule)), props);
@@ -216,7 +216,7 @@ class OpenGaussSystemCatalogAdminQueryExecutorTest {
ConfigurationProperties props = new ConfigurationProperties(new
Properties());
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps()).thenReturn(props);
Map<String, ShardingSphereDatabase> databases =
createShardingSphereDatabaseMap();
- SQLFederationRule sqlFederationRule = new SQLFederationRule(new
SQLFederationRuleConfiguration(false, new CacheOption(1, 1)), databases, props);
+ SQLFederationRule sqlFederationRule = new SQLFederationRule(new
SQLFederationRuleConfiguration(false, false, new CacheOption(1, 1)), databases,
props);
OpenGaussSelectStatement sqlStatement =
createSelectStatementForGsPasswordNotifyTime();
ShardingSphereMetaData metaData =
new ShardingSphereMetaData(databases,
mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new
RuleMetaData(Collections.singletonList(sqlFederationRule)), props);
diff --git
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/SQLRewriterIT.java
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/SQLRewriterIT.java
index 249e2592d92..001b719aac6 100644
---
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/SQLRewriterIT.java
+++
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/SQLRewriterIT.java
@@ -165,7 +165,7 @@ public abstract class SQLRewriterIT {
private Collection<ShardingSphereRule> createGlobalRules() {
Collection<ShardingSphereRule> result = new LinkedList<>();
result.add(new SQLTranslatorRule(new
DefaultSQLTranslatorRuleConfigurationBuilder().build()));
- result.add(new SQLFederationRule(new
SQLFederationRuleConfiguration(false, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
+ result.add(new SQLFederationRule(new
SQLFederationRuleConfiguration(false, false, mock(CacheOption.class)),
Collections.emptyMap(), mock(ConfigurationProperties.class)));
result.add(new
TimestampServiceRule(mock(TimestampServiceRuleConfiguration.class)));
return result;
}