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 ac4e412f0a7 Fix PostgreSQL Proxy cannot prepare empty statement
(#18761)
ac4e412f0a7 is described below
commit ac4e412f0a771fb828acb7c75c8efc63b8ba8290
Author: 吴伟杰 <[email protected]>
AuthorDate: Fri Jul 1 15:29:14 2022 +0800
Fix PostgreSQL Proxy cannot prepare empty statement (#18761)
* Fix PostgreSQL Proxy cannot execute empty statement
* Complete PostgreSQLComParseExecutorTest
---
.../command/query/extended/parse/PostgreSQLComParseExecutor.java | 2 +-
.../query/extended/parse/PostgreSQLComParseExecutorTest.java | 9 +--------
2 files changed, 2 insertions(+), 9 deletions(-)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java
index 8e4cfd718ba..ce3138aa74f 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java
@@ -66,7 +66,7 @@ public final class PostgreSQLComParseExecutor implements
CommandExecutor {
sqlStatement = sqlParserEngine.parse(sql, true);
}
List<PostgreSQLColumnType> paddedColumnTypes =
paddingColumnTypes(sqlStatement.getParameterCount(),
packet.readParameterTypes());
- SQLStatementContext<?> sqlStatementContext = !(sqlStatement instanceof
DistSQLStatement)
+ SQLStatementContext<?> sqlStatementContext = !(sqlStatement instanceof
DistSQLStatement || sqlStatement instanceof EmptyStatement)
?
SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabases(),
sqlStatement,
connectionSession.getDefaultDatabaseName())
: null;
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java
index 1e383e806dc..6ee3b0fed5f 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java
@@ -23,7 +23,6 @@ import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.ext
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.parse.PostgreSQLComParsePacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.parse.PostgreSQLParseCompletePacket;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.queryable.ShowVariableStatement;
-import
org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
import
org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -42,7 +41,6 @@ import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.MockedConstruction;
import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Field;
@@ -55,7 +53,6 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.mockConstruction;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -81,17 +78,13 @@ public final class PostgreSQLComParseExecutorTest extends
ProxyContextRestorer {
when(connectionSession.getPreparedStatementRegistry()).thenReturn(new
PreparedStatementRegistry());
}
- @SuppressWarnings("rawtypes")
@Test
public void assertExecuteWithEmptySQL() {
final String expectedSQL = "";
final String statementId = "S_1";
when(parsePacket.getSql()).thenReturn(expectedSQL);
when(parsePacket.getStatementId()).thenReturn(statementId);
- Collection<DatabasePacket<?>> actualPackets;
- try (MockedConstruction<CommonSQLStatementContext> ignored =
mockConstruction(CommonSQLStatementContext.class)) {
- actualPackets = executor.execute();
- }
+ Collection<DatabasePacket<?>> actualPackets = executor.execute();
assertThat(actualPackets.size(), is(1));
assertThat(actualPackets.iterator().next(),
is(PostgreSQLParseCompletePacket.getInstance()));
PostgreSQLPreparedStatement actualPreparedStatement =
connectionSession.getPreparedStatementRegistry().getPreparedStatement(statementId);