This is an automated email from the ASF dual-hosted git repository.

sunnianjun 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 b4dbdfbddf8 Remove useless DatabaseTypeEngine.getTrunkDatabaseType() 
(#27392)
b4dbdfbddf8 is described below

commit b4dbdfbddf80b9a2f6a3db3eec857ac38b8a79f4
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jul 23 23:27:53 2023 +0800

    Remove useless DatabaseTypeEngine.getTrunkDatabaseType() (#27392)
    
    * Fix sonar issue of ConfigurationContextManager
    
    * Refactor EnumerableScanExecutor
    
    * Remove useless MariaDBOptimizerBuilder
    
    * Refactor OptimizerParserContextFactory
    
    * Refactor SQLFederationPlannerUtils
    
    * Remove useless DatabaseTypeEngine.getTrunkDatabaseType()
    
    * Remove useless DatabaseTypeEngine.getTrunkDatabaseType()
---
 .../infra/database/DatabaseTypeEngine.java         | 11 -----
 .../infra/database/DatabaseTypeEngineTest.java     | 10 -----
 .../parser/OptimizerParserContextFactory.java      | 13 ++----
 .../dialect/impl/MariaDBOptimizerBuilder.java      | 47 ----------------------
 .../planner/util/SQLFederationPlannerUtils.java    |  2 +-
 .../enumerable/EnumerableScanExecutor.java         |  5 +--
 ...ntext.parser.dialect.OptimizerSQLDialectBuilder |  1 -
 .../enumerable/EnumerableScanExecutorTest.java     |  4 +-
 8 files changed, 9 insertions(+), 84 deletions(-)

diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java
index a2d96fa0b92..67dfaab89da 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java
@@ -132,17 +132,6 @@ public final class DatabaseTypeEngine {
         return null == configuredDatabaseType ? Optional.empty() : 
Optional.of(configuredDatabaseType.getTrunkDatabaseType().orElse(configuredDatabaseType));
     }
     
-    /**
-     * Get trunk database type.
-     *
-     * @param name database name 
-     * @return trunk database type
-     */
-    public static DatabaseType getTrunkDatabaseType(final String name) {
-        DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, name);
-        return databaseType.getTrunkDatabaseType().orElse(databaseType);
-    }
-    
     /**
      * Get default schema name.
      * 
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngineTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngineTest.java
index 3c3046c9c58..ee11e9e93e2 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngineTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngineTest.java
@@ -120,16 +120,6 @@ class DatabaseTypeEngineTest {
         }
     }
     
-    @Test
-    void assertGetTrunkDatabaseTypeWithTrunkDatabaseType() {
-        assertThat(DatabaseTypeEngine.getTrunkDatabaseType("MySQL").getType(), 
is("MySQL"));
-    }
-    
-    @Test
-    void assertGetTrunkDatabaseTypeWithBranchDatabaseType() {
-        assertThat(DatabaseTypeEngine.getTrunkDatabaseType("H2").getType(), 
is("MySQL"));
-    }
-    
     @Test
     void assertGetDefaultSchemaName() {
         DatabaseType schemaSupportDatabaseType = 
TypedSPILoader.getService(DatabaseType.class, "openGauss");
diff --git 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/context/parser/OptimizerParserContextFactory.java
 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/context/parser/OptimizerParserContextFactory.java
index 3ba3d729597..dc69d48af5d 100644
--- 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/context/parser/OptimizerParserContextFactory.java
+++ 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/context/parser/OptimizerParserContextFactory.java
@@ -19,15 +19,13 @@ package 
org.apache.shardingsphere.sqlfederation.compiler.context.parser;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
 import org.apache.shardingsphere.infra.database.spi.DatabaseType;
-import org.apache.shardingsphere.infra.database.DatabaseTypeEngine;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import 
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
 import 
org.apache.shardingsphere.sqlfederation.compiler.context.parser.dialect.OptimizerSQLDialectBuilder;
 
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
@@ -45,8 +43,7 @@ public final class OptimizerParserContextFactory {
     public static Map<String, OptimizerParserContext> create(final Map<String, 
ShardingSphereDatabase> databases) {
         Map<String, OptimizerParserContext> result = new ConcurrentHashMap<>();
         for (Entry<String, ShardingSphereDatabase> entry : 
databases.entrySet()) {
-            DatabaseType databaseType = 
DatabaseTypeEngine.getTrunkDatabaseType(entry.getValue().getProtocolType().getType());
-            result.put(entry.getKey(), new 
OptimizerParserContext(databaseType, createSQLDialectProperties(databaseType)));
+            result.put(entry.getKey(), 
create(entry.getValue().getProtocolType()));
         }
         return result;
     }
@@ -58,10 +55,6 @@ public final class OptimizerParserContextFactory {
      * @return optimizer parser context
      */
     public static OptimizerParserContext create(final DatabaseType 
databaseType) {
-        return new OptimizerParserContext(databaseType, 
createSQLDialectProperties(databaseType));
-    }
-    
-    private static Properties createSQLDialectProperties(final DatabaseType 
databaseType) {
-        return 
DatabaseTypedSPILoader.getService(OptimizerSQLDialectBuilder.class, 
databaseType).build();
+        return new OptimizerParserContext(databaseType, 
DatabaseTypedSPILoader.getService(OptimizerSQLDialectBuilder.class, 
databaseType).build());
     }
 }
