Skip to content

Commit

Permalink
code fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yaofly committed Dec 26, 2024
1 parent d052945 commit 8a2a8ca
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ 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());
if (null != tableBinderContexts) {
tableBinderContexts.put(new CaseInsensitiveString(segment.getAliasName().orElseGet(tableName::getValue)),
createSimpleTableBinderContext(segment, schema, databaseName, schemaName, binderContext));
}
tableBinderContexts.put(new CaseInsensitiveString(segment.getAliasName().orElseGet(tableName::getValue)),
createSimpleTableBinderContext(segment, schema, databaseName, schemaName, binderContext));
TableNameSegment tableNameSegment = new TableNameSegment(segment.getTableName().getStartIndex(), segment.getTableName().getStopIndex(), tableName);
tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(databaseName, schemaName));
SimpleTableSegment result = new SimpleTableSegment(tableNameSegment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@

package org.apache.shardingsphere.infra.binder.engine.statement.ddl;

import com.cedarsoftware.util.CaseInsensitiveMap;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.binder.engine.segment.from.type.SimpleTableSegmentBinder;
import org.apache.shardingsphere.infra.binder.engine.segment.dml.from.context.TableSegmentBinderContext;
import org.apache.shardingsphere.infra.binder.engine.segment.dml.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.
Expand All @@ -31,21 +34,18 @@ public class AlterIndexStatementBinder implements SQLStatementBinder<AlterIndexS

@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;
if (!sqlStatement.getSimpleTable().isPresent()) {
return sqlStatement;
}
return sqlStatement;
AlterIndexStatement result = copy(sqlStatement);
Multimap<CaseInsensitiveMap.CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create();
result.setSimpleTable(SimpleTableSegmentBinder.bind(sqlStatement.getSimpleTable().get(), binderContext, tableBinderContexts));
return result;
}

@SneakyThrows(ReflectiveOperationException.class)
private static SQLServerAlterIndexStatement copy(final SQLServerAlterIndexStatement sqlStatement) {
SQLServerAlterIndexStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance();
private static AlterIndexStatement copy(final AlterIndexStatement sqlStatement) {
AlterIndexStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance();
sqlStatement.getIndex().ifPresent(result::setIndex);
sqlStatement.getSimpleTable().ifPresent(result::setSimpleTable);
result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public Optional<IndexSegment> getIndex() {
public Optional<SimpleTableSegment> getSimpleTable() {
return Optional.empty();
}

/**
* Set simple table segment.
*
* @param simpleTableSegment simple table segment
*/
public void setSimpleTable(final SimpleTableSegment simpleTableSegment) {
}

/**
* Get rename index segment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public final class SQLServerAlterIndexStatement extends AlterIndexStatement impl
public Optional<SimpleTableSegment> getSimpleTable() {
return Optional.ofNullable(simpleTable);
}

@Override
public void setSimpleTable(final SimpleTableSegment simpleTable) {
this.simpleTable = simpleTable;
}
}

0 comments on commit 8a2a8ca

Please sign in to comment.