You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/06/13 11:46:22 UTC

(shardingsphere) branch master updated: Merge CommentStatementContext and TableAvailableSQLStatementContext (#35700)

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

zhangliang 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 5154bd86c34 Merge CommentStatementContext and TableAvailableSQLStatementContext (#35700)
5154bd86c34 is described below

commit 5154bd86c3479b3edf99928ae2c49998e77801ea
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Jun 13 19:46:16 2025 +0800

    Merge CommentStatementContext and TableAvailableSQLStatementContext (#35700)
---
 .../infra/binder/context/statement/SQLStatementContextFactory.java  | 4 ++--
 .../data/pipeline/core/metadata/generator/PipelineDDLDecorator.java | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java
index 33400a01b54..68d97b0c3ef 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java
@@ -29,7 +29,6 @@ import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterIn
 import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterTableStatementContext;
 import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterViewStatementContext;
 import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CloseStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CommentStatementContext;
 import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateFunctionStatementContext;
 import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateIndexStatementContext;
 import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateProcedureStatementContext;
@@ -218,7 +217,8 @@ public final class SQLStatementContextFactory {
             return new TableAvailableSQLStatementContext(databaseType, sqlStatement, ((PrepareStatement) sqlStatement).getTables());
         }
         if (sqlStatement instanceof CommentStatement) {
-            return new CommentStatementContext(databaseType, (CommentStatement) sqlStatement);
+            return new TableAvailableSQLStatementContext(databaseType, sqlStatement,
+                    null == ((CommentStatement) sqlStatement).getTable() ? Collections.emptyList() : Collections.singletonList(((CommentStatement) sqlStatement).getTable()));
         }
         if (sqlStatement instanceof CursorStatement) {
             return new CursorStatementContext(metaData, databaseType, params, (CursorStatement) sqlStatement, currentDatabaseName);
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java
index 36fb08dd4e4..84d16895c1c 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java
@@ -21,7 +21,6 @@ import com.google.common.base.Strings;
 import lombok.AllArgsConstructor;
 import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
 import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterTableStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CommentStatementContext;
 import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateIndexStatementContext;
 import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateTableStatementContext;
 import org.apache.shardingsphere.infra.binder.context.type.ConstraintAvailable;
@@ -38,6 +37,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constrain
 import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
 import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
 import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CommentStatement;
 
 import java.util.Collections;
 import java.util.Comparator;
@@ -87,7 +87,7 @@ public final class PipelineDDLDecorator {
             appendFromIndexAndConstraint(replaceMap, targetTableName, sqlStatementContext);
             appendFromTable(replaceMap, targetTableName, (TableAvailable) sqlStatementContext);
         }
-        if (sqlStatementContext instanceof CommentStatementContext) {
+        if (sqlStatementContext.getSqlStatement() instanceof CommentStatement) {
             appendFromTable(replaceMap, targetTableName, (TableAvailable) sqlStatementContext);
         }
         if (sqlStatementContext instanceof CreateIndexStatementContext) {
@@ -159,7 +159,7 @@ public final class PipelineDDLDecorator {
     
     private String replaceTableNameWithPrefix(final String sql, final String schemaName, final String databaseName, final SQLParserEngine parserEngine, final DatabaseType databaseType) {
         SQLStatementContext sqlStatementContext = parseSQL(databaseName, parserEngine, databaseType, sql);
-        if (sqlStatementContext instanceof CreateTableStatementContext || sqlStatementContext instanceof CommentStatementContext
+        if (sqlStatementContext instanceof CreateTableStatementContext || sqlStatementContext.getSqlStatement() instanceof CommentStatement
                 || sqlStatementContext instanceof CreateIndexStatementContext || sqlStatementContext instanceof AlterTableStatementContext) {
             if (((TableAvailable) sqlStatementContext).getTablesContext().getSimpleTables().isEmpty()) {
                 return sql;