diff --git 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/context/parser/dialect/impl/MariaDBOptimizerBuilder.java
 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/context/parser/dialect/impl/MariaDBOptimizerBuilder.java
deleted file mode 100644
index 4f0f3566ca7..00000000000
--- 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/context/parser/dialect/impl/MariaDBOptimizerBuilder.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package 
org.apache.shardingsphere.sqlfederation.compiler.context.parser.dialect.impl;
-
-import org.apache.calcite.config.CalciteConnectionProperty;
-import org.apache.calcite.config.Lex;
-import org.apache.calcite.sql.fun.SqlLibrary;
-import org.apache.calcite.sql.validate.SqlConformanceEnum;
-import 
org.apache.shardingsphere.sqlfederation.compiler.context.parser.dialect.OptimizerSQLDialectBuilder;
-
-import java.util.Properties;
-
-/**
- * Optimizer properties builder for MariaDB.
- */
-public final class MariaDBOptimizerBuilder implements 
OptimizerSQLDialectBuilder {
-    
-    @Override
-    public Properties build() {
-        Properties result = new Properties();
-        result.setProperty(CalciteConnectionProperty.LEX.camelName(), 
Lex.MYSQL.name());
-        result.setProperty(CalciteConnectionProperty.CONFORMANCE.camelName(), 
SqlConformanceEnum.MYSQL_5.name());
-        result.setProperty(CalciteConnectionProperty.FUN.camelName(), 
SqlLibrary.MYSQL.fun);
-        
result.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), 
String.valueOf(Lex.MYSQL.caseSensitive));
-        return result;
-    }
-    
-    @Override
-    public String getDatabaseType() {
-        return "MariaDB";
-    }
-}
diff --git 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/planner/util/SQLFederationPlannerUtils.java
 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/planner/util/SQLFederationPlannerUtils.java
index e35b717cb99..1f1161468dc 100644
--- 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/planner/util/SQLFederationPlannerUtils.java
+++ 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/planner/util/SQLFederationPlannerUtils.java
@@ -222,7 +222,7 @@ public final class SQLFederationPlannerUtils {
                 .withConformance(connectionConfig.conformance())
                 
.withDefaultNullCollation(connectionConfig.defaultNullCollation())
                 .withIdentifierExpansion(true);
-        SqlOperatorTable sqlOperatorTable = getSQLOperatorTable(catalogReader, 
databaseType);
+        SqlOperatorTable sqlOperatorTable = getSQLOperatorTable(catalogReader, 
databaseType.getTrunkDatabaseType().orElse(databaseType));
         return SqlValidatorUtil.newValidator(sqlOperatorTable, catalogReader, 
relDataTypeFactory, validatorConfig);
     }
     
diff --git 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java
 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java
index 80aeff2fe41..502af4f4fc4 100644
--- 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java
+++ 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java
@@ -26,9 +26,8 @@ import org.apache.shardingsphere.authority.rule.AuthorityRule;
 import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.infra.connection.kernel.KernelProcessor;
-import org.apache.shardingsphere.infra.database.spi.DatabaseType;
-import org.apache.shardingsphere.infra.database.DatabaseTypeEngine;
 import 
