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 950f5b289da Refactor constructor of BuildIndexStatement to empty 
buildAttributes (#38284)
950f5b289da is described below

commit 950f5b289da4c51ed35e2c279f9c97e4d3077e9a
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Mar 1 16:46:16 2026 +0800

    Refactor constructor of BuildIndexStatement to empty buildAttributes 
(#38284)
    
    * Refactor constructor of BuildIndexStatement to empty buildAttributes
    
    * Refactor constructor of BuildIndexStatement to empty buildAttributes
---
 .../statement/type/DorisDDLStatementVisitor.java       | 17 +++++++----------
 .../statement/type/ddl/index/BuildIndexStatement.java  | 18 +++++++++---------
 2 files changed, 16 insertions(+), 19 deletions(-)

diff --git 
a/parser/sql/engine/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/engine/doris/visitor/statement/type/DorisDDLStatementVisitor.java
 
b/parser/sql/engine/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/engine/doris/visitor/statement/type/DorisDDLStatementVisitor.java
index dd76f507747..81f6cf2e49d 100644
--- 
a/parser/sql/engine/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/engine/doris/visitor/statement/type/DorisDDLStatementVisitor.java
+++ 
b/parser/sql/engine/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/engine/doris/visitor/statement/type/DorisDDLStatementVisitor.java
@@ -280,6 +280,7 @@ import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 /**
  * DDL statement visitor for Doris.
@@ -1164,17 +1165,13 @@ public final class DorisDDLStatementVisitor extends 
DorisStatementVisitor implem
     
     @Override
     public ASTNode visitBuildIndex(final BuildIndexContext ctx) {
-        BuildIndexStatement result = new 
BuildIndexStatement(getDatabaseType());
-        result.setTable((SimpleTableSegment) visit(ctx.tableName()));
         IndexNameSegment indexName = new 
IndexNameSegment(ctx.indexName().start.getStartIndex(), 
ctx.indexName().stop.getStopIndex(), new 
IdentifierValue(ctx.indexName().getText()));
-        result.setIndex(new 
IndexSegment(ctx.indexName().start.getStartIndex(), 
ctx.indexName().stop.getStopIndex(), indexName));
-        if (null != ctx.partitionNames()) {
-            for (IdentifierContext each : ctx.partitionNames().identifier()) {
-                PartitionSegment partitionSegment = new 
PartitionSegment(each.getStart().getStartIndex(), 
each.getStop().getStopIndex(), (IdentifierValue) visit(each));
-                result.getPartitions().add(partitionSegment);
-            }
-        }
-        return result;
+        Collection<PartitionSegment> partitions = null == ctx.partitionNames()
+                ? Collections.emptyList()
+                : ctx.partitionNames().identifier().stream()
+                        .map(each -> new 
PartitionSegment(each.getStart().getStartIndex(), 
each.getStop().getStopIndex(), (IdentifierValue) 
visit(each))).collect(Collectors.toList());
+        return new BuildIndexStatement(
+                getDatabaseType(), new 
IndexSegment(ctx.indexName().start.getStartIndex(), 
ctx.indexName().stop.getStopIndex(), indexName), (SimpleTableSegment) 
visit(ctx.tableName()), partitions);
     }
     
     @Override
diff --git 
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/BuildIndexStatement.java
 
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/BuildIndexStatement.java
index 0955fb7b731..c248ad201b4 100644
--- 
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/BuildIndexStatement.java
+++ 
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/ddl/index/BuildIndexStatement.java
@@ -18,7 +18,6 @@
 package 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index;
 
 import lombok.Getter;
-import lombok.Setter;
 import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dal.PartitionSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
@@ -31,30 +30,31 @@ import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.DD
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.LinkedList;
 
 /**
  * Build index statement.
  */
 @Getter
-@Setter
 public final class BuildIndexStatement extends DDLStatement {
     
-    private IndexSegment index;
+    private final IndexSegment index;
     
-    private SimpleTableSegment table;
+    private final SimpleTableSegment table;
     
-    private final Collection<PartitionSegment> partitions = new LinkedList<>();
+    private final Collection<PartitionSegment> partitions;
     
-    private SQLStatementAttributes attributes;
+    private final SQLStatementAttributes attributes;
     
-    public BuildIndexStatement(final DatabaseType databaseType) {
+    public BuildIndexStatement(final DatabaseType databaseType, final 
IndexSegment index, final SimpleTableSegment table, final 
Collection<PartitionSegment> partitions) {
         super(databaseType);
+        this.index = index;
+        this.table = table;
+        this.partitions = partitions;
+        attributes = new SQLStatementAttributes(new 
TableSQLStatementAttribute(table), new BuildIndexIndexSQLStatementAttribute());
     }
     
     @Override
     public void buildAttributes() {
-        attributes = new SQLStatementAttributes(new 
TableSQLStatementAttribute(table), new BuildIndexIndexSQLStatementAttribute());
     }
     
     private class BuildIndexIndexSQLStatementAttribute implements 
IndexSQLStatementAttribute {

Reply via email to