This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 349735f7106 Fix npe when execute use database when database doesn't
contains datasource (#17946)
349735f7106 is described below
commit 349735f7106c09623e91ccef247c22cdc1db1072
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Wed May 25 19:40:55 2022 +0800
Fix npe when execute use database when database doesn't contains datasource
(#17946)
---
.../algorithm/sharding/datetime/IntervalShardingAlgorithm.java | 2 +-
.../algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java | 6 +++---
.../optimizer/context/parser/OptimizerParserContextFactory.java | 4 ++--
.../proxy/backend/text/admin/DatabaseAdminQueryBackendHandler.java | 5 ++---
4 files changed, 8 insertions(+), 9 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
index 4b5d4c7879d..af9a905fb28 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
@@ -220,7 +220,7 @@ public final class IntervalShardingAlgorithm implements
StandardShardingAlgorith
private LocalTime parseLocalTime(final Comparable<?> endpoint) {
return LocalTime.parse(getDateTimeText(endpoint).substring(0,
dateTimePatternLength), dateTimeFormatter);
}
-
+
private String getDateTimeText(final Comparable<?> endpoint) {
if (endpoint instanceof LocalDateTime || endpoint instanceof
ZonedDateTime
|| endpoint instanceof OffsetDateTime || endpoint instanceof
LocalTime
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java
index afe9249840d..5c11b55ec0f 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithmTest.java
@@ -57,7 +57,7 @@ public final class IntervalShardingAlgorithmTest {
private final Collection<String> availableTablesForDayDataSources = new
LinkedList<>();
private final Collection<String> availableTablesForJDBCDateDataSources =
new LinkedList<>();
-
+
private final Collection<String> availableTablesForJDBCTimeDataSources =
new LinkedList<>();
private final Collection<String>
availableTablesForDayWithMillisecondDataSources = new LinkedList<>();
@@ -69,9 +69,9 @@ public final class IntervalShardingAlgorithmTest {
private IntervalShardingAlgorithm shardingAlgorithmByDay;
private IntervalShardingAlgorithm shardingAlgorithmByJDBCDate;
-
+
private IntervalShardingAlgorithm shardingAlgorithmByJDBCTime;
-
+
private IntervalShardingAlgorithm shardingAlgorithmByDayWithMillisecond;
@Before
diff --git
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/OptimizerParserContextFactory.java
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/OptimizerParserContextFactory.java
index ebcd517d8fd..0ca286cba8c 100644
---
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/OptimizerParserContextFactory.java
+++
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/context/parser/OptimizerParserContextFactory.java
@@ -21,8 +21,8 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.calcite.config.CalciteConnectionProperty;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.federation.optimizer.context.parser.dialect.OptimizerSQLDialectBuilderFactory;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabase;
import java.util.HashMap;
import java.util.Map;
@@ -45,7 +45,7 @@ public final class OptimizerParserContextFactory {
public static Map<String, OptimizerParserContext> create(final Map<String,
ShardingSphereDatabase> databaseMap) {
Map<String, OptimizerParserContext> result = new HashMap<>();
for (Entry<String, ShardingSphereDatabase> entry :
databaseMap.entrySet()) {
- DatabaseType databaseType =
entry.getValue().getResource().getDatabaseType();
+ DatabaseType databaseType = entry.getValue().getProtocolType();
result.put(entry.getKey(), new
OptimizerParserContext(databaseType, createSQLDialectProperties(databaseType)));
}
return result;
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandler.java
index 2a50f02fa16..eff6a21c613 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandler.java
@@ -26,9 +26,9 @@ import
org.apache.shardingsphere.infra.metadata.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
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.QueryHeaderBuilderEngine;
import
org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
-import
org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import
org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminQueryExecutor;
@@ -64,8 +64,7 @@ public final class DatabaseAdminQueryBackendHandler
implements TextProtocolBacke
private List<QueryHeader> createResponseHeader() throws SQLException {
List<QueryHeader> result = new
ArrayList<>(queryResultMetaData.getColumnCount());
ShardingSphereDatabase database = null ==
connectionSession.getDatabaseName() ? null :
ProxyContext.getInstance().getDatabase(connectionSession.getDatabaseName());
- DatabaseType databaseType = null == database ?
connectionSession.getDatabaseType()
- :
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getDatabaseMetaData(database.getName()).getResource().getDatabaseType();
+ DatabaseType databaseType = null == database ?
connectionSession.getDatabaseType() : database.getProtocolType();
QueryHeaderBuilderEngine queryHeaderBuilderEngine = new
QueryHeaderBuilderEngine(databaseType);
LazyInitializer<DataNodeContainedRule> dataNodeContainedRule =
getDataNodeContainedRuleLazyInitializer(database);
for (int columnIndex = 1; columnIndex <=
queryResultMetaData.getColumnCount(); columnIndex++) {