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

panjuan 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 99166c4  fix calcite select result merge error when call execute 
method (#10758)
99166c4 is described below

commit 99166c491f1e3005946dc7324094a08e812121af
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Fri Jun 11 13:29:00 2021 +0800

    fix calcite select result merge error when call execute method (#10758)
    
    * fix calcite select result merge error when call execute method
    
    * fix test case
---
 .../select/projection/engine/ProjectionEngine.java |   4 +-
 .../engine/ProjectionsContextEngine.java           |   2 +-
 .../projection/engine/ProjectionEngineTest.java    |  23 +++-
 .../statement/ShardingSpherePreparedStatement.java |   7 ++
 .../core/statement/ShardingSphereStatement.java    |  83 ++++---------
 ...actShardingSphereDataSourceForFederateTest.java |  25 ++++
 .../statement/FederatePrepareStatementTest.java    | 107 ++++++++++++----
 .../jdbc/core/statement/FederateStatementTest.java | 138 ++++++++++++++++-----
 8 files changed, 274 insertions(+), 115 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngine.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngine.java
index d4f930f..dfdc135 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngine.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngine.java
@@ -39,7 +39,7 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.Sim
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.LinkedList;
+import java.util.LinkedHashSet;
 import java.util.Optional;
 import java.util.stream.Collectors;
 
@@ -130,7 +130,7 @@ public final class ProjectionEngine {
     }
     
     private Collection<ColumnProjection> getUnqualifiedShorthandColumns(final 
Collection<SimpleTableSegment> tables) {
-        Collection<ColumnProjection> result = new LinkedList<>();
+        Collection<ColumnProjection> result = new LinkedHashSet<>();
         for (SimpleTableSegment each : tables) {
             String owner = 
each.getAlias().orElse(each.getTableName().getIdentifier().getValue());
             result.addAll(schema.getAllColumnNames(
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngine.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngine.java
index 0014cf1..05b6ca2 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngine.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngine.java
@@ -18,7 +18,6 @@
 package 
org.apache.shardingsphere.infra.binder.segment.select.projection.engine;
 
 import com.google.common.base.Preconditions;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.binder.segment.select.groupby.GroupByContext;
 import 
org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByContext;
 import 
org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByItem;
@@ -27,6 +26,7 @@ import 
org.apache.shardingsphere.infra.binder.segment.select.projection.Projecti
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.ProjectionsContext;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.DerivedProjection;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ShorthandProjection;
+import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.ColumnOrderByItemSegment;
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java
index c8f0581..779e261 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java
@@ -17,13 +17,15 @@
 
 package 
org.apache.shardingsphere.infra.binder.segment.select.projection.engine;
 
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.Projection;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.AggregationDistinctProjection;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.AggregationProjection;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ExpressionProjection;
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ShorthandProjection;
+import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import 
org.apache.shardingsphere.sql.parser.sql.common.constant.AggregationType;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationDistinctProjectionSegment;
@@ -33,17 +35,22 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.Expressi
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ShorthandProjectionSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
 import org.junit.Test;
 
+import java.util.Collection;
 import java.util.Collections;
+import java.util.LinkedList;
 import java.util.Optional;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public final class ProjectionEngineTest {
     
@@ -62,6 +69,20 @@ public final class ProjectionEngineTest {
     }
     
     @Test
+    public void 
assertCreateProjectionWhenProjectionSegmentInstanceOfShorthandProjectionSegmentAndDuplicateTableSegment()
 {
+        Collection<SimpleTableSegment> tableSegments = new LinkedList<>();
+        tableSegments.add(new SimpleTableSegment(0, 0, new 
IdentifierValue("t_order")));
+        tableSegments.add(new SimpleTableSegment(0, 0, new 
IdentifierValue("t_order")));
+        ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
+        
when(schema.getAllColumnNames("t_order")).thenReturn(Lists.newArrayList("order_id",
 "content"));
+        Optional<Projection> actual = new 
ProjectionEngine(schema).createProjection(tableSegments, new 
ShorthandProjectionSegment(0, 0));
+        assertTrue(actual.isPresent());
+        assertThat(actual.get(), instanceOf(ShorthandProjection.class));
+        assertThat(((ShorthandProjection) 
actual.get()).getActualColumns().size(), is(2));
+        assertThat(((ShorthandProjection) actual.get()).getActualColumns(), 
is(Sets.newHashSet(new ColumnProjection("t_order", "order_id", null), new 
ColumnProjection("t_order", "content", null))));
+    }
+    
+    @Test
     public void 
assertCreateProjectionWhenProjectionSegmentInstanceOfColumnProjectionSegment() {
         ColumnProjectionSegment columnProjectionSegment = new 
ColumnProjectionSegment(new ColumnSegment(0, 10, new IdentifierValue("name")));
         columnProjectionSegment.setAlias(new AliasSegment(0, 0, new 
IdentifierValue("alias")));
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
index 12d0f8b..4c922fc 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
@@ -274,6 +274,10 @@ public final class ShardingSpherePreparedStatement extends 
AbstractPreparedState
                 Collection<ExecuteResult> executeResults = 
rawExecutor.execute(createRawExecutionGroupContext(), 
executionContext.getSqlStatementContext(), new RawSQLExecutorCallback());
                 return executeResults.iterator().next() instanceof QueryResult;
             }
+            if (executionContext.getRouteContext().isFederated()) {
+                List<QueryResult> queryResults = executeFederatedQuery();
+                return !queryResults.isEmpty();
+            }
             ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext = 
createExecutionGroupContext();
             cacheStatements(executionGroupContext.getInputGroups());
             return driverJDBCExecutor.execute(executionGroupContext,
@@ -336,6 +340,9 @@ public final class ShardingSpherePreparedStatement extends 
AbstractPreparedState
         for (Statement each : statements) {
             result.add(each.getResultSet());
         }
+        if (executionContext.getRouteContext().isFederated()) {
+            result.add(federateExecutor.getResultSet());
+        }
         return result;
     }
     
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
index aa14e2d..6330473 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
@@ -291,20 +291,7 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
     
     @Override
     public boolean execute(final String sql) throws SQLException {
-        try {
-            executionContext = createExecutionContext(sql);
-            if 
(metaDataContexts.getDefaultMetaData().getRuleMetaData().getRules().stream().anyMatch(each
 -> each instanceof RawExecutionRule)) {
-                // TODO process getStatement
-                Collection<ExecuteResult> results = 
rawExecutor.execute(createRawExecutionContext(), 
executionContext.getSqlStatementContext(), new RawSQLExecutorCallback());
-                return results.iterator().next() instanceof QueryResult;
-            }
-            ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext = 
createExecutionContext();
-            cacheStatements(executionGroupContext.getInputGroups());
-            return execute(executionGroupContext,
-                (actualSQL, statement) -> statement.execute(actualSQL), 
executionContext.getSqlStatementContext().getSqlStatement(), 
executionContext.getRouteContext().getRouteUnits());
-        } finally {
-            currentResultSet = null;
-        }
+        return execute0(sql, (actualSQL, statement) -> 
statement.execute(actualSQL));
     }
     
     @Override
@@ -312,58 +299,19 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
         if (RETURN_GENERATED_KEYS == autoGeneratedKeys) {
             returnGeneratedKeys = true;
         }
-        try {
-            executionContext = createExecutionContext(sql);
-            if 
(metaDataContexts.getDefaultMetaData().getRuleMetaData().getRules().stream().anyMatch(each
 -> each instanceof RawExecutionRule)) {
-                // TODO process getStatement
-                Collection<ExecuteResult> results = 
rawExecutor.execute(createRawExecutionContext(), 
executionContext.getSqlStatementContext(), new RawSQLExecutorCallback());
-                return results.iterator().next() instanceof QueryResult;
-            }
-            ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext = 
createExecutionContext();
-            cacheStatements(executionGroupContext.getInputGroups());
-            return execute(executionGroupContext, (actualSQL, statement) -> 
statement.execute(actualSQL, autoGeneratedKeys),
-                    
executionContext.getSqlStatementContext().getSqlStatement(), 
executionContext.getRouteContext().getRouteUnits());
-        } finally {
-            currentResultSet = null;
-        }
+        return execute0(sql, (actualSQL, statement) -> 
statement.execute(actualSQL, autoGeneratedKeys));
     }
     
     @Override
     public boolean execute(final String sql, final int[] columnIndexes) throws 
SQLException {
         returnGeneratedKeys = true;
-        try {
-            executionContext = createExecutionContext(sql);
-            if 
(metaDataContexts.getDefaultMetaData().getRuleMetaData().getRules().stream().anyMatch(each
 -> each instanceof RawExecutionRule)) {
-                // TODO process getStatement
-                Collection<ExecuteResult> results = 
rawExecutor.execute(createRawExecutionContext(), 
executionContext.getSqlStatementContext(), new RawSQLExecutorCallback());
-                return results.iterator().next() instanceof QueryResult;
-            }
-            ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext = 
createExecutionContext();
-            cacheStatements(executionGroupContext.getInputGroups());
-            return execute(executionGroupContext, (actualSQL, statement) -> 
statement.execute(actualSQL, columnIndexes),
-                    
executionContext.getSqlStatementContext().getSqlStatement(), 
executionContext.getRouteContext().getRouteUnits());
-        } finally {
-            currentResultSet = null;
-        }
+        return execute0(sql, (actualSQL, statement) -> 
statement.execute(actualSQL, columnIndexes));
     }
     
     @Override
     public boolean execute(final String sql, final String[] columnNames) 
throws SQLException {
         returnGeneratedKeys = true;
-        try {
-            executionContext = createExecutionContext(sql);
-            if 
(metaDataContexts.getDefaultMetaData().getRuleMetaData().getRules().stream().anyMatch(each
 -> each instanceof RawExecutionRule)) {
-                // TODO process getStatement
-                Collection<ExecuteResult> results = 
rawExecutor.execute(createRawExecutionContext(), 
executionContext.getSqlStatementContext(), new RawSQLExecutorCallback());
-                return results.iterator().next() instanceof QueryResult;
-            }
-            ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext = 
createExecutionContext();
-            cacheStatements(executionGroupContext.getInputGroups());
-            return execute(executionGroupContext, (actualSQL, statement) -> 
statement.execute(actualSQL, columnNames),
-                    
executionContext.getSqlStatementContext().getSqlStatement(), 
executionContext.getRouteContext().getRouteUnits());
-        } finally {
-            currentResultSet = null;
-        }
+        return execute0(sql, (actualSQL, statement) -> 
statement.execute(actualSQL, columnNames));
     }
     
     private boolean execute(final ExecutionGroupContext<JDBCExecutionUnit> 
executionGroupContext, final ExecuteCallback executor,
@@ -385,6 +333,26 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
         return driverJDBCExecutor.execute(executionGroupContext, 
executionContext.getSqlStatementContext(), routeUnits, jdbcExecutorCallback);
     }
     
+    private boolean execute0(final String sql, final ExecuteCallback callback) 
throws SQLException {
+        try {
+            executionContext = createExecutionContext(sql);
+            if 
(metaDataContexts.getDefaultMetaData().getRuleMetaData().getRules().stream().anyMatch(each
 -> each instanceof RawExecutionRule)) {
+                // TODO process getStatement
+                Collection<ExecuteResult> results = 
rawExecutor.execute(createRawExecutionContext(), 
executionContext.getSqlStatementContext(), new RawSQLExecutorCallback());
+                return results.iterator().next() instanceof QueryResult;
+            }
+            if (executionContext.getRouteContext().isFederated()) {
+                List<QueryResult> queryResults = executeFederatedQuery();
+                return !queryResults.isEmpty();
+            }
+            ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext = 
createExecutionContext();
+            cacheStatements(executionGroupContext.getInputGroups());
+            return execute(executionGroupContext, callback, 
executionContext.getSqlStatementContext().getSqlStatement(), 
executionContext.getRouteContext().getRouteUnits());
+        } finally {
+            currentResultSet = null;
+        }
+    }
+    
     private void clearStatements() throws SQLException {
         for (Statement each : statements) {
             each.close();
@@ -457,6 +425,9 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
         for (Statement each : statements) {
             result.add(each.getResultSet());
         }
+        if (executionContext.getRouteContext().isFederated()) {
+            result.add(federateExecutor.getResultSet());
+        }
         return result;
     }
     
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForFederateTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForFederateTest.java
index 1e3d919..8a39d0a 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForFederateTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForFederateTest.java
@@ -32,7 +32,10 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -92,4 +95,26 @@ public abstract class 
AbstractShardingSphereDataSourceForFederateTest extends Ab
         dataSource.close();
         dataSource = null;
     }
+        
+    protected final ResultSet getResultSet(final PreparedStatement 
preparedStatement, final boolean executeQuery) throws SQLException {
+        ResultSet resultSet;
+        if (executeQuery) {
+            resultSet = preparedStatement.executeQuery();
+        } else {
+            preparedStatement.execute();
+            resultSet = preparedStatement.getResultSet();
+        }
+        return resultSet;
+    }
+    
+    protected final ResultSet getResultSet(final Statement statement, final 
String sql, final boolean executeQuery) throws SQLException {
+        ResultSet resultSet;
+        if (executeQuery) {
+            resultSet = statement.executeQuery(sql);
+        } else {
+            statement.execute(sql);
+            resultSet = statement.getResultSet();
+        }
+        return resultSet;
+    }
 }
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederatePrepareStatementTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederatePrepareStatementTest.java
index b1f2924..426ce3a 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederatePrepareStatementTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederatePrepareStatementTest.java
@@ -24,9 +24,9 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 
 import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 public final class FederatePrepareStatementTest extends 
AbstractShardingSphereDataSourceForFederateTest {
@@ -64,11 +64,20 @@ public final class FederatePrepareStatementTest extends 
AbstractShardingSphereDa
                     + "where o.order_id_sharding = i.item_id and i.order_id > 
?";
 
     @Test
-    public void assertQueryWithFederateInSingleTables() throws SQLException {
+    public void assertQueryWithFederateInSingleTablesByExecuteQuery() throws 
SQLException {
+        assertQueryWithFederateInSingleTables(true);
+    }
+    
+    @Test
+    public void assertQueryWithFederateInSingleTablesByExecute() throws 
SQLException {
+        assertQueryWithFederateInSingleTables(false);
+    }
+    
+    private void assertQueryWithFederateInSingleTables(final boolean 
executeQuery) throws SQLException {
         ShardingSpherePreparedStatement preparedStatement = 
(ShardingSpherePreparedStatement) 
getShardingSphereDataSource().getConnection().prepareStatement(SELECT_SQL_BY_ID_ACROSS_SINGLE_TABLES);
         preparedStatement.setInt(1, 1000);
         preparedStatement.setInt(2, 100000);
-        ResultSet resultSet = preparedStatement.executeQuery();
+        ResultSet resultSet = getResultSet(preparedStatement, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(1000));
@@ -80,13 +89,22 @@ public final class FederatePrepareStatementTest extends 
AbstractShardingSphereDa
         assertThat(resultSet.getString(7), is("init"));
         assertFalse(resultSet.next());
     }
-
+    
+    @Test
+    public void 
assertQueryWithFederateInSingleAndShardingTableByExecuteQuery() throws 
SQLException {
+        assertQueryWithFederateInSingleAndShardingTable(true);
+    }
+    
     @Test
-    public void assertQueryWithFederateInSingleAndShardingTable() throws 
SQLException {
+    public void assertQueryWithFederateInSingleAndShardingTableByExecute() 
throws SQLException {
+        assertQueryWithFederateInSingleAndShardingTable(false);
+    }
+    
+    private void assertQueryWithFederateInSingleAndShardingTable(final boolean 
executeQuery) throws SQLException {
         ShardingSpherePreparedStatement preparedStatement = 
(ShardingSpherePreparedStatement) getShardingSphereDataSource()
                 
.getConnection().prepareStatement(SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES);
         preparedStatement.setInt(1, 10001);
-        ResultSet resultSet = preparedStatement.executeQuery();
+        ResultSet resultSet = getResultSet(preparedStatement, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(1001));
@@ -96,13 +114,22 @@ public final class FederatePrepareStatementTest extends 
AbstractShardingSphereDa
         assertThat(resultSet.getInt(5), is(10001));
         assertFalse(resultSet.next());
     }
-
+    
+    @Test
+    public void 
assertQueryWithFederateInSingleAndShardingTableWithAliasByExecuteQuery() throws 
SQLException {
+        assertQueryWithFederateInSingleAndShardingTableWithAlias(true);
+    }
+    
     @Test
-    public void assertQueryWithFederateInSingleAndShardingTableWithAlias() 
throws SQLException {
+    public void 
assertQueryWithFederateInSingleAndShardingTableWithAliasByExecute() throws 
SQLException {
+        assertQueryWithFederateInSingleAndShardingTableWithAlias(false);
+    }
+    
+    public void assertQueryWithFederateInSingleAndShardingTableWithAlias(final 
boolean executeQuery) throws SQLException {
         ShardingSpherePreparedStatement preparedStatement = 
(ShardingSpherePreparedStatement) getShardingSphereDataSource()
                 
.getConnection().prepareStatement(SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_ALIAS);
         preparedStatement.setInt(1, 10001);
-        ResultSet resultSet = preparedStatement.executeQuery();
+        ResultSet resultSet = getResultSet(preparedStatement, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(1001));
@@ -112,13 +139,22 @@ public final class FederatePrepareStatementTest extends 
AbstractShardingSphereDa
         assertThat(resultSet.getInt(5), is(10001));
         assertFalse(resultSet.next());
     }
-
+    
     @Test
-    public void assertQueryWithFederateInSingleAndShardingTableRewrite() 
throws SQLException {
+    public void 
assertQueryWithFederateInSingleAndShardingTableRewriteByExecuteQuery() throws 
SQLException {
+        assertQueryWithFederateInSingleAndShardingTableRewrite(true);
+    }
+    
+    @Test
+    public void 
assertQueryWithFederateInSingleAndShardingTableRewriteByExecute() throws 
SQLException {
+        assertQueryWithFederateInSingleAndShardingTableRewrite(false);
+    }
+    
+    private void assertQueryWithFederateInSingleAndShardingTableRewrite(final 
boolean executeQuery) throws SQLException {
         ShardingSpherePreparedStatement preparedStatement = 
(ShardingSpherePreparedStatement) getShardingSphereDataSource()
                 
.getConnection().prepareStatement(SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_REWRITE);
         preparedStatement.setInt(1, 11);
-        ResultSet resultSet = preparedStatement.executeQuery();
+        ResultSet resultSet = getResultSet(preparedStatement, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(1001));
@@ -128,7 +164,7 @@ public final class FederatePrepareStatementTest extends 
AbstractShardingSphereDa
         assertThat(resultSet.getInt(5), is(10001));
         assertFalse(resultSet.next());
         preparedStatement.setInt(1, 10);
-        ResultSet resultSet1 = preparedStatement.executeQuery();
+        ResultSet resultSet1 = getResultSet(preparedStatement, executeQuery);
         assertNotNull(resultSet1);
         assertTrue(resultSet1.next());
         assertThat(resultSet1.getInt(1), is(1000));
@@ -138,13 +174,22 @@ public final class FederatePrepareStatementTest extends 
AbstractShardingSphereDa
         assertThat(resultSet1.getInt(5), is(10000));
         assertFalse(resultSet1.next());
     }
-
+    
     @Test
-    public void assertQueryWithFederateInSingleTablesWithEncryptRule() throws 
SQLException {
+    public void 
assertQueryWithFederateInSingleTablesWithEncryptRuleByExecuteQuery() throws 
SQLException {
+        assertQueryWithFederateInSingleTablesWithEncryptRule(true);
+    }
+    
+    @Test
+    public void 
assertQueryWithFederateInSingleTablesWithEncryptRuleByExecute() throws 
SQLException {
+        assertQueryWithFederateInSingleTablesWithEncryptRule(false);
+    }
+    
+    private void assertQueryWithFederateInSingleTablesWithEncryptRule(final 
boolean executeQuery) throws SQLException {
         ShardingSpherePreparedStatement preparedStatement = 
(ShardingSpherePreparedStatement) getShardingSphereDataSource()
                 
.getConnection().prepareStatement(SELECT_SQL_BY_ID_ACROSS_SINGLE_TABLES_WITH_ENCRYPT);
         preparedStatement.setInt(1, 1);
-        ResultSet resultSet = preparedStatement.executeQuery();
+        ResultSet resultSet = getResultSet(preparedStatement, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(2));
@@ -156,13 +201,22 @@ public final class FederatePrepareStatementTest extends 
AbstractShardingSphereDa
         assertThat(resultSet.getString(3), is("description3"));
         assertFalse(resultSet.next());
     }
-
+    
     @Test
-    public void 
assertQueryWithFederateInSingleAndShardingTablesWithEncryptRule() throws 
SQLException {
+    public void 
assertQueryWithFederateInSingleAndShardingTablesWithEncryptRuleByExecuteQuery() 
throws SQLException {
+        assertQueryWithFederateInSingleAndShardingTablesWithEncryptRule(true); 
  
+    }
+    
+    @Test
+    public void 
assertQueryWithFederateInSingleAndShardingTablesWithEncryptRuleByExecute() 
throws SQLException {
+        assertQueryWithFederateInSingleAndShardingTablesWithEncryptRule(false);
+    }
+    
+    private void 
assertQueryWithFederateInSingleAndShardingTablesWithEncryptRule(final boolean 
executeQuery) throws SQLException {
         ShardingSpherePreparedStatement preparedStatement = 
(ShardingSpherePreparedStatement) getShardingSphereDataSource()
                 
.getConnection().prepareStatement(SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_WITH_ENCRYPT);
         preparedStatement.setInt(1, 1);
-        ResultSet resultSet = preparedStatement.executeQuery();
+        ResultSet resultSet = getResultSet(preparedStatement, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(2));
@@ -174,13 +228,22 @@ public final class FederatePrepareStatementTest extends 
AbstractShardingSphereDa
         assertThat(resultSet.getString(3), is("description3"));
         assertFalse(resultSet.next());
     }
-
+    
     @Test
-    public void assertQueryWithFederateBetweenTwoShardingTables() throws 
SQLException {
+    public void 
assertQueryWithFederateBetweenTwoShardingTablesByExecuteQuery() throws 
SQLException {
+        assertQueryWithFederateBetweenTwoShardingTables(true);
+    }
+    
+    @Test
+    public void assertQueryWithFederateBetweenTwoShardingTablesByExecute() 
throws SQLException {
+        assertQueryWithFederateBetweenTwoShardingTables(false);
+    }
+    
+    private void assertQueryWithFederateBetweenTwoShardingTables(final boolean 
executeQuery) throws SQLException {
         ShardingSpherePreparedStatement preparedStatement = 
(ShardingSpherePreparedStatement) getShardingSphereDataSource()
                 
.getConnection().prepareStatement(SELECT_SQL_BY_ID_ACROSS_TWO_SHARDING_TABLES);
         preparedStatement.setInt(1, 10000);
-        ResultSet resultSet = preparedStatement.executeQuery();
+        ResultSet resultSet = getResultSet(preparedStatement, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(1010));
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederateStatementTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederateStatementTest.java
index 57f25c9..55689b5 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederateStatementTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederateStatementTest.java
@@ -24,9 +24,9 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 
 import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 public final class FederateStatementTest extends 
AbstractShardingSphereDataSourceForFederateTest {
@@ -65,11 +65,20 @@ public final class FederateStatementTest extends 
AbstractShardingSphereDataSourc
     private static final String SELECT_SQL_BY_ID_ACROSS_TWO_SHARDING_TABLES =
             "select o.order_id_sharding, i.order_id from 
t_order_federate_sharding o, t_order_item_federate_sharding i "
                     + "where o.order_id_sharding = i.item_id";
-
+    
+    @Test
+    public void assertQueryWithFederateInSingleTablesByExecuteQuery() throws 
SQLException {
+        assertQueryWithFederateInSingleTables(true);
+    }
+    
     @Test
-    public void assertQueryWithFederateInSingleTables() throws SQLException {
-        ShardingSphereStatement preparedStatement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
-        ResultSet resultSet = 
preparedStatement.executeQuery(SELECT_SQL_BY_ID_ACROSS_SINGLE_TABLES);
+    public void assertQueryWithFederateInSingleTablesByExecute() throws 
SQLException {
+        assertQueryWithFederateInSingleTables(false);
+    }
+    
+    private void assertQueryWithFederateInSingleTables(final boolean 
executeQuery) throws SQLException {
+        ShardingSphereStatement statement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
+        ResultSet resultSet = getResultSet(statement, 
SELECT_SQL_BY_ID_ACROSS_SINGLE_TABLES, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(1000));
@@ -81,11 +90,20 @@ public final class FederateStatementTest extends 
AbstractShardingSphereDataSourc
         assertThat(resultSet.getString(7), is("init"));
         assertFalse(resultSet.next());
     }
-
+    
+    @Test
+    public void 
assertQueryWithFederateInSingleAndShardingTableByExecuteQuery() throws 
SQLException {
+        assertQueryWithFederateInSingleAndShardingTable(true);
+    }
+    
     @Test
-    public void assertQueryWithFederateInSingleAndShardingTable() throws 
SQLException {
-        ShardingSphereStatement preparedStatement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
-        ResultSet resultSet = 
preparedStatement.executeQuery(SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES);
+    public void assertQueryWithFederateInSingleAndShardingTableByExecute() 
throws SQLException {
+        assertQueryWithFederateInSingleAndShardingTable(false);
+    }
+    
+    private void assertQueryWithFederateInSingleAndShardingTable(final boolean 
executeQuery) throws SQLException {
+        ShardingSphereStatement statement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
+        ResultSet resultSet = getResultSet(statement, 
SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(1000));
@@ -101,11 +119,20 @@ public final class FederateStatementTest extends 
AbstractShardingSphereDataSourc
         assertThat(resultSet.getInt(5), is(10001));
         assertFalse(resultSet.next());
     }
-
+    
+    @Test
+    public void 
assertQueryWithFederateInSingleAndShardingTableWithAliasByExecuteQuery() throws 
SQLException {
+        assertQueryWithFederateInSingleAndShardingTableWithAlias(true);
+    }
+    
     @Test
-    public void assertQueryWithFederateInSingleAndShardingTableWithAlias() 
throws SQLException {
-        ShardingSphereStatement preparedStatement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
-        ResultSet resultSet = 
preparedStatement.executeQuery(SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_ALIAS);
+    public void 
assertQueryWithFederateInSingleAndShardingTableWithAliasByExecute() throws 
SQLException {
+        assertQueryWithFederateInSingleAndShardingTableWithAlias(false);
+    }
+    
+    private void 
assertQueryWithFederateInSingleAndShardingTableWithAlias(final boolean 
executeQuery) throws SQLException {
+        ShardingSphereStatement statement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
+        ResultSet resultSet = getResultSet(statement, 
SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_ALIAS, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(1000));
@@ -121,11 +148,20 @@ public final class FederateStatementTest extends 
AbstractShardingSphereDataSourc
         assertThat(resultSet.getInt(5), is(10001));
         assertFalse(resultSet.next());
     }
-
+    
+    @Test
+    public void 
assertQueryWithFederateInSingleAndShardingTableRewriteByExecuteQuery() throws 
SQLException {
+        assertQueryWithFederateInSingleAndShardingTableRewrite(true);
+    }
+    
     @Test
-    public void assertQueryWithFederateInSingleAndShardingTableRewrite() 
throws SQLException {
-        ShardingSphereStatement preparedStatement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
-        ResultSet resultSet = 
preparedStatement.executeQuery(SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_REWRITE);
+    public void 
assertQueryWithFederateInSingleAndShardingTableRewriteByExecute() throws 
SQLException {
+        assertQueryWithFederateInSingleAndShardingTableRewrite(false);
+    }
+    
+    private void assertQueryWithFederateInSingleAndShardingTableRewrite(final 
boolean executeQuery) throws SQLException {
+        ShardingSphereStatement statement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
+        ResultSet resultSet = getResultSet(statement, 
SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_REWRITE, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(1000));
@@ -141,11 +177,20 @@ public final class FederateStatementTest extends 
AbstractShardingSphereDataSourc
         assertThat(resultSet.getInt(5), is(10001));
         assertFalse(resultSet.next());
     }
-
+    
     @Test
-    public void assertQueryWithFederateInSingleAndShardingTableOrderBy() 
throws SQLException {
-        ShardingSphereStatement preparedStatement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
-        ResultSet resultSet = 
preparedStatement.executeQuery(SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_ORDER_BY);
+    public void 
assertQueryWithFederateInSingleAndShardingTableOrderByByExecuteQuery() throws 
SQLException {
+        assertQueryWithFederateInSingleAndShardingTableOrderBy(true);   
+    }
+    
+    @Test
+    public void 
assertQueryWithFederateInSingleAndShardingTableOrderByByExecute() throws 
SQLException {
+        assertQueryWithFederateInSingleAndShardingTableOrderBy(false);
+    }
+    
+    private void assertQueryWithFederateInSingleAndShardingTableOrderBy(final 
boolean executeQuery) throws SQLException {
+        ShardingSphereStatement statement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
+        ResultSet resultSet = getResultSet(statement, 
SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_ORDER_BY, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(1000));
@@ -157,11 +202,20 @@ public final class FederateStatementTest extends 
AbstractShardingSphereDataSourc
         assertThat(resultSet.getString(3), is("init"));
         assertFalse(resultSet.next());
     }
-
+    
+    @Test
+    public void 
assertQueryWithFederateInSingleTablesWithEncryptRuleByExecuteQuery() throws 
SQLException {
+        assertQueryWithFederateInSingleTablesWithEncryptRule(true);
+    }
+    
     @Test
-    public void assertQueryWithFederateInSingleTablesWithEncryptRule() throws 
SQLException {
-        ShardingSphereStatement preparedStatement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
-        ResultSet resultSet = 
preparedStatement.executeQuery(SELECT_SQL_BY_ID_ACROSS_SINGLE_TABLES_WITH_ENCRYPT);
+    public void 
assertQueryWithFederateInSingleTablesWithEncryptRuleByExecute() throws 
SQLException {
+        assertQueryWithFederateInSingleTablesWithEncryptRule(false);
+    }
+    
+    private void assertQueryWithFederateInSingleTablesWithEncryptRule(final 
boolean executeQuery) throws SQLException {
+        ShardingSphereStatement statement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
+        ResultSet resultSet = getResultSet(statement, 
SELECT_SQL_BY_ID_ACROSS_SINGLE_TABLES_WITH_ENCRYPT, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(0));
@@ -181,11 +235,20 @@ public final class FederateStatementTest extends 
AbstractShardingSphereDataSourc
         assertThat(resultSet.getString(3), is("description3"));
         assertFalse(resultSet.next());
     }
-
+    
+    @Test
+    public void 
assertQueryWithFederateInSingleAndShardingTablesWithEncryptRuleByExecuteQuery() 
throws SQLException {
+        assertQueryWithFederateInSingleAndShardingTablesWithEncryptRule(true);
+    }
+    
     @Test
-    public void 
assertQueryWithFederateInSingleAndShardingTablesWithEncryptRule() throws 
SQLException {
-        ShardingSphereStatement preparedStatement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
-        ResultSet resultSet = 
preparedStatement.executeQuery(SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_WITH_ENCRYPT);
+    public void 
assertQueryWithFederateInSingleAndShardingTablesWithEncryptRuleByExecute() 
throws SQLException {
+        assertQueryWithFederateInSingleAndShardingTablesWithEncryptRule(false);
+    }
+    
+    private void 
assertQueryWithFederateInSingleAndShardingTablesWithEncryptRule(final boolean 
executeQuery) throws SQLException {
+        ShardingSphereStatement statement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
+        ResultSet resultSet = getResultSet(statement, 
SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_WITH_ENCRYPT, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(0));
@@ -205,11 +268,20 @@ public final class FederateStatementTest extends 
AbstractShardingSphereDataSourc
         assertThat(resultSet.getString(3), is("description3"));
         assertFalse(resultSet.next());
     }
-
+    
+    @Test
+    public void 
assertQueryWithFederateBetweenTwoShardingTablesByExecuteQuery() throws 
SQLException {
+        assertQueryWithFederateBetweenTwoShardingTables(true);   
+    }
+    
     @Test
-    public void assertQueryWithFederateBetweenTwoShardingTables() throws 
SQLException {
-        ShardingSphereStatement preparedStatement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
-        ResultSet resultSet = 
preparedStatement.executeQuery(SELECT_SQL_BY_ID_ACROSS_TWO_SHARDING_TABLES);
+    public void assertQueryWithFederateBetweenTwoShardingTablesByExecute() 
throws SQLException {
+        assertQueryWithFederateBetweenTwoShardingTables(false);
+    }
+    
+    private void assertQueryWithFederateBetweenTwoShardingTables(final boolean 
executeQuery) throws SQLException {
+        ShardingSphereStatement statement = (ShardingSphereStatement) 
getShardingSphereDataSource().getConnection().createStatement();
+        ResultSet resultSet = getResultSet(statement, 
SELECT_SQL_BY_ID_ACROSS_TWO_SHARDING_TABLES, executeQuery);
         assertNotNull(resultSet);
         assertTrue(resultSet.next());
         assertThat(resultSet.getInt(1), is(1010));

Reply via email to