org.apache.shardingsphere.infra.database.opengauss.OpenGaussDatabaseType;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
 import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
 import 
org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext;
 import 
org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupReportContext;
@@ -131,7 +130,7 @@ public final class EnumerableScanExecutor {
     public Enumerable<Object> execute(final ShardingSphereTable table, final 
EnumerableScanExecutorContext scanContext) {
         String databaseName = executorContext.getDatabaseName().toLowerCase();
         String schemaName = executorContext.getSchemaName().toLowerCase();
-        DatabaseType databaseType = 
DatabaseTypeEngine.getTrunkDatabaseType(optimizerContext.getParserContext(databaseName).getDatabaseType().getType());
+        DatabaseType databaseType = 
optimizerContext.getParserContext(databaseName).getDatabaseType();
         if (databaseType.getSystemSchemas().contains(schemaName)) {
             return executeByShardingSphereData(databaseName, schemaName, 
table, databaseType);
         }
diff --git 
a/kernel/sql-federation/core/src/main/resources/META-INF/services/org.apache.shardingsphere.sqlfederation.compiler.context.parser.dialect.OptimizerSQLDialectBuilder
 
b/kernel/sql-federation/core/src/main/resources/META-INF/services/org.apache.shardingsphere.sqlfederation.compiler.context.parser.dialect.OptimizerSQLDialectBuilder
index 5436e90bced..fd9908a787e 100644
--- 
a/kernel/sql-federation/core/src/main/resources/META-INF/services/org.apache.shardingsphere.sqlfederation.compiler.context.parser.dialect.OptimizerSQLDialectBuilder
+++ 
b/kernel/sql-federation/core/src/main/resources/META-INF/services/org.apache.shardingsphere.sqlfederation.compiler.context.parser.dialect.OptimizerSQLDialectBuilder
@@ -17,7 +17,6 @@
 
 
org.apache.shardingsphere.sqlfederation.compiler.context.parser.dialect.impl.H2OptimizerBuilder
 
org.apache.shardingsphere.sqlfederation.compiler.context.parser.dialect.impl.MySQLOptimizerBuilder
-org.apache.shardingsphere.sqlfederation.compiler.context.parser.dialect.impl.MariaDBOptimizerBuilder
 
org.apache.shardingsphere.sqlfederation.compiler.context.parser.dialect.impl.PostgreSQLOptimizerBuilder
 
org.apache.shardingsphere.sqlfederation.compiler.context.parser.dialect.impl.OpenGaussOptimizerBuilder
 
org.apache.shardingsphere.sqlfederation.compiler.context.parser.dialect.impl.SQLServerOptimizerBuilder
diff --git 
a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutorTest.java
 
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutorTest.java
index 477cfc2075f..b2ae6c801d7 100644
--- 
a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutorTest.java
+++ 
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutorTest.java
@@ -19,12 +19,14 @@ package 
org.apache.shardingsphere.sqlfederation.executor.enumerable;
 
 import org.apache.calcite.linq4j.Enumerable;
 import org.apache.calcite.linq4j.Enumerator;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
 import 
org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereDatabaseData;
 import 
org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereRowData;
 import 
org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereSchemaData;
 import 
org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereStatistics;
 import 
org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereTableData;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
 import 
org.apache.shardingsphere.sqlfederation.compiler.context.OptimizerContext;
 import 
org.apache.shardingsphere.sqlfederation.executor.TableScanExecutorContext;
 import org.junit.jupiter.api.Test;
@@ -44,7 +46,7 @@ class EnumerableScanExecutorTest {
     @Test
     void assertExecuteWithStatistics() {
         OptimizerContext optimizerContext = mock(OptimizerContext.class, 
RETURNS_DEEP_STUBS);
-        
when(optimizerContext.getParserContext(any()).getDatabaseType().getType()).thenReturn("PostgreSQL");
+        
when(optimizerContext.getParserContext(any()).getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
 "PostgreSQL"));
         TableScanExecutorContext executorContext = 
mock(TableScanExecutorContext.class);
         when(executorContext.getDatabaseName()).thenReturn("db");
         when(executorContext.getSchemaName()).thenReturn("pg_catalog");

Reply via email to