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

totalo 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 fcfdb2b0159 Register database functions for ADVANCED federation 
executor (#21033)
fcfdb2b0159 is described below

commit fcfdb2b01596926230fb096747ad6993f0493284
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Sat Sep 17 18:06:03 2022 +0800

    Register database functions for ADVANCED federation executor (#21033)
---
 .../advanced/AdvancedSQLFederationExecutor.java    | 12 +++---
 .../advanced/resultset/SQLFederationResultSet.java |  6 +--
 .../advanced/result/FederationResultSetTest.java   |  8 ++--
 .../executor/FilterableTableScanExecutor.java      |  4 +-
 .../executor/TranslatableTableScanExecutor.java    |  4 +-
 .../parser/dialect/impl/H2OptimizerBuilder.java    |  1 +
 .../dialect/impl/MariaDBOptimizerBuilder.java      |  1 +
 .../parser/dialect/impl/MySQLOptimizerBuilder.java |  1 +
 .../dialect/impl/OpenGaussOptimizerBuilder.java    |  1 +
 .../dialect/impl/OracleOptimizerBuilder.java       |  1 +
 .../dialect/impl/PostgreSQLOptimizerBuilder.java   |  1 +
 .../parser/dialect/impl/SQL92OptimizerBuilder.java |  1 +
 .../dialect/impl/SQLServerOptimizerBuilder.java    |  1 +
 .../planner/OptimizerPlannerContextFactory.java    | 46 +++++++++++++---------
 .../optimizer/ShardingSphereOptimizerTest.java     | 13 +++---
 .../cases/dql/dql-integration-test-cases.xml       |  5 +--
 16 files changed, 63 insertions(+), 43 deletions(-)

diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/AdvancedSQLFederationExecutor.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/AdvancedSQLFederationExecutor.java
index 65a0e13d3de..0093f0871aa 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/AdvancedSQLFederationExecutor.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/AdvancedSQLFederationExecutor.java
@@ -52,6 +52,7 @@ import 
org.apache.shardingsphere.sqlfederation.executor.TableScanExecutorContext
 import 
org.apache.shardingsphere.sqlfederation.optimizer.ShardingSphereOptimizer;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.context.OptimizerContext;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.context.OptimizerContextFactory;
+import 
org.apache.shardingsphere.sqlfederation.optimizer.context.parser.OptimizerParserContext;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.context.planner.OptimizerPlannerContextFactory;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.executor.TableScanExecutor;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.metadata.filter.FilterableSchema;
@@ -107,7 +108,7 @@ public final class AdvancedSQLFederationExecutor implements 
SQLFederationExecuto
         ShardingSphereSchema schema = 
federationContext.getDatabases().get(databaseName.toLowerCase()).getSchema(schemaName);
         AbstractSchema sqlFederationSchema = 
createSQLFederationSchema(prepareEngine, schema, callback, federationContext);
         Map<String, Object> parameters = 
createParameters(federationContext.getQueryContext().getParameters());
-        Enumerator<Object[]> enumerator = 
execute(sqlStatementContext.getSqlStatement(), sqlFederationSchema, 
parameters).enumerator();
+        Enumerator<Object> enumerator = 
execute(sqlStatementContext.getSqlStatement(), sqlFederationSchema, 
parameters).enumerator();
         resultSet = new SQLFederationResultSet(enumerator, schema, 
sqlFederationSchema, sqlStatementContext);
         return resultSet;
     }
@@ -131,15 +132,16 @@ public final class AdvancedSQLFederationExecutor 
implements SQLFederationExecuto
     }
     
     @SuppressWarnings("unchecked")
