strongduanmu commented on code in PR #34160: URL: https://github.com/apache/shardingsphere/pull/34160#discussion_r1897725415
########## infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/AlterIndexStatementBinder.java: ########## @@ -0,0 +1,56 @@ +/* + * 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 lombok.SneakyThrows; +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.AlterIndexStatement; +import org.apache.shardingsphere.sql.parser.statement.sqlserver.ddl.SQLServerAlterIndexStatement; + +/** + * Alter index statement binder. + */ +public class AlterIndexStatementBinder implements SQLStatementBinder<AlterIndexStatement> { + + @Override + public AlterIndexStatement bind(final AlterIndexStatement sqlStatement, final SQLStatementBinderContext binderContext) { + if (sqlStatement instanceof SQLServerAlterIndexStatement) { + SQLServerAlterIndexStatement source = (SQLServerAlterIndexStatement) sqlStatement; + if (!source.getSimpleTable().isPresent()) { + return sqlStatement; + } + SQLServerAlterIndexStatement result = copy(source); + result.setSimpleTable(SimpleTableSegmentBinder.bind(source.getSimpleTable().get(), binderContext, null)); + return result; + } + return sqlStatement; + } + + @SneakyThrows(ReflectiveOperationException.class) + private static SQLServerAlterIndexStatement copy(final SQLServerAlterIndexStatement sqlStatement) { Review Comment: Can you use AlterIndexStatement instead of SQLServerAlterIndexStatement? ########## infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java: ########## @@ -80,8 +80,10 @@ public static SimpleTableSegment bind(final SimpleTableSegment segment, final SQ IdentifierValue tableName = segment.getTableName().getIdentifier(); ShardingSphereSchema schema = binderContext.getMetaData().getDatabase(databaseName.getValue()).getSchema(schemaName.getValue()); checkTableExists(binderContext, schema, schemaName.getValue(), tableName.getValue()); - tableBinderContexts.put(new CaseInsensitiveString(segment.getAliasName().orElseGet(tableName::getValue)), - createSimpleTableBinderContext(segment, schema, databaseName, schemaName, binderContext)); + if (null != tableBinderContexts) { Review Comment: Why add null check? ########## infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/AlterIndexStatementBinder.java: ########## @@ -0,0 +1,56 @@ +/* + * 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 lombok.SneakyThrows; +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.AlterIndexStatement; +import org.apache.shardingsphere.sql.parser.statement.sqlserver.ddl.SQLServerAlterIndexStatement; + +/** + * Alter index statement binder. + */ +public class AlterIndexStatementBinder implements SQLStatementBinder<AlterIndexStatement> { + + @Override + public AlterIndexStatement bind(final AlterIndexStatement sqlStatement, final SQLStatementBinderContext binderContext) { + if (sqlStatement instanceof SQLServerAlterIndexStatement) { + SQLServerAlterIndexStatement source = (SQLServerAlterIndexStatement) sqlStatement; + if (!source.getSimpleTable().isPresent()) { + return sqlStatement; + } + SQLServerAlterIndexStatement result = copy(source); + result.setSimpleTable(SimpleTableSegmentBinder.bind(source.getSimpleTable().get(), binderContext, null)); Review Comment: Please pass `Multimap<CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create()` to replace null. ########## infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/AlterIndexStatementBinder.java: ########## @@ -0,0 +1,56 @@ +/* + * 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 lombok.SneakyThrows; +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.AlterIndexStatement; +import org.apache.shardingsphere.sql.parser.statement.sqlserver.ddl.SQLServerAlterIndexStatement; + +/** + * Alter index statement binder. + */ +public class AlterIndexStatementBinder implements SQLStatementBinder<AlterIndexStatement> { + + @Override + public AlterIndexStatement bind(final AlterIndexStatement sqlStatement, final SQLStatementBinderContext binderContext) { + if (sqlStatement instanceof SQLServerAlterIndexStatement) { Review Comment: If we add setSimpleTable in AlterIndexStatement, maybe we can remove this judge logic. ########## infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/AlterIndexStatementBinder.java: ########## @@ -0,0 +1,56 @@ +/* + * 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 lombok.SneakyThrows; +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.AlterIndexStatement; +import org.apache.shardingsphere.sql.parser.statement.sqlserver.ddl.SQLServerAlterIndexStatement; + +/** + * Alter index statement binder. + */ +public class AlterIndexStatementBinder implements SQLStatementBinder<AlterIndexStatement> { + + @Override + public AlterIndexStatement bind(final AlterIndexStatement sqlStatement, final SQLStatementBinderContext binderContext) { + if (sqlStatement instanceof SQLServerAlterIndexStatement) { + SQLServerAlterIndexStatement source = (SQLServerAlterIndexStatement) sqlStatement; + if (!source.getSimpleTable().isPresent()) { + return sqlStatement; + } + SQLServerAlterIndexStatement result = copy(source); + result.setSimpleTable(SimpleTableSegmentBinder.bind(source.getSimpleTable().get(), binderContext, null)); + return result; + } + return sqlStatement; + } + + @SneakyThrows(ReflectiveOperationException.class) + private static SQLServerAlterIndexStatement copy(final SQLServerAlterIndexStatement sqlStatement) { + SQLServerAlterIndexStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance(); + sqlStatement.getIndex().ifPresent(result::setIndex); + sqlStatement.getSimpleTable().ifPresent(result::setSimpleTable); Review Comment: Besides, we can add empty setSimpleTable method in AlterIndexStatement -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
