From 2ec734aefd7d1a69f05a33979a241e9871aa54e1 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Sat, 21 Dec 2024 16:51:32 +0800 Subject: [PATCH 1/4] Support create index statement sql bind --- ...ardingCreateIndexSupportedCheckerTest.java | 14 ++--- .../ddl/CreateIndexStatementBinder.java | 59 +++++++++++++++++++ .../engine/type/DDLStatementBindEngine.java | 5 ++ .../type/OpenGaussDDLStatementVisitor.java | 3 +- .../type/PostgreSQLDDLStatementVisitor.java | 3 +- .../statement/ddl/CreateIndexStatement.java | 32 ++++++++++ .../ddl/OpenGaussCreateIndexStatement.java | 2 +- .../ddl/PostgreSQLCreateIndexStatement.java | 2 +- .../dialect/opengauss/OpenGaussBinderIT.java | 25 ++++++++ .../postgresql/PostgreSQLBinderIT.java | 25 ++++++++ .../test/resources/cases/ddl/create-index.xml | 32 ++++++++++ .../test/resources/sqls/ddl/create-index.xml | 21 +++++++ 12 files changed, 212 insertions(+), 11 deletions(-) create mode 100644 infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/CreateIndexStatementBinder.java create mode 100644 test/it/binder/src/test/java/org/apache/shardingsphere/test/it/sql/binder/dialect/opengauss/OpenGaussBinderIT.java create mode 100644 test/it/binder/src/test/java/org/apache/shardingsphere/test/it/sql/binder/dialect/postgresql/PostgreSQLBinderIT.java create mode 100644 test/it/binder/src/test/resources/cases/ddl/create-index.xml create mode 100644 test/it/binder/src/test/resources/sqls/ddl/create-index.xml diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedCheckerTest.java index 1fedc80468e83..20a4daaa6536e 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedCheckerTest.java @@ -19,9 +19,9 @@ import org.apache.shardingsphere.infra.binder.context.statement.ddl.CreateIndexStatementContext; import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.NoSuchTableException; +import org.apache.shardingsphere.infra.exception.kernel.metadata.DuplicateIndexException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; -import org.apache.shardingsphere.infra.exception.kernel.metadata.DuplicateIndexException; import org.apache.shardingsphere.sharding.rule.ShardingRule; import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment; @@ -52,7 +52,7 @@ class ShardingCreateIndexSupportedCheckerTest { @Test void assertCheckWhenTableExistIndexNotExistForPostgreSQL() { - PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(false); + PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index")))); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); @@ -62,7 +62,7 @@ void assertCheckWhenTableExistIndexNotExistForPostgreSQL() { @Test void assertCheckWhenTableNotExistIndexNotExistForPostgreSQL() { - PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(false); + PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index")))); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); @@ -72,7 +72,7 @@ void assertCheckWhenTableNotExistIndexNotExistForPostgreSQL() { @Test void assertCheckWhenTableExistIndexExistForPostgreSQL() { - PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(false); + PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index")))); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); @@ -83,7 +83,7 @@ void assertCheckWhenTableExistIndexExistForPostgreSQL() { @Test void assertCheckWithoutIndexNameWhenTableExistIndexNotExistForPostgreSQL() { - PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(false); + PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.getColumns().add(new ColumnSegment(0, 0, new IdentifierValue("content"))); sqlStatement.setGeneratedIndexStartIndex(10); @@ -94,7 +94,7 @@ void assertCheckWithoutIndexNameWhenTableExistIndexNotExistForPostgreSQL() { @Test void assertCheckWithoutIndexNameWhenTableNotExistIndexNotExistForPostgreSQL() { - PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(false); + PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.getColumns().add(new ColumnSegment(0, 0, new IdentifierValue("content"))); sqlStatement.setGeneratedIndexStartIndex(10); @@ -105,7 +105,7 @@ void assertCheckWithoutIndexNameWhenTableNotExistIndexNotExistForPostgreSQL() { @Test void assertCheckWithoutIndexNameWhenTableExistIndexExistForPostgreSQL() { - PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(false); + PostgreSQLCreateIndexStatement sqlStatement = new PostgreSQLCreateIndexStatement(); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.getColumns().add(new ColumnSegment(0, 0, new IdentifierValue("content"))); sqlStatement.setGeneratedIndexStartIndex(10); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/CreateIndexStatementBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/CreateIndexStatementBinder.java new file mode 100644 index 0000000000000..79b5a353bbf2d --- /dev/null +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/CreateIndexStatementBinder.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.binder.engine.statement.ddl; + +import com.cedarsoftware.util.CaseInsensitiveMap.CaseInsensitiveString; +import com.google.common.collect.LinkedHashMultimap; +import com.google.common.collect.Multimap; +import lombok.SneakyThrows; +import org.apache.shardingsphere.infra.binder.engine.segment.SegmentType; +import org.apache.shardingsphere.infra.binder.engine.segment.expression.type.ColumnSegmentBinder; +import org.apache.shardingsphere.infra.binder.engine.segment.from.context.TableSegmentBinderContext; +import org.apache.shardingsphere.infra.binder.engine.segment.from.type.SimpleTableSegmentBinder; +import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinder; +import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext; +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateIndexStatement; + +/** + * Create index statement binder. + */ +public final class CreateIndexStatementBinder implements SQLStatementBinder { + + @Override + public CreateIndexStatement bind(final CreateIndexStatement sqlStatement, final SQLStatementBinderContext binderContext) { + CreateIndexStatement result = copy(sqlStatement); + Multimap tableBinderContexts = LinkedHashMultimap.create(); + result.setTable(SimpleTableSegmentBinder.bind(sqlStatement.getTable(), binderContext, tableBinderContexts)); + sqlStatement.getColumns().forEach(each -> ColumnSegmentBinder.bind(each, SegmentType.DEFINITION_COLUMNS, binderContext, tableBinderContexts, LinkedHashMultimap.create())); + return result; + } + + @SneakyThrows(ReflectiveOperationException.class) + private static CreateIndexStatement copy(final CreateIndexStatement sqlStatement) { + CreateIndexStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance(); + result.setIndex(sqlStatement.getIndex()); + sqlStatement.getGeneratedIndexStartIndex().ifPresent(result::setGeneratedIndexStartIndex); + result.setIfNotExists(sqlStatement.isIfNotExists()); + sqlStatement.getAlgorithmType().ifPresent(result::setAlgorithmType); + sqlStatement.getLockTable().ifPresent(result::setLockTable); + result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments()); + result.getCommentSegments().addAll(sqlStatement.getCommentSegments()); + result.getVariableNames().addAll(sqlStatement.getVariableNames()); + return result; + } +} diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DDLStatementBindEngine.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DDLStatementBindEngine.java index 948a74bda03c7..6665fc27ec50e 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DDLStatementBindEngine.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DDLStatementBindEngine.java @@ -19,10 +19,12 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext; +import org.apache.shardingsphere.infra.binder.engine.statement.ddl.CreateIndexStatementBinder; import org.apache.shardingsphere.infra.binder.engine.statement.ddl.CreateTableStatementBinder; import org.apache.shardingsphere.infra.binder.engine.statement.ddl.CursorStatementBinder; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateIndexStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateTableStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CursorStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStatement; @@ -53,6 +55,9 @@ public DDLStatement bind(final DDLStatement statement) { if (statement instanceof CreateTableStatement) { return new CreateTableStatementBinder().bind((CreateTableStatement) statement, binderContext); } + if (statement instanceof CreateIndexStatement) { + return new CreateIndexStatementBinder().bind((CreateIndexStatement) statement, binderContext); + } return statement; } } diff --git a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java index bc873d3a0b221..f0940ad4a0d17 100644 --- a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java +++ b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java @@ -528,7 +528,8 @@ public ASTNode visitTruncateTable(final TruncateTableContext ctx) { @SuppressWarnings("unchecked") @Override public ASTNode visitCreateIndex(final CreateIndexContext ctx) { - OpenGaussCreateIndexStatement result = new OpenGaussCreateIndexStatement(null != ctx.ifNotExists()); + OpenGaussCreateIndexStatement result = new OpenGaussCreateIndexStatement(); + result.setIfNotExists(null != ctx.ifNotExists()); result.setTable((SimpleTableSegment) visit(ctx.tableName())); result.getColumns().addAll(((CollectionValue) visit(ctx.indexParams())).getValue()); if (null == ctx.indexName()) { diff --git a/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDDLStatementVisitor.java b/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDDLStatementVisitor.java index dd5a0abf893ba..6a23b13361f77 100644 --- a/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDDLStatementVisitor.java +++ b/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDDLStatementVisitor.java @@ -668,7 +668,8 @@ public ASTNode visitDropSubscription(final DropSubscriptionContext ctx) { @SuppressWarnings("unchecked") @Override public ASTNode visitCreateIndex(final CreateIndexContext ctx) { - PostgreSQLCreateIndexStatement result = new PostgreSQLCreateIndexStatement(null != ctx.ifNotExists()); + PostgreSQLCreateIndexStatement result = new PostgreSQLCreateIndexStatement(); + result.setIfNotExists(null != ctx.ifNotExists()); result.setTable((SimpleTableSegment) visit(ctx.tableName())); result.getColumns().addAll(((CollectionValue) visit(ctx.indexParams())).getValue()); if (null != ctx.indexName()) { diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/CreateIndexStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/CreateIndexStatement.java index d40abeb5f0856..e1b800c0847e8 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/CreateIndexStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/CreateIndexStatement.java @@ -52,6 +52,14 @@ public Optional getGeneratedIndexStartIndex() { return Optional.empty(); } + /** + * Set generated index start index. + * + * @param generatedIndexStartIndex generated index start index + */ + public void setGeneratedIndexStartIndex(final Integer generatedIndexStartIndex) { + } + /** * Judge whether contains if not exists or not. * @@ -61,6 +69,14 @@ public boolean isIfNotExists() { return false; } + /** + * Set if not exists or not. + * + * @param ifNotExists if not exists or not + */ + public void setIfNotExists(final boolean ifNotExists) { + } + /** * Get algorithm type. * @@ -70,6 +86,14 @@ public Optional getAlgorithmType() { return Optional.empty(); } + /** + * Set algorithm type. + * + * @param algorithmType algorithm type + */ + public void setAlgorithmType(final AlgorithmTypeSegment algorithmType) { + } + /** * Get lock table. * @@ -78,4 +102,12 @@ public Optional getAlgorithmType() { public Optional getLockTable() { return Optional.empty(); } + + /** + * Set lock table. + * + * @param lockTable lock table + */ + public void setLockTable(final LockTableSegment lockTable) { + } } diff --git a/parser/sql/statement/type/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/statement/opengauss/ddl/OpenGaussCreateIndexStatement.java b/parser/sql/statement/type/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/statement/opengauss/ddl/OpenGaussCreateIndexStatement.java index bf8e5a11925b3..131156afc2e49 100644 --- a/parser/sql/statement/type/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/statement/opengauss/ddl/OpenGaussCreateIndexStatement.java +++ b/parser/sql/statement/type/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/statement/opengauss/ddl/OpenGaussCreateIndexStatement.java @@ -33,7 +33,7 @@ @Setter public final class OpenGaussCreateIndexStatement extends CreateIndexStatement implements OpenGaussStatement { - private final boolean ifNotExists; + private boolean ifNotExists; private Integer generatedIndexStartIndex; diff --git a/parser/sql/statement/type/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/statement/postgresql/ddl/PostgreSQLCreateIndexStatement.java b/parser/sql/statement/type/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/statement/postgresql/ddl/PostgreSQLCreateIndexStatement.java index 8abc8d050f941..4a5403a512845 100644 --- a/parser/sql/statement/type/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/statement/postgresql/ddl/PostgreSQLCreateIndexStatement.java +++ b/parser/sql/statement/type/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/statement/postgresql/ddl/PostgreSQLCreateIndexStatement.java @@ -33,7 +33,7 @@ @Setter public final class PostgreSQLCreateIndexStatement extends CreateIndexStatement implements PostgreSQLStatement { - private final boolean ifNotExists; + private boolean ifNotExists; private Integer generatedIndexStartIndex; diff --git a/test/it/binder/src/test/java/org/apache/shardingsphere/test/it/sql/binder/dialect/opengauss/OpenGaussBinderIT.java b/test/it/binder/src/test/java/org/apache/shardingsphere/test/it/sql/binder/dialect/opengauss/OpenGaussBinderIT.java new file mode 100644 index 0000000000000..e9477b0029636 --- /dev/null +++ b/test/it/binder/src/test/java/org/apache/shardingsphere/test/it/sql/binder/dialect/opengauss/OpenGaussBinderIT.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.test.it.sql.binder.dialect.opengauss; + +import org.apache.shardingsphere.test.it.sql.binder.SQLBinderIT; +import org.apache.shardingsphere.test.it.sql.binder.SQLBinderITSettings; + +@SQLBinderITSettings("openGauss") +class OpenGaussBinderIT extends SQLBinderIT { +} diff --git a/test/it/binder/src/test/java/org/apache/shardingsphere/test/it/sql/binder/dialect/postgresql/PostgreSQLBinderIT.java b/test/it/binder/src/test/java/org/apache/shardingsphere/test/it/sql/binder/dialect/postgresql/PostgreSQLBinderIT.java new file mode 100644 index 0000000000000..4256eb33f95a5 --- /dev/null +++ b/test/it/binder/src/test/java/org/apache/shardingsphere/test/it/sql/binder/dialect/postgresql/PostgreSQLBinderIT.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.test.it.sql.binder.dialect.postgresql; + +import org.apache.shardingsphere.test.it.sql.binder.SQLBinderIT; +import org.apache.shardingsphere.test.it.sql.binder.SQLBinderITSettings; + +@SQLBinderITSettings("PostgreSQL") +class PostgreSQLBinderIT extends SQLBinderIT { +} diff --git a/test/it/binder/src/test/resources/cases/ddl/create-index.xml b/test/it/binder/src/test/resources/cases/ddl/create-index.xml new file mode 100644 index 0000000000000..a7d6864d2e20e --- /dev/null +++ b/test/it/binder/src/test/resources/cases/ddl/create-index.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + +
+ +
+
diff --git a/test/it/binder/src/test/resources/sqls/ddl/create-index.xml b/test/it/binder/src/test/resources/sqls/ddl/create-index.xml new file mode 100644 index 0000000000000..4e6253c22108a --- /dev/null +++ b/test/it/binder/src/test/resources/sqls/ddl/create-index.xml @@ -0,0 +1,21 @@ + + + + + + From adf976c6bf8e7ab8434e5c41dc92bb97b8ac6198 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Sat, 21 Dec 2024 16:55:10 +0800 Subject: [PATCH 2/4] update release note --- RELEASE-NOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index edc87b648e8d2..298ef5e59adf9 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -35,6 +35,7 @@ 1. Agent: Simplify the use of Agent's Docker Image - [#33356](https://github.com/apache/shardingsphere/pull/33356) 1. Metadata: Add load-table-metadata-batch-size props to concurrent load table metadata - [#34009](https://github.com/apache/shardingsphere/pull/34009) 1. SQL Binder: Add sql bind logic for create table statement - [#34074](https://github.com/apache/shardingsphere/pull/34074) +1. SQL Binder: Support create index statement sql bind - [#34112](https://github.com/apache/shardingsphere/pull/34112) ### Bug Fixes From f3bb85a38c56de1377d2d3b462c41e7a52ffd9e7 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Sat, 21 Dec 2024 17:02:05 +0800 Subject: [PATCH 3/4] update binder expected file --- .../engine/statement/ddl/CreateIndexStatementBinder.java | 2 +- .../binder/src/test/resources/cases/ddl/create-index.xml | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/CreateIndexStatementBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/CreateIndexStatementBinder.java index 79b5a353bbf2d..62d745fde95ca 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/CreateIndexStatementBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/CreateIndexStatementBinder.java @@ -39,7 +39,7 @@ public CreateIndexStatement bind(final CreateIndexStatement sqlStatement, final CreateIndexStatement result = copy(sqlStatement); Multimap tableBinderContexts = LinkedHashMultimap.create(); result.setTable(SimpleTableSegmentBinder.bind(sqlStatement.getTable(), binderContext, tableBinderContexts)); - sqlStatement.getColumns().forEach(each -> ColumnSegmentBinder.bind(each, SegmentType.DEFINITION_COLUMNS, binderContext, tableBinderContexts, LinkedHashMultimap.create())); + sqlStatement.getColumns().forEach(each -> result.getColumns().add(ColumnSegmentBinder.bind(each, SegmentType.DEFINITION_COLUMNS, binderContext, tableBinderContexts, LinkedHashMultimap.create()))); return result; } diff --git a/test/it/binder/src/test/resources/cases/ddl/create-index.xml b/test/it/binder/src/test/resources/cases/ddl/create-index.xml index a7d6864d2e20e..ae7c22542bbce 100644 --- a/test/it/binder/src/test/resources/cases/ddl/create-index.xml +++ b/test/it/binder/src/test/resources/cases/ddl/create-index.xml @@ -28,5 +28,13 @@ + + + + + + + + From 73dca8284e0882115bdab0a55321a05ccb15e4c2 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Sat, 21 Dec 2024 17:02:40 +0800 Subject: [PATCH 4/4] fix checkstyle --- .../engine/statement/ddl/CreateIndexStatementBinder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/CreateIndexStatementBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/CreateIndexStatementBinder.java index 62d745fde95ca..6fb91821bc6d4 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/CreateIndexStatementBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/CreateIndexStatementBinder.java @@ -39,7 +39,8 @@ public CreateIndexStatement bind(final CreateIndexStatement sqlStatement, final CreateIndexStatement result = copy(sqlStatement); Multimap tableBinderContexts = LinkedHashMultimap.create(); result.setTable(SimpleTableSegmentBinder.bind(sqlStatement.getTable(), binderContext, tableBinderContexts)); - sqlStatement.getColumns().forEach(each -> result.getColumns().add(ColumnSegmentBinder.bind(each, SegmentType.DEFINITION_COLUMNS, binderContext, tableBinderContexts, LinkedHashMultimap.create()))); + sqlStatement.getColumns() + .forEach(each -> result.getColumns().add(ColumnSegmentBinder.bind(each, SegmentType.DEFINITION_COLUMNS, binderContext, tableBinderContexts, LinkedHashMultimap.create()))); return result; }