You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by tu...@apache.org on 2022/06/08 09:49:37 UTC
[shardingsphere] branch master updated: Fix NoSuchElementException when execute preview cursor statement (#18241)
This is an automated email from the ASF dual-hosted git repository.
tuichenchuxin 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 aac0d3026e0 Fix NoSuchElementException when execute preview cursor statement (#18241)
aac0d3026e0 is described below
commit aac0d3026e00575114701be603ec189a02a45747
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Wed Jun 8 17:49:24 2022 +0800
Fix NoSuchElementException when execute preview cursor statement (#18241)
---
.../data/impl/SchemaAssignedDatabaseBackendHandler.java | 7 ++++---
.../distsql/ral/advanced/PreviewDistSQLBackendHandler.java | 13 +++++++++++++
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java
index e57ee177f3e..051dcfdb6f9 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java
@@ -95,14 +95,15 @@ public final class SchemaAssignedDatabaseBackendHandler implements DatabaseBacke
if (statementContext instanceof CursorStatementContext) {
connectionSession.getCursorDefinitions().put(cursorName, (CursorStatementContext) statementContext);
}
- if (statementContext instanceof CloseStatementContext) {
- FetchOrderByValueQueuesHolder.get().remove(cursorName);
- }
if (statementContext instanceof CursorDefinitionAware) {
CursorStatementContext cursorStatementContext = connectionSession.getCursorDefinitions().get(cursorName);
Preconditions.checkArgument(null != cursorStatementContext, "Cursor %s does not exist.", cursorName);
((CursorDefinitionAware) statementContext).setUpCursorDefinition(cursorStatementContext);
}
+ if (statementContext instanceof CloseStatementContext) {
+ FetchOrderByValueQueuesHolder.get().remove(cursorName);
+ connectionSession.getCursorDefinitions().remove(cursorName);
+ }
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewDistSQLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewDistSQLBackendHandler.java
index 10b2121f1d4..536807169b7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewDistSQLBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewDistSQLBackendHandler.java
@@ -22,7 +22,10 @@ import com.google.common.base.Strings;
import org.apache.shardingsphere.distsql.parser.statement.ral.advanced.PreviewStatement;
import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
+import org.apache.shardingsphere.infra.binder.aware.CursorDefinitionAware;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
+import org.apache.shardingsphere.infra.binder.statement.ddl.CursorStatementContext;
+import org.apache.shardingsphere.infra.binder.type.CursorAvailable;
import org.apache.shardingsphere.infra.binder.type.TableAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.context.kernel.KernelProcessor;
@@ -107,6 +110,9 @@ public final class PreviewDistSQLBackendHandler extends QueryableRALBackendHandl
if (sqlStatementContext instanceof TableAvailable) {
((TableAvailable) sqlStatementContext).getTablesContext().getDatabaseName().ifPresent(SQLStatementDatabaseHolder::set);
}
+ if (sqlStatementContext instanceof CursorAvailable && sqlStatementContext instanceof CursorDefinitionAware) {
+ setUpCursorDefinition(sqlStatementContext);
+ }
ShardingSphereDatabase database = ProxyContext.getInstance().getDatabase(connectionSession.getDatabaseName());
if (!database.isComplete()) {
throw new RuleNotExistedException();
@@ -119,6 +125,13 @@ public final class PreviewDistSQLBackendHandler extends QueryableRALBackendHandl
return executionUnits.stream().map(this::buildRow).collect(Collectors.toList());
}
+ private void setUpCursorDefinition(final SQLStatementContext<?> sqlStatementContext) {
+ String cursorName = ((CursorAvailable) sqlStatementContext).getCursorName().getIdentifier().getValue().toLowerCase();
+ CursorStatementContext cursorStatementContext = connectionSession.getCursorDefinitions().get(cursorName);
+ Preconditions.checkArgument(null != cursorStatementContext, "Cursor %s does not exist.", cursorName);
+ ((CursorDefinitionAware) sqlStatementContext).setUpCursorDefinition(cursorStatementContext);
+ }
+
private List<Object> buildRow(final ExecutionUnit unit) {
return Arrays.asList(unit.getDataSourceName(), unit.getSqlUnit().getSql());
}