-    private Enumerable<Object[]> execute(final SQLStatement sqlStatement, 
final AbstractSchema sqlFederationSchema, final Map<String, Object> parameters) 
{
-        CalciteConnectionConfig connectionConfig = new 
CalciteConnectionConfigImpl(OptimizerPlannerContextFactory.createConnectionProperties());
+    private Enumerable<Object> execute(final SQLStatement sqlStatement, final 
AbstractSchema sqlFederationSchema, final Map<String, Object> parameters) {
+        OptimizerParserContext parserContext = 
optimizerContext.getParserContexts().get(databaseName);
+        CalciteConnectionConfig connectionConfig = new 
CalciteConnectionConfigImpl(parserContext.getDialectProps());
         RelDataTypeFactory relDataTypeFactory = new JavaTypeFactoryImpl();
         CalciteCatalogReader catalogReader = 
OptimizerPlannerContextFactory.createCatalogReader(schemaName, 
sqlFederationSchema, relDataTypeFactory, connectionConfig);
-        SqlValidator validator = 
OptimizerPlannerContextFactory.createValidator(catalogReader, 
relDataTypeFactory, connectionConfig);
+        SqlValidator validator = 
OptimizerPlannerContextFactory.createValidator(catalogReader, 
relDataTypeFactory, parserContext.getDatabaseType(), connectionConfig);
         SqlToRelConverter converter = 
OptimizerPlannerContextFactory.createConverter(catalogReader, validator, 
relDataTypeFactory);
         RelNode bestPlan =
                 new ShardingSphereOptimizer(converter, 
QueryOptimizePlannerFactory.createHepPlanner()).optimize(sqlStatement);
-        Bindable<Object[]> executablePlan = 
EnumerableInterpretable.toBindable(Collections.emptyMap(), null, 
(EnumerableRel) bestPlan, EnumerableRel.Prefer.ARRAY);
+        Bindable<Object> executablePlan = 
EnumerableInterpretable.toBindable(Collections.emptyMap(), null, 
(EnumerableRel) bestPlan, EnumerableRel.Prefer.ARRAY);
         return executablePlan.bind(new SQLFederationDataContext(validator, 
converter, parameters));
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/resultset/SQLFederationResultSet.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/resultset/SQLFederationResultSet.java
index 2951467c33b..88acbac0637 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/resultset/SQLFederationResultSet.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/main/java/org/apache/shardingsphere/sqlfederation/advanced/resultset/SQLFederationResultSet.java
@@ -60,7 +60,7 @@ public final class SQLFederationResultSet extends 
AbstractUnsupportedOperationRe
     
     private static final String BINARY = "Binary";
     
-    private final Enumerator<Object[]> enumerator;
+    private final Enumerator<Object> enumerator;
     
     private final Map<String, Integer> columnLabelAndIndexMap;
     
@@ -72,7 +72,7 @@ public final class SQLFederationResultSet extends 
AbstractUnsupportedOperationRe
     
     private boolean closed;
     
-    public SQLFederationResultSet(final Enumerator<Object[]> enumerator, final 
ShardingSphereSchema schema, final AbstractSchema filterableSchema, final 
SQLStatementContext<?> sqlStatementContext) {
+    public SQLFederationResultSet(final Enumerator<Object> enumerator, final 
ShardingSphereSchema schema, final AbstractSchema filterableSchema, final 
SQLStatementContext<?> sqlStatementContext) {
         this.enumerator = enumerator;
         columnLabelAndIndexMap = 
createColumnLabelAndIndexMap(sqlStatementContext);
         resultSetMetaData = new SQLFederationResultSetMetaData(schema, 
filterableSchema, new JavaTypeFactoryImpl(), (SelectStatementContext) 
sqlStatementContext);
@@ -91,7 +91,7 @@ public final class SQLFederationResultSet extends 
AbstractUnsupportedOperationRe
     @Override
     public boolean next() {
         boolean result = enumerator.moveNext();
-        currentRows = result ? enumerator.current() : new Object[]{};
+        currentRows = result ? (enumerator.current().getClass().isArray() ? 
(Object[]) enumerator.current() : new Object[]{enumerator.current()}) : new 
Object[]{};
         return result;
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/test/java/org/apache/shardingsphere/sqlfederation/advanced/result/FederationResultSetTest.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/test/java/org/apache/shardingsphere/sqlfederation/advanced/result/FederationResultSetTest.java
index 2ebb0da483a..547cff4d5ad 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/test/java/org/apache/shardingsphere/sqlfederation/advanced/result/FederationResultSetTest.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-advanced/src/test/java/org/apache/shardingsphere/sqlfederation/advanced/result/FederationResultSetTest.java
@@ -22,9 +22,9 @@ import 
org.apache.shardingsphere.infra.binder.segment.select.projection.Projecti
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection;
 import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
 import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
 import 
org.apache.shardingsphere.sqlfederation.advanced.resultset.SQLFederationResultSet;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.metadata.filter.FilterableSchema;
-import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -59,7 +59,7 @@ import static org.mockito.Mockito.when;
 
 public final class FederationResultSetTest {
     
-    private Enumerator<Object[]> enumerator;
+    private Enumerator<Object> enumerator;
     
     private SQLFederationResultSet federationResultSet;
     
@@ -81,8 +81,8 @@ public final class FederationResultSetTest {
     }
     
     @SuppressWarnings("unchecked")
-    private Enumerator<Object[]> createEnumerator() {
-        Enumerator<Object[]> result = mock(Enumerator.class);
+    private Enumerator<Object> createEnumerator() {
+        Enumerator<Object> result = mock(Enumerator.class);
         when(result.moveNext()).thenReturn(true, false);
         when(result.current()).thenReturn(new Object[]{1, 1, "OK", 1});
         return result;
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/FilterableTableScanExecutor.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/FilterableTableScanExecutor.java
index 12f84907905..b530209eff8 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/FilterableTableScanExecutor.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/FilterableTableScanExecutor.java
@@ -73,8 +73,8 @@ import 
org.apache.shardingsphere.sqlfederation.optimizer.executor.ScanNodeExecut
 import 
org.apache.shardingsphere.sqlfederation.optimizer.executor.TableScanExecutor;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.metadata.filter.FilterableSchema;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.planner.QueryOptimizePlannerFactory;
-import org.apache.shardingsphere.sqlfederation.row.SQLFederationRowEnumerator;
 import org.apache.shardingsphere.sqlfederation.row.EmptyRowEnumerator;
+import org.apache.shardingsphere.sqlfederation.row.SQLFederationRowEnumerator;
 import 
org.apache.shardingsphere.sqlfederation.spi.SQLFederationExecutorContext;
 
 import java.sql.Connection;
@@ -194,7 +194,7 @@ public final class FilterableTableScanExecutor implements 
TableScanExecutor {
     private RelNode createRelNode(final ShardingSphereTable table, final 
FilterableScanNodeExecutorContext scanContext) {
         String databaseName = executorContext.getDatabaseName();
         String schemaName = executorContext.getSchemaName();
-        CalciteConnectionConfig connectionConfig = new 
CalciteConnectionConfigImpl(OptimizerPlannerContextFactory.createConnectionProperties());
+        CalciteConnectionConfig connectionConfig = new 
CalciteConnectionConfigImpl(optimizerContext.getParserContexts().get(databaseName).getDialectProps());
         ShardingSphereSchema schema = 
executorContext.getFederationContext().getDatabases().get(databaseName).getSchema(schemaName);
         CalciteCatalogReader catalogReader = 
OptimizerPlannerContextFactory.createCatalogReader(schemaName,
                 new FilterableSchema(schemaName, schema, null), new 
JavaTypeFactoryImpl(), connectionConfig);
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/TranslatableTableScanExecutor.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/TranslatableTableScanExecutor.java
index b563e41c84f..66643232c5f 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/TranslatableTableScanExecutor.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-executor/shardingsphere-sql-federation-executor-core/src/main/java/org/apache/shardingsphere/sqlfederation/executor/TranslatableTableScanExecutor.java
@@ -77,8 +77,8 @@ import 
org.apache.shardingsphere.sqlfederation.optimizer.executor.TranslatableSc
 import 
org.apache.shardingsphere.sqlfederation.optimizer.metadata.filter.FilterableSchema;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.metadata.translatable.StringToRexNodeUtil;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.planner.QueryOptimizePlannerFactory;
-import org.apache.shardingsphere.sqlfederation.row.SQLFederationRowEnumerator;
 import org.apache.shardingsphere.sqlfederation.row.EmptyRowEnumerator;
+import org.apache.shardingsphere.sqlfederation.row.SQLFederationRowEnumerator;
 import 
org.apache.shardingsphere.sqlfederation.spi.SQLFederationExecutorContext;
 
 import java.io.IOException;
@@ -198,7 +198,7 @@ public final class TranslatableTableScanExecutor implements 
TableScanExecutor {
     private RelNode createRelNode(final ShardingSphereTable table, final 
TranslatableScanNodeExecutorContext scanContext) {
         String databaseName = executorContext.getDatabaseName();
         String schemaName = executorContext.getSchemaName();
-        CalciteConnectionConfig connectionConfig = new 
CalciteConnectionConfigImpl(OptimizerPlannerContextFactory.createConnectionProperties());
+        CalciteConnectionConfig connectionConfig = new 
CalciteConnectionConfigImpl(optimizerContext.getParserContexts().get(databaseName).getDialectProps());
         ShardingSphereSchema schema = 
executorContext.getFederationContext().getDatabases().get(databaseName).getSchema(schemaName);
         CalciteCatalogReader catalogReader = 
OptimizerPlannerContextFactory.createCatalogReader(schemaName,
                 new FilterableSchema(schemaName, schema, null), new 
JavaTypeFactoryImpl(), connectionConfig);
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/H2OptimizerBuilder.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/H2OptimizerBuilder.java
index 698497bc8e2..061fc80cf0b 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/H2OptimizerBuilder.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/H2OptimizerBuilder.java
@@ -37,6 +37,7 @@ public final class H2OptimizerBuilder implements 
OptimizerSQLDialectBuilder {
         result.setProperty(CalciteConnectionProperty.LEX.camelName(), 
Lex.MYSQL.name());
         result.setProperty(CalciteConnectionProperty.CONFORMANCE.camelName(), 
SqlConformanceEnum.LENIENT.name());
         result.setProperty(CalciteConnectionProperty.FUN.camelName(), 
SqlLibrary.STANDARD.fun);
+        
result.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), 
String.valueOf(Lex.MYSQL.caseSensitive));
         return result;
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/MariaDBOptimizerBuilder.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/MariaDBOptimizerBuilder.java
index 2f47cd06d0d..da197d0a57e 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/MariaDBOptimizerBuilder.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/MariaDBOptimizerBuilder.java
@@ -36,6 +36,7 @@ public final class MariaDBOptimizerBuilder implements 
OptimizerSQLDialectBuilder
         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;
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/MySQLOptimizerBuilder.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/MySQLOptimizerBuilder.java
index 24459f9b6ef..86f4fba7ac4 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/MySQLOptimizerBuilder.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/MySQLOptimizerBuilder.java
@@ -36,6 +36,7 @@ public final class MySQLOptimizerBuilder implements 
OptimizerSQLDialectBuilder {
         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;
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/OpenGaussOptimizerBuilder.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/OpenGaussOptimizerBuilder.java
index cd38489c0c1..a636a20fb3d 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/OpenGaussOptimizerBuilder.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/OpenGaussOptimizerBuilder.java
@@ -36,6 +36,7 @@ public final class OpenGaussOptimizerBuilder implements 
OptimizerSQLDialectBuild
         result.setProperty(CalciteConnectionProperty.LEX.camelName(), 
Lex.JAVA.name());
         result.setProperty(CalciteConnectionProperty.CONFORMANCE.camelName(), 
SqlConformanceEnum.BABEL.name());
         result.setProperty(CalciteConnectionProperty.FUN.camelName(), 
SqlLibrary.POSTGRESQL.fun);
+        
result.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), 
String.valueOf(Lex.JAVA.caseSensitive));
         return result;
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/OracleOptimizerBuilder.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/OracleOptimizerBuilder.java
index 17a48eaf309..240294cc99b 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/OracleOptimizerBuilder.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/OracleOptimizerBuilder.java
@@ -36,6 +36,7 @@ public final class OracleOptimizerBuilder implements 
OptimizerSQLDialectBuilder
         result.setProperty(CalciteConnectionProperty.LEX.camelName(), 
Lex.ORACLE.name());
         result.setProperty(CalciteConnectionProperty.CONFORMANCE.camelName(), 
SqlConformanceEnum.ORACLE_12.name());
         result.setProperty(CalciteConnectionProperty.FUN.camelName(), 
SqlLibrary.ORACLE.fun);
+        
result.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), 
String.valueOf(Lex.ORACLE.caseSensitive));
         return result;
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/PostgreSQLOptimizerBuilder.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/PostgreSQLOptimizerBuilder.java
index ec5f0b9b939..425a42fa7c1 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/PostgreSQLOptimizerBuilder.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/PostgreSQLOptimizerBuilder.java
@@ -36,6 +36,7 @@ public final class PostgreSQLOptimizerBuilder implements 
OptimizerSQLDialectBuil
         result.setProperty(CalciteConnectionProperty.LEX.camelName(), 
Lex.JAVA.name());
         result.setProperty(CalciteConnectionProperty.CONFORMANCE.camelName(), 
SqlConformanceEnum.BABEL.name());
         result.setProperty(CalciteConnectionProperty.FUN.camelName(), 
SqlLibrary.POSTGRESQL.fun);
+        
result.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), 
String.valueOf(Lex.JAVA.caseSensitive));
         return result;
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/SQL92OptimizerBuilder.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/SQL92OptimizerBuilder.java
index ec5606e39ff..0e12d2a4599 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/SQL92OptimizerBuilder.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/SQL92OptimizerBuilder.java
@@ -36,6 +36,7 @@ public final class SQL92OptimizerBuilder implements 
OptimizerSQLDialectBuilder {
         result.setProperty(CalciteConnectionProperty.LEX.camelName(), 
Lex.MYSQL.name());
         result.setProperty(CalciteConnectionProperty.CONFORMANCE.camelName(), 
SqlConformanceEnum.STRICT_92.name());
         result.setProperty(CalciteConnectionProperty.FUN.camelName(), 
SqlLibrary.STANDARD.fun);
+        
result.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), 
String.valueOf(Lex.MYSQL.caseSensitive));
         return result;
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/SQLServerOptimizerBuilder.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/SQLServerOptimizerBuilder.java
index d6aec8cefab..ba6cd8c23b8 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/SQLServerOptimizerBuilder.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/dialect/impl/SQLServerOptimizerBuilder.java
@@ -36,6 +36,7 @@ public final class SQLServerOptimizerBuilder implements 
OptimizerSQLDialectBuild
         result.setProperty(CalciteConnectionProperty.LEX.camelName(), 
Lex.SQL_SERVER.name());
         result.setProperty(CalciteConnectionProperty.CONFORMANCE.camelName(), 
SqlConformanceEnum.SQL_SERVER_2008.name());
         result.setProperty(CalciteConnectionProperty.FUN.camelName(), 
SqlLibrary.STANDARD.fun);
+        
result.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), 
String.valueOf(Lex.SQL_SERVER.caseSensitive));
         return result;
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/planner/OptimizerPlannerContextFactory.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/planner/OptimizerPlannerContextFactory.java
index 5e72640368b..193c6639624 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/planner/OptimizerPlannerContextFactory.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/planner/OptimizerPlannerContextFactory.java
@@ -20,7 +20,6 @@ package 
org.apache.shardingsphere.sqlfederation.optimizer.context.planner;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.calcite.config.CalciteConnectionConfig;
-import org.apache.calcite.config.CalciteConnectionProperty;
 import org.apache.calcite.jdbc.CalciteSchema;
 import org.apache.calcite.plan.RelOptCluster;
 import org.apache.calcite.plan.RelOptTable.ViewExpander;
@@ -28,19 +27,24 @@ import org.apache.calcite.prepare.CalciteCatalogReader;
 import org.apache.calcite.rel.type.RelDataTypeFactory;
 import org.apache.calcite.rex.RexBuilder;
 import org.apache.calcite.schema.Schema;
-import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.SqlOperatorTable;
+import org.apache.calcite.sql.fun.SqlLibrary;
+import org.apache.calcite.sql.fun.SqlLibraryOperatorTableFactory;
+import org.apache.calcite.sql.util.SqlOperatorTables;
 import org.apache.calcite.sql.validate.SqlValidator;
 import org.apache.calcite.sql.validate.SqlValidatorUtil;
 import org.apache.calcite.sql2rel.SqlToRelConverter;
 import org.apache.calcite.sql2rel.SqlToRelConverter.Config;
 import org.apache.calcite.sql2rel.StandardConvertletTable;
-import 
org.apache.shardingsphere.sqlfederation.optimizer.planner.QueryOptimizePlannerFactory;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import 
org.apache.shardingsphere.sqlfederation.optimizer.planner.QueryOptimizePlannerFactory;
 
+import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
@@ -49,6 +53,15 @@ import java.util.concurrent.ConcurrentHashMap;
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class OptimizerPlannerContextFactory {
     
+    private static final Map<String, SqlLibrary> DATABASE_TYPE_SQL_LIBRARIES = 
new HashMap<>();
+    
+    static {
+        DATABASE_TYPE_SQL_LIBRARIES.put(SqlLibrary.MYSQL.name().toLowerCase(), 
SqlLibrary.MYSQL);
+        
DATABASE_TYPE_SQL_LIBRARIES.put(SqlLibrary.POSTGRESQL.name().toLowerCase(), 
SqlLibrary.POSTGRESQL);
+        DATABASE_TYPE_SQL_LIBRARIES.put(SqlLibrary.ORACLE.name(), 
SqlLibrary.ORACLE);
+        DATABASE_TYPE_SQL_LIBRARIES.put("openGauss", SqlLibrary.POSTGRESQL);
+    }
+    
     /**
      * Create optimizer planner context map.
      *
@@ -63,17 +76,6 @@ public final class OptimizerPlannerContextFactory {
         return result;
     }
     
-    /**
-     * Create connection properties.
-     * 
-     * @return properties
-     */
-    public static Properties createConnectionProperties() {
-        Properties result = new Properties();
-        result.setProperty(CalciteConnectionProperty.TIME_ZONE.camelName(), 
"UTC");
-        return result;
-    }
-    
     /**
      * Create catalog reader.
      * 
@@ -91,19 +93,27 @@ public final class OptimizerPlannerContextFactory {
     
     /**
      * Create validator.
-     * 
+     *
      * @param catalogReader catalog reader
      * @param relDataTypeFactory rel data type factory
+     * @param databaseType database type
      * @param connectionConfig connection config
      * @return sql validator
      */
-    public static SqlValidator createValidator(final CalciteCatalogReader 
catalogReader, final RelDataTypeFactory relDataTypeFactory, final 
CalciteConnectionConfig connectionConfig) {
+    public static SqlValidator createValidator(final CalciteCatalogReader 
catalogReader, final RelDataTypeFactory relDataTypeFactory,
+                                               final DatabaseType 
databaseType, final CalciteConnectionConfig connectionConfig) {
         SqlValidator.Config validatorConfig = SqlValidator.Config.DEFAULT
                 
.withLenientOperatorLookup(connectionConfig.lenientOperatorLookup())
                 .withConformance(connectionConfig.conformance())
                 
.withDefaultNullCollation(connectionConfig.defaultNullCollation())
                 .withIdentifierExpansion(true);
-        return SqlValidatorUtil.newValidator(SqlStdOperatorTable.instance(), 
catalogReader, relDataTypeFactory, validatorConfig);
+        SqlOperatorTable sqlOperatorTable = getSQLOperatorTable(catalogReader, 
databaseType);
+        return SqlValidatorUtil.newValidator(sqlOperatorTable, catalogReader, 
relDataTypeFactory, validatorConfig);
+    }
+    
+    private static SqlOperatorTable getSQLOperatorTable(final 
CalciteCatalogReader catalogReader, final DatabaseType databaseType) {
+        return 
SqlOperatorTables.chain(Arrays.asList(SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
+                Arrays.asList(SqlLibrary.STANDARD, 
DATABASE_TYPE_SQL_LIBRARIES.getOrDefault(databaseType.getType(), 
SqlLibrary.MYSQL))), catalogReader));
     }
     
     /**
diff --git 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/ShardingSphereOptimizerTest.java
 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/ShardingSphereOptimizerTest.java
index ffb59339a9e..92af477a6e8 100644
--- 
a/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/ShardingSphereOptimizerTest.java
+++ 
b/shardingsphere-kernel/shardingsphere-sql-federation/shardingsphere-sql-federation-optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/ShardingSphereOptimizerTest.java
@@ -26,9 +26,6 @@ import org.apache.calcite.sql.validate.SqlValidator;
 import org.apache.calcite.sql2rel.SqlToRelConverter;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
 import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
-import 
org.apache.shardingsphere.sqlfederation.optimizer.context.planner.OptimizerPlannerContextFactory;
-import 
org.apache.shardingsphere.sqlfederation.optimizer.metadata.translatable.TranslatableSchema;
-import 
org.apache.shardingsphere.sqlfederation.optimizer.planner.QueryOptimizePlannerFactory;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereColumn;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
@@ -36,6 +33,9 @@ import 
org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine;
 import org.apache.shardingsphere.parser.rule.SQLParserRule;
 import 
org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import 
org.apache.shardingsphere.sqlfederation.optimizer.context.planner.OptimizerPlannerContextFactory;
+import 
org.apache.shardingsphere.sqlfederation.optimizer.metadata.translatable.TranslatableSchema;
+import 
org.apache.shardingsphere.sqlfederation.optimizer.planner.QueryOptimizePlannerFactory;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -44,6 +44,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
@@ -116,12 +117,12 @@ public final class ShardingSphereOptimizerTest {
         return new ShardingSphereTable("t_user_info", 
Arrays.asList(userIdColumn, informationColumn), Collections.emptyList(), 
Collections.emptyList());
     }
     
-    private static SqlToRelConverter createSqlToRelConverter(final 
ShardingSphereSchema schema) {
-        CalciteConnectionConfig connectionConfig = new 
CalciteConnectionConfigImpl(OptimizerPlannerContextFactory.createConnectionProperties());
+    private SqlToRelConverter createSqlToRelConverter(final 
ShardingSphereSchema schema) {
+        CalciteConnectionConfig connectionConfig = new 
CalciteConnectionConfigImpl(new Properties());
         RelDataTypeFactory relDataTypeFactory = new JavaTypeFactoryImpl();
         TranslatableSchema federationSchema = new 
TranslatableSchema(SCHEMA_NAME, schema, null);
         CalciteCatalogReader catalogReader = 
OptimizerPlannerContextFactory.createCatalogReader(SCHEMA_NAME, 
federationSchema, relDataTypeFactory, connectionConfig);
-        SqlValidator validator = 
OptimizerPlannerContextFactory.createValidator(catalogReader, 
relDataTypeFactory, connectionConfig);
+        SqlValidator validator = 
OptimizerPlannerContextFactory.createValidator(catalogReader, 
relDataTypeFactory, new H2DatabaseType(), connectionConfig);
         return OptimizerPlannerContextFactory.createConverter(catalogReader, 
validator, relDataTypeFactory);
     }
     
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dql-integration-test-cases.xml
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dql-integration-test-cases.xml
index 6a51a849b2d..d6d6f986d71 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dql-integration-test-cases.xml
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dql-integration-test-cases.xml
@@ -541,10 +541,9 @@
         <assertion parameters="10000:int" 
expected-data-source-name="read_dataset" />
     </test-case>-->
     
-    <!-- FIXME No match found for function signature CONCAT(<CHARACTER>, 
<CHARACTER>) -->
-    <!--<test-case sql="select t_order_federate.*, 
t_order_item_federate_sharding.* from 
t_order_federate,t_order_item_federate_sharding where t_order_federate.order_id 
= t_order_item_federate_sharding.item_id" 
scenario-types="dbtbl_with_readwrite_splitting,dbtbl_with_readwrite_splitting_and_encrypt,sharding_and_encrypt,encrypt_and_readwrite_splitting">
+    <test-case sql="select t_order_federate.*, 
t_order_item_federate_sharding.* from 
t_order_federate,t_order_item_federate_sharding where t_order_federate.order_id 
= t_order_item_federate_sharding.item_id" 
scenario-types="dbtbl_with_readwrite_splitting,dbtbl_with_readwrite_splitting_and_encrypt,sharding_and_encrypt,encrypt_and_readwrite_splitting">
         <assertion expected-data-source-name="read_dataset" />
-    </test-case>-->
+    </test-case>
     
     <test-case sql="select t_order_federate.*, 
t_order_item_federate_sharding.* from t_order_federate, 
t_order_item_federate_sharding where t_order_federate.order_id = 
t_order_item_federate_sharding.item_id AND 
t_order_item_federate_sharding.order_id = ?" 
scenario-types="dbtbl_with_readwrite_splitting,dbtbl_with_readwrite_splitting_and_encrypt,sharding_and_encrypt,encrypt_and_readwrite_splitting">
         <assertion parameters="10001:int" 
expected-data-source-name="read_dataset" />


Reply via email to