You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/01/17 16:03:17 UTC

[shardingsphere] branch master updated: Disable ONLY_FULL_GROUP_BY for MySQL IT (#9068)

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

wuweijie 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 aafecc3  Disable ONLY_FULL_GROUP_BY for MySQL IT (#9068)
aafecc3 is described below

commit aafecc3477d3052f24cd7ea45584f28320c7d8ee
Author: Liang Zhang <te...@163.com>
AuthorDate: Mon Jan 18 00:02:47 2021 +0800

    Disable ONLY_FULL_GROUP_BY for MySQL IT (#9068)
---
 .../jdbc/sane/mysql/MySQLSaneQueryResultEngine.java  |  7 ++++---
 .../executor/callback/ProxyJDBCExecutorCallback.java | 20 ++++++++++++++++++--
 .../src/test/resources/docker/db/docker-compose.yml  |  2 +-
 .../dbtbl_with_replica_query/docker-compose.yml      |  2 +-
 .../docker/replica_query/docker-compose.yml          |  2 +-
 .../src/test/resources/docker/tbl/docker-compose.yml |  2 +-
 6 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/mysql/MySQLSaneQueryResultEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/mysql/MySQLSaneQueryResultEngine.java
index 094c483..1d3928d 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/mysql/MySQLSaneQueryResultEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/mysql/MySQLSaneQueryResultEngine.java
@@ -43,7 +43,7 @@ public final class MySQLSaneQueryResultEngine implements SaneQueryResultEngine {
     @Override
     public Optional<QueryResult> getSaneQueryResult(final SQLStatement sqlStatement) {
         if (sqlStatement instanceof SelectStatement) {
-            return Optional.of(createQueryResult((SelectStatement) sqlStatement));
+            return createQueryResult((SelectStatement) sqlStatement);
         }
         if (sqlStatement instanceof MySQLShowOtherStatement) {
             return Optional.of(createQueryResult((MySQLShowOtherStatement) sqlStatement));
@@ -51,7 +51,7 @@ public final class MySQLSaneQueryResultEngine implements SaneQueryResultEngine {
         return Optional.empty();
     }
     
-    private QueryResult createQueryResult(final SelectStatement sqlStatement) {
+    private Optional<QueryResult> createQueryResult(final SelectStatement sqlStatement) {
         List<RawQueryResultColumnMetaData> queryResultColumnMetaDataList = new ArrayList<>(sqlStatement.getProjections().getProjections().size());
         List<Object> data = new ArrayList<>(sqlStatement.getProjections().getProjections().size());
         for (ProjectionSegment each : sqlStatement.getProjections().getProjections()) {
@@ -62,7 +62,8 @@ public final class MySQLSaneQueryResultEngine implements SaneQueryResultEngine {
                 data.add(MySQLDefaultVariable.containsVariable(alias) ? MySQLDefaultVariable.getVariable(alias) : "1");
             }
         }
-        return new RawMemoryQueryResult(new RawQueryResultMetaData(queryResultColumnMetaDataList), Collections.singletonList(new MemoryQueryResultDataRow(data)));
+        return queryResultColumnMetaDataList.isEmpty()
+                ? Optional.empty() : Optional.of(new RawMemoryQueryResult(new RawQueryResultMetaData(queryResultColumnMetaDataList), Collections.singletonList(new MemoryQueryResultDataRow(data))));
     }
     
     private QueryResult createQueryResult(final MySQLShowOtherStatement sqlStatement) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
index 601efe4..12dacca 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
@@ -90,8 +90,24 @@ public abstract class ProxyJDBCExecutorCallback extends JDBCExecutorCallback<Exe
     
     @Override
     protected final ExecuteResult getSaneResult(final SQLStatement sqlStatement) {
-        String configuredDatabaseType = ProxyContext.getInstance().getMetaDataContexts().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE);
-        Optional<QueryResult> queryResult = JDBCSaneQueryResultEngineFactory.newInstance(DatabaseTypeRegistry.getTrunkDatabaseType(configuredDatabaseType)).getSaneQueryResult(sqlStatement);
+        Optional<QueryResult> queryResult = JDBCSaneQueryResultEngineFactory.newInstance(getFrontendDatabaseType()).getSaneQueryResult(sqlStatement);
         return queryResult.isPresent() ? queryResult.get() : new UpdateResult(0, 0);
     }
+    
+    private DatabaseType getFrontendDatabaseType() {
+        Optional<DatabaseType> configuredDatabaseType = findConfiguredDatabaseType();
+        if (configuredDatabaseType.isPresent()) {
+            return configuredDatabaseType.get();
+        }
+        if (ProxyContext.getInstance().getMetaDataContexts().getAllSchemaNames().isEmpty()) {
+            return DatabaseTypeRegistry.getTrunkDatabaseType("MySQL");
+        }
+        String schemaName = ProxyContext.getInstance().getMetaDataContexts().getAllSchemaNames().iterator().next();
+        return ProxyContext.getInstance().getMetaDataContexts().getMetaData(schemaName).getResource().getDatabaseType();
+    }
+    
+    private static Optional<DatabaseType> findConfiguredDatabaseType() {
+        String configuredDatabaseType = ProxyContext.getInstance().getMetaDataContexts().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE);
+        return configuredDatabaseType.isEmpty() ? Optional.empty() : Optional.of(DatabaseTypeRegistry.getTrunkDatabaseType(configuredDatabaseType));
+    }
 }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/docker-compose.yml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/docker-compose.yml
index 2d7ded4..f710473 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/docker-compose.yml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/docker-compose.yml
@@ -21,7 +21,7 @@ services:
   mysql:
     image: "mysql/mysql-server:5.7"
     container_name: db-mysql
-    command: --default-authentication-plugin=mysql_native_password
+    command: ['--sql_mode=', '--default-authentication-plugin=mysql_native_password']
     volumes:
       - ../../env/db/mysql:/docker-entrypoint-initdb.d/
     ports:
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_replica_query/docker-compose.yml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_replica_query/docker-compose.yml
index b331494..617e884 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_replica_query/docker-compose.yml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_replica_query/docker-compose.yml
@@ -21,7 +21,7 @@ services:
   mysql:
     image: "mysql/mysql-server:5.7"
     container_name: dbtbl-with-replica-query-mysql
-    command: --default-authentication-plugin=mysql_native_password
+    command: ['--sql_mode=', '--default-authentication-plugin=mysql_native_password']
     volumes:
       - ../../env/dbtbl_with_replica_query/mysql:/docker-entrypoint-initdb.d/
     ports:
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/replica_query/docker-compose.yml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/replica_query/docker-compose.yml
index d9c9cfb..d376bca 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/replica_query/docker-compose.yml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/replica_query/docker-compose.yml
@@ -21,7 +21,7 @@ services:
   mysql:
     image: "mysql/mysql-server:5.7"
     container_name: replica-query-mysql
-    command: --default-authentication-plugin=mysql_native_password
+    command: ['--sql_mode=', '--default-authentication-plugin=mysql_native_password']
     volumes:
       - ../../env/replica_query/mysql:/docker-entrypoint-initdb.d/
     ports:
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/docker-compose.yml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/docker-compose.yml
index a4e400f..7b31bf5 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/docker-compose.yml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/docker-compose.yml
@@ -21,7 +21,7 @@ services:
   mysql:
     image: "mysql/mysql-server:5.7"
     container_name: tbl-mysql
-    command: --default-authentication-plugin=mysql_native_password
+    command: ['--sql_mode=', '--default-authentication-plugin=mysql_native_password']
     volumes:
       - ../../env/tbl/mysql:/docker-entrypoint-initdb.d/
     ports: