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

yx9o 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 1ace234e671 Optimize mysql admin executor creator (#34957)
1ace234e671 is described below

commit 1ace234e67145e8e5593f617a6600737527c882f
Author: jiangML <1060319...@qq.com>
AuthorDate: Wed Mar 12 10:03:30 2025 +0800

    Optimize mysql admin executor creator (#34957)
    
    * Optimize mysql admin executor creator
    
    * Fix test error
---
 .../handler/admin/MySQLAdminExecutorCreator.java   | 53 ++++++++--------------
 .../MySQLInformationSchemaExecutorFactory.java     | 22 ++-------
 .../admin/MySQLMySQLSchemaExecutorFactory.java     |  6 ++-
 .../MySQLPerformanceSchemaExecutorFactory.java     |  6 ++-
 .../admin/MySQLSysSchemaExecutorFactory.java       |  6 ++-
 .../admin/MySQLAdminExecutorCreatorTest.java       | 29 ++++++++++--
 6 files changed, 60 insertions(+), 62 deletions(-)

diff --git 
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreator.java
 
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreator.java
index c9098dd7ab0..9bf02432acd 100644
--- 
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreator.java
+++ 
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreator.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.proxy.backend.mysql.handler.admin;
 
 import 
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
+import 
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutorCreator;
@@ -76,10 +77,10 @@ public final class MySQLAdminExecutorCreator implements 
DatabaseAdminExecutorCre
     
     @Override
     public Optional<DatabaseAdminExecutor> create(final SQLStatementContext 
sqlStatementContext, final String sql, final String databaseName, final 
List<Object> parameters) {
-        SQLStatement sqlStatement = sqlStatementContext.getSqlStatement();
-        if (sqlStatement instanceof SelectStatement) {
-            return create((SelectStatement) sqlStatement, sql, databaseName, 
parameters);
+        if (sqlStatementContext instanceof SelectStatementContext) {
+            return createExecutorForSelectStatement((SelectStatementContext) 
sqlStatementContext, sql, databaseName, parameters);
         }
+        SQLStatement sqlStatement = sqlStatementContext.getSqlStatement();
         if (sqlStatement instanceof UseStatement) {
             return Optional.of(new UseDatabaseExecutor((UseStatement) 
sqlStatement));
         }
@@ -110,21 +111,22 @@ public final class MySQLAdminExecutorCreator implements 
DatabaseAdminExecutorCre
         return Optional.empty();
     }
     
-    private Optional<DatabaseAdminExecutor> create(final SelectStatement 
selectStatement, final String sql, final String databaseName, final 
List<Object> parameters) {
-        if (!selectStatement.getFrom().isPresent()) {
-            return findAdminExecutorForSelectWithoutFrom(sql, databaseName, 
selectStatement);
+    private Optional<DatabaseAdminExecutor> 
createExecutorForSelectStatement(final SelectStatementContext 
selectStatementContext, final String sql,
+                                                                             
final String databaseName, final List<Object> parameters) {
+        if (!selectStatementContext.getSqlStatement().getFrom().isPresent()) {
+            return findAdminExecutorForSelectWithoutFrom(sql, databaseName, 
selectStatementContext.getSqlStatement());
         }
-        if (isQueryInformationSchema(databaseName)) {
-            return 
MySQLInformationSchemaExecutorFactory.newInstance(selectStatement, sql, 
parameters);
+        if (INFORMATION_SCHEMA.equalsIgnoreCase(databaseName) && 
!ProxyContext.getInstance().getContextManager().getDatabase(databaseName).isComplete())
 {
+            return 
MySQLInformationSchemaExecutorFactory.newInstance(selectStatementContext, sql, 
parameters);
         }
-        if (isQueryPerformanceSchema(databaseName)) {
-            return 
MySQLPerformanceSchemaExecutorFactory.newInstance(selectStatement, sql, 
parameters);
+        if (PERFORMANCE_SCHEMA.equalsIgnoreCase(databaseName) && 
!ProxyContext.getInstance().getContextManager().getDatabase(databaseName).isComplete())
 {
+            return 
MySQLPerformanceSchemaExecutorFactory.newInstance(selectStatementContext, sql, 
parameters);
         }
-        if (isQueryMySQLSchema(databaseName)) {
-            return 
MySQLMySQLSchemaExecutorFactory.newInstance(selectStatement, sql, parameters);
+        if (MYSQL_SCHEMA.equalsIgnoreCase(databaseName) && 
!ProxyContext.getInstance().getContextManager().getDatabase(databaseName).isComplete())
 {
+            return 
MySQLMySQLSchemaExecutorFactory.newInstance(selectStatementContext, sql, 
parameters);
         }
-        if (isQuerySysSchema(databaseName)) {
-            return MySQLSysSchemaExecutorFactory.newInstance(selectStatement, 
sql, parameters);
+        if (SYS_SCHEMA.equalsIgnoreCase(databaseName) && 
!ProxyContext.getInstance().getContextManager().getDatabase(databaseName).isComplete())
 {
+            return 
MySQLSysSchemaExecutorFactory.newInstance(selectStatementContext, sql, 
parameters);
         }
         return Optional.empty();
     }
@@ -141,8 +143,7 @@ public final class MySQLAdminExecutorCreator implements 
DatabaseAdminExecutorCre
         if (isShowSpecialFunction(selectStatement, 
ShowVersionExecutor.FUNCTION_NAME)) {
             return Optional.of(new ShowVersionExecutor(selectStatement));
         }
-        if (isShowSpecialFunction(selectStatement, 
ShowCurrentUserExecutor.FUNCTION_NAME)
-                || isShowSpecialFunction(selectStatement, 
ShowCurrentUserExecutor.FUNCTION_NAME_ALIAS)) {
+        if (isShowSpecialFunction(selectStatement, 
ShowCurrentUserExecutor.FUNCTION_NAME) || 
isShowSpecialFunction(selectStatement, 
ShowCurrentUserExecutor.FUNCTION_NAME_ALIAS)) {
             return Optional.of(new ShowCurrentUserExecutor());
         }
         if (isShowSpecialFunction(selectStatement, 
ShowCurrentDatabaseExecutor.FUNCTION_NAME)) {
@@ -154,25 +155,7 @@ public final class MySQLAdminExecutorCreator implements 
DatabaseAdminExecutorCre
     private boolean isShowSpecialFunction(final SelectStatement sqlStatement, 
final String functionName) {
         Iterator<ProjectionSegment> segmentIterator = 
sqlStatement.getProjections().getProjections().iterator();
         ProjectionSegment firstProjection = segmentIterator.next();
-        return !segmentIterator.hasNext() && firstProjection instanceof 
ExpressionProjectionSegment
-                && 
functionName.equalsIgnoreCase(((ExpressionProjectionSegment) 
firstProjection).getText());
-    }
-    
-    private boolean isQueryInformationSchema(final String databaseName) {
-        // TODO remove DefaultDatabaseMetaDataExecutor when sql federation can 
support all system table query
-        return INFORMATION_SCHEMA.equalsIgnoreCase(databaseName) && 
!ProxyContext.getInstance().getContextManager().getDatabase(databaseName).isComplete();
-    }
-    
-    private boolean isQueryPerformanceSchema(final String databaseName) {
-        return PERFORMANCE_SCHEMA.equalsIgnoreCase(databaseName);
-    }
-    
-    private boolean isQueryMySQLSchema(final String databaseName) {
-        return MYSQL_SCHEMA.equalsIgnoreCase(databaseName);
-    }
-    
-    private boolean isQuerySysSchema(final String databaseName) {
-        return SYS_SCHEMA.equalsIgnoreCase(databaseName);
+        return !segmentIterator.hasNext() && firstProjection instanceof 
ExpressionProjectionSegment && 
functionName.equalsIgnoreCase(((ExpressionProjectionSegment) 
firstProjection).getText());
     }
     
     private Optional<DatabaseAdminExecutor> mockExecutor(final String 
databaseName, final SelectStatement sqlStatement, final String sql) {
diff --git 
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLInformationSchemaExecutorFactory.java
 
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLInformationSchemaExecutorFactory.java
index 63116373d4f..2cc8f0b696c 100644
--- 
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLInformationSchemaExecutorFactory.java
+++ 
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLInformationSchemaExecutorFactory.java
@@ -19,6 +19,7 @@ package 
org.apache.shardingsphere.proxy.backend.mysql.handler.admin;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.executor.AbstractDatabaseMetaDataExecutor.DefaultDatabaseMetaDataExecutor;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
@@ -26,11 +27,7 @@ import 
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.info
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement;
 
-import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Optional;
 
 /**
@@ -44,12 +41,13 @@ public final class MySQLInformationSchemaExecutorFactory {
     /**
      * Create executor.
      *
-     * @param sqlStatement SQL statement
+     * @param selectStatementContext select statement context
      * @param sql SQL being executed
      * @param parameters parameters
      * @return executor
      */
-    public static Optional<DatabaseAdminExecutor> newInstance(final 
SelectStatement sqlStatement, final String sql, final List<Object> parameters) {
+    public static Optional<DatabaseAdminExecutor> newInstance(final 
SelectStatementContext selectStatementContext, final String sql, final 
List<Object> parameters) {
+        SelectStatement sqlStatement = 
selectStatementContext.getSqlStatement();
         if (!sqlStatement.getFrom().isPresent() || 
!(sqlStatement.getFrom().get() instanceof SimpleTableSegment)) {
             return Optional.empty();
         }
@@ -57,19 +55,9 @@ public final class MySQLInformationSchemaExecutorFactory {
         if (SCHEMATA_TABLE.equalsIgnoreCase(tableName)) {
             return Optional.of(new 
SelectInformationSchemataExecutor(sqlStatement, sql, parameters));
         }
-        Map<String, Collection<String>> selectedSchemaTables = 
Collections.singletonMap("information_schema", 
Collections.singletonList(tableName));
-        if (isSelectSystemTable(selectedSchemaTables)) {
+        if (SystemSchemaManager.isSystemTable("mysql", "information_schema", 
tableName)) {
             return Optional.of(new DefaultDatabaseMetaDataExecutor(sql, 
parameters));
         }
         return Optional.empty();
     }
-    
-    private static boolean isSelectSystemTable(final Map<String, 
Collection<String>> selectedSchemaTableNames) {
-        for (Entry<String, Collection<String>> each : 
selectedSchemaTableNames.entrySet()) {
-            if (!SystemSchemaManager.isSystemTable("mysql", each.getKey(), 
each.getValue())) {
-                return false;
-            }
-        }
-        return true;
-    }
 }
diff --git 
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLMySQLSchemaExecutorFactory.java
 
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLMySQLSchemaExecutorFactory.java
index 78c2a9a5610..41051292000 100644
--- 
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLMySQLSchemaExecutorFactory.java
+++ 
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLMySQLSchemaExecutorFactory.java
@@ -19,6 +19,7 @@ package 
org.apache.shardingsphere.proxy.backend.mysql.handler.admin;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.executor.AbstractDatabaseMetaDataExecutor.DefaultDatabaseMetaDataExecutor;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
@@ -37,12 +38,13 @@ public final class MySQLMySQLSchemaExecutorFactory {
     /**
      * Create executor.
      *
-     * @param sqlStatement SQL statement
+     * @param selectStatementContext select statement context
      * @param sql SQL being executed
      * @param parameters parameters
      * @return executor
      */
-    public static Optional<DatabaseAdminExecutor> newInstance(final 
SelectStatement sqlStatement, final String sql, final List<Object> parameters) {
+    public static Optional<DatabaseAdminExecutor> newInstance(final 
SelectStatementContext selectStatementContext, final String sql, final 
List<Object> parameters) {
+        SelectStatement sqlStatement = 
selectStatementContext.getSqlStatement();
         if (!sqlStatement.getFrom().isPresent() || 
!(sqlStatement.getFrom().get() instanceof SimpleTableSegment)) {
             return Optional.empty();
         }
diff --git 
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLPerformanceSchemaExecutorFactory.java
 
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLPerformanceSchemaExecutorFactory.java
index e8d261fc94d..91766ab7f03 100644
--- 
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLPerformanceSchemaExecutorFactory.java
+++ 
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLPerformanceSchemaExecutorFactory.java
@@ -19,6 +19,7 @@ package 
org.apache.shardingsphere.proxy.backend.mysql.handler.admin;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.executor.AbstractDatabaseMetaDataExecutor.DefaultDatabaseMetaDataExecutor;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
@@ -37,12 +38,13 @@ public final class MySQLPerformanceSchemaExecutorFactory {
     /**
      * Create executor.
      *
-     * @param sqlStatement SQL statement
+     * @param selectStatementContext select statement context
      * @param sql SQL being executed
      * @param parameters parameters
      * @return executor
      */
-    public static Optional<DatabaseAdminExecutor> newInstance(final 
SelectStatement sqlStatement, final String sql, final List<Object> parameters) {
+    public static Optional<DatabaseAdminExecutor> newInstance(final 
SelectStatementContext selectStatementContext, final String sql, final 
List<Object> parameters) {
+        SelectStatement sqlStatement = 
selectStatementContext.getSqlStatement();
         if (!sqlStatement.getFrom().isPresent() || 
!(sqlStatement.getFrom().get() instanceof SimpleTableSegment)) {
             return Optional.empty();
         }
diff --git 
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSysSchemaExecutorFactory.java
 
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSysSchemaExecutorFactory.java
index 062993ab374..6c4c637a1aa 100644
--- 
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSysSchemaExecutorFactory.java
+++ 
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSysSchemaExecutorFactory.java
@@ -19,6 +19,7 @@ package 
org.apache.shardingsphere.proxy.backend.mysql.handler.admin;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.executor.AbstractDatabaseMetaDataExecutor.DefaultDatabaseMetaDataExecutor;
 import 
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
@@ -37,12 +38,13 @@ public final class MySQLSysSchemaExecutorFactory {
     /**
      * Create executor.
      *
-     * @param sqlStatement SQL statement
+     * @param selectStatementContext select statement context
      * @param sql SQL being executed
      * @param parameters parameters
      * @return executor
      */
-    public static Optional<DatabaseAdminExecutor> newInstance(final 
SelectStatement sqlStatement, final String sql, final List<Object> parameters) {
+    public static Optional<DatabaseAdminExecutor> newInstance(final 
SelectStatementContext selectStatementContext, final String sql, final 
List<Object> parameters) {
+        SelectStatement sqlStatement = 
selectStatementContext.getSqlStatement();
         if (!sqlStatement.getFrom().isPresent() || 
!(sqlStatement.getFrom().get() instanceof SimpleTableSegment)) {
             return Optional.empty();
         }
diff --git 
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
 
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
index 64c8aacef60..7cacbb97766 100644
--- 
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
+++ 
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.proxy.backend.mysql.handler.admin;
 
 import 
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
+import 
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -70,7 +71,6 @@ import org.apache.shardingsphere.test.mock.AutoMockExtension;
 import org.apache.shardingsphere.test.mock.StaticMockSettings;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
 
 import java.util.Collection;
 import java.util.Collections;
@@ -92,11 +92,9 @@ class MySQLAdminExecutorCreatorTest {
     
     private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
     
-    @Mock
-    private SQLStatementContext sqlStatementContext;
-    
     @Test
     void assertCreateWithMySQLShowFunctionStatus() {
+        SQLStatementContext sqlStatementContext = 
mock(SQLStatementContext.class);
         when(sqlStatementContext.getSqlStatement()).thenReturn(new 
MySQLShowFunctionStatusStatement());
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "", "", 
Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -105,6 +103,7 @@ class MySQLAdminExecutorCreatorTest {
     
     @Test
     void assertCreateWithShowProcedureStatus() {
+        SQLStatementContext sqlStatementContext = 
mock(SQLStatementContext.class);
         when(sqlStatementContext.getSqlStatement()).thenReturn(new 
MySQLShowProcedureStatusStatement());
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "", "", 
Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -113,6 +112,7 @@ class MySQLAdminExecutorCreatorTest {
     
     @Test
     void assertCreateWithShowTables() {
+        SQLStatementContext sqlStatementContext = 
mock(SQLStatementContext.class);
         when(sqlStatementContext.getSqlStatement()).thenReturn(new 
MySQLShowTablesStatement());
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "", "", 
Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -121,11 +121,13 @@ class MySQLAdminExecutorCreatorTest {
     
     @Test
     void assertCreateWithOtherSQLStatementContext() {
+        SQLStatementContext sqlStatementContext = 
mock(SQLStatementContext.class);
         assertThat(new 
MySQLAdminExecutorCreator().create(sqlStatementContext), is(Optional.empty()));
     }
     
     @Test
     void assertCreateWithUse() {
+        SQLStatementContext sqlStatementContext = 
mock(SQLStatementContext.class);
         when(sqlStatementContext.getSqlStatement()).thenReturn(new 
MySQLUseStatement());
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "use db", "", 
Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -134,6 +136,7 @@ class MySQLAdminExecutorCreatorTest {
     
     @Test
     void assertCreateWithMySQLShowDatabasesStatement() {
+        SQLStatementContext sqlStatementContext = 
mock(SQLStatementContext.class);
         when(sqlStatementContext.getSqlStatement()).thenReturn(new 
MySQLShowDatabasesStatement());
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "", "", 
Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -142,6 +145,7 @@ class MySQLAdminExecutorCreatorTest {
     
     @Test
     void assertCreateWithMySQLShowProcessListStatement() {
+        SQLStatementContext sqlStatementContext = 
mock(SQLStatementContext.class);
         when(sqlStatementContext.getSqlStatement()).thenReturn(new 
MySQLShowProcessListStatement(false));
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "", "", 
Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -150,6 +154,7 @@ class MySQLAdminExecutorCreatorTest {
     
     @Test
     void assertCreateWithMySQLShowCreateDatabaseStatement() {
+        SQLStatementContext sqlStatementContext = 
mock(SQLStatementContext.class);
         when(sqlStatementContext.getSqlStatement()).thenReturn(new 
MySQLShowCreateDatabaseStatement());
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "", "", 
Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -158,6 +163,7 @@ class MySQLAdminExecutorCreatorTest {
     
     @Test
     void assertCreateWithSetStatement() {
+        SQLStatementContext sqlStatementContext = 
mock(SQLStatementContext.class);
         when(sqlStatementContext.getSqlStatement()).thenReturn(new 
MySQLSetStatement());
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "", "", 
Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -166,6 +172,7 @@ class MySQLAdminExecutorCreatorTest {
     
     @Test
     void assertCreateWithSelectStatementForShowConnectionId() {
+        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class);
         MySQLSelectStatement selectStatement = 
mock(MySQLSelectStatement.class);
         when(selectStatement.getFrom()).thenReturn(Optional.empty());
         ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
@@ -179,6 +186,7 @@ class MySQLAdminExecutorCreatorTest {
     
     @Test
     void assertCreateWithSelectStatementForShowVersion() {
+        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class);
         MySQLSelectStatement selectStatement = 
mock(MySQLSelectStatement.class);
         when(selectStatement.getFrom()).thenReturn(Optional.empty());
         ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
@@ -192,6 +200,7 @@ class MySQLAdminExecutorCreatorTest {
     
     @Test
     void assertCreateWithSelectStatementForCurrentUser() {
+        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class);
         MySQLSelectStatement selectStatement = 
mock(MySQLSelectStatement.class);
         when(selectStatement.getFrom()).thenReturn(Optional.empty());
         ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
@@ -205,6 +214,7 @@ class MySQLAdminExecutorCreatorTest {
     
     @Test
     void assertCreateWithSelectStatementForTransactionReadOnly() {
+        
         initProxyContext(Collections.emptyList());
         MySQLSelectStatement selectStatement = 
mock(MySQLSelectStatement.class);
         when(selectStatement.getFrom()).thenReturn(Optional.empty());
@@ -212,6 +222,7 @@ class MySQLAdminExecutorCreatorTest {
         VariableSegment variableSegment = new VariableSegment(0, 0, 
"transaction_read_only", "SESSION");
         
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
 ExpressionProjectionSegment(0, 10, "@@session.transaction_read_only", 
variableSegment)));
         when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class);
         
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "select 
@@session.transaction_read_only", "", Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -227,6 +238,7 @@ class MySQLAdminExecutorCreatorTest {
         VariableSegment variableSegment = new VariableSegment(0, 0, 
"transaction_isolation", "SESSION");
         
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
 ExpressionProjectionSegment(0, 10, "@@session.transaction_isolation", 
variableSegment)));
         when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class);
         
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "select 
@@session.transaction_isolation", "", Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -241,6 +253,7 @@ class MySQLAdminExecutorCreatorTest {
         ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
         
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
 ExpressionProjectionSegment(0, 10, "DATABASE()")));
         when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class);
         
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "select DATABASE()", 
"", Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -255,6 +268,7 @@ class MySQLAdminExecutorCreatorTest {
         ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
         
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
 ExpressionProjectionSegment(0, 10, "CURRENT_DATE()")));
         when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class);
         
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "select 
CURRENT_DATE()", null, Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -273,6 +287,7 @@ class MySQLAdminExecutorCreatorTest {
         ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
         
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
 ExpressionProjectionSegment(0, 10, "CURRENT_DATE()")));
         when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class);
         
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "select 
CURRENT_DATE()", "test_db", Collections.emptyList());
         assertThat(actual, is(Optional.empty()));
@@ -290,6 +305,7 @@ class MySQLAdminExecutorCreatorTest {
         ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
         
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
 ExpressionProjectionSegment(0, 10, "CURRENT_DATE()")));
         when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class);
         
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "select 
CURRENT_DATE()", null, Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -303,6 +319,7 @@ class MySQLAdminExecutorCreatorTest {
         tableSegment.setOwner(new OwnerSegment(7, 8, new 
IdentifierValue("information_schema")));
         MySQLSelectStatement selectStatement = 
mock(MySQLSelectStatement.class);
         when(selectStatement.getFrom()).thenReturn(Optional.of(tableSegment));
+        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class);
         
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "select ENGINE from 
ENGINES", "information_schema", Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -316,6 +333,7 @@ class MySQLAdminExecutorCreatorTest {
         tableSegment.setOwner(new OwnerSegment(7, 8, new 
IdentifierValue("information_schema")));
         MySQLSelectStatement selectStatement = 
mock(MySQLSelectStatement.class);
         when(selectStatement.getFrom()).thenReturn(Optional.of(tableSegment));
+        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class);
         
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "select SCHEMA_NAME 
from SCHEMATA", "information_schema", Collections.emptyList());
         assertTrue(actual.isPresent());
@@ -331,6 +349,7 @@ class MySQLAdminExecutorCreatorTest {
         SimpleTableSegment tableSegment = new SimpleTableSegment(new 
TableNameSegment(10, 13, new IdentifierValue("CHARACTER_SETS")));
         tableSegment.setOwner(new OwnerSegment(7, 8, new 
IdentifierValue("information_schema")));
         MySQLSelectStatement selectStatement = 
mock(MySQLSelectStatement.class);
+        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class);
         when(selectStatement.getFrom()).thenReturn(Optional.of(tableSegment));
         
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "select 
CHARACTER_SET_NAME from CHARACTER_SETS", "", Collections.emptyList());
@@ -344,6 +363,7 @@ class MySQLAdminExecutorCreatorTest {
         tableSegment.setOwner(new OwnerSegment(7, 8, new 
IdentifierValue("performance_schema")));
         MySQLSelectStatement selectStatement = 
mock(MySQLSelectStatement.class);
         when(selectStatement.getFrom()).thenReturn(Optional.of(tableSegment));
+        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class);
         
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "select * from 
accounts", "", Collections.emptyList());
         assertFalse(actual.isPresent());
@@ -359,6 +379,7 @@ class MySQLAdminExecutorCreatorTest {
     
     @Test
     void assertCreateWithDMLStatement() {
+        SQLStatementContext sqlStatementContext = 
mock(SQLStatementContext.class);
         when(sqlStatementContext.getSqlStatement()).thenReturn(new 
MySQLDeleteStatement());
         Optional<DatabaseAdminExecutor> actual = new 
MySQLAdminExecutorCreator().create(sqlStatementContext, "delete from t", "", 
Collections.emptyList());
         assertThat(actual, is(Optional.empty()));

Reply via email to