Skip to content

Commit

Permalink
change "tableSegment" to "table"(keep the naming consistent) (#19763)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunkai-cai authored Aug 2, 2022
1 parent d578cac commit 2e65417
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected static InsertStatement createInsertStatement() {

protected static UpdateStatementContext createUpdatesStatementContext() {
MySQLUpdateStatement mySQLUpdateStatement = new MySQLUpdateStatement();
mySQLUpdateStatement.setTableSegment(createTableSegment(TABLE_NAME));
mySQLUpdateStatement.setTable(createTableSegment(TABLE_NAME));
mySQLUpdateStatement.setWhere(createWhereSegment());
mySQLUpdateStatement.setSetAssignment(createSetAssignmentSegment());
return new UpdateStatementContext(mySQLUpdateStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void assertPreValidateWhenDeleteMultiTables(final DeleteStatement sqlSta
tableSegment.getActualDeleteTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user"))));
tableSegment.getActualDeleteTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("order"))));
tableSegment.getActualDeleteTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("order_item"))));
sqlStatement.setTableSegment(tableSegment);
sqlStatement.setTable(tableSegment);
DeleteStatementContext sqlStatementContext = new DeleteStatementContext(sqlStatement);
Collection<String> tableNames = new HashSet<>(Arrays.asList("user", "order", "order_item"));
when(shardingRule.isAllShardingTables(tableNames)).thenReturn(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public final class ShardingUpdateStatementValidatorTest {
@Test
public void assertPreValidateWhenUpdateSingleTable() {
UpdateStatement updateStatement = createUpdateStatement();
updateStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user"))));
updateStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user"))));
SQLStatementContext<UpdateStatement> sqlStatementContext = new UpdateStatementContext(updateStatement);
Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
when(shardingRule.isAllShardingTables(tableNames)).thenReturn(true);
Expand All @@ -83,7 +83,7 @@ public void assertPreValidateWhenUpdateMultipleTables() {
JoinTableSegment joinTableSegment = new JoinTableSegment();
joinTableSegment.setLeft(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user"))));
joinTableSegment.setRight(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("order"))));
updateStatement.setTableSegment(joinTableSegment);
updateStatement.setTable(joinTableSegment);
SQLStatementContext<UpdateStatement> sqlStatementContext = new UpdateStatementContext(updateStatement);
Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
when(shardingRule.isAllShardingTables(tableNames)).thenReturn(false);
Expand Down Expand Up @@ -158,7 +158,7 @@ private RouteContext createFullRouteContext() {

private UpdateStatement createUpdateStatement() {
UpdateStatement result = new MySQLUpdateStatement();
result.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user"))));
result.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user"))));
List<ColumnSegment> columns = new LinkedList<>();
columns.add(new ColumnSegment(0, 0, new IdentifierValue("id")));
AssignmentSegment assignment = new ColumnAssignmentSegment(0, 0, columns, new LiteralExpressionSegment(0, 0, 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ private InsertStatement getInsert() {

private UpdateStatement getUpdate() {
UpdateStatement update = new PostgreSQLUpdateStatement();
update.setTableSegment(table);
update.setTable(table);
SetAssignmentSegment setAssignmentSegment = new SetAssignmentSegment(0, 0, Collections.singletonList(new ColumnAssignmentSegment(0, 0, Collections.singletonList(column), column)));
update.setSetAssignment(setAssignmentSegment);
return update;
}

private DeleteStatement getDelete() {
DeleteStatement delete = new PostgreSQLDeleteStatement();
delete.setTableSegment(table);
delete.setTable(table);
return delete;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void assertNewInstance(final DeleteStatement deleteStatement) {
tableSegment.setLeft(table1);
tableSegment.setRight(table2);
deleteStatement.setWhere(whereSegment);
deleteStatement.setTableSegment(tableSegment);
deleteStatement.setTable(tableSegment);
DeleteStatementContext actual = new DeleteStatementContext(deleteStatement);
assertThat(actual.getTablesContext().getTableNames(), is(new HashSet<>(Arrays.asList("tbl_1", "tbl_2"))));
assertThat(actual.getWhereSegments(), is(Collections.singletonList(whereSegment)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void assertNewInstance() {
joinTableSegment.setRight(table2);
UpdateStatement updateStatement = new MySQLUpdateStatement();
updateStatement.setWhere(whereSegment);
updateStatement.setTableSegment(joinTableSegment);
updateStatement.setTable(joinTableSegment);
updateStatement.setSetAssignment(new SetAssignmentSegment(0, 0, Collections.emptyList()));
UpdateStatementContext actual = new UpdateStatementContext(updateStatement);
assertThat(actual.getTablesContext().getTableNames(), is(new HashSet<>(Arrays.asList("tbl_1", "tbl_2"))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ private Collection<InsertValuesSegment> createReplaceValuesSegments(final Collec
public ASTNode visitUpdate(final UpdateContext ctx) {
MySQLUpdateStatement result = new MySQLUpdateStatement();
TableSegment tableSegment = (TableSegment) visit(ctx.tableReferences());
result.setTableSegment(tableSegment);
result.setTable(tableSegment);
result.setSetAssignment((SetAssignmentSegment) visit(ctx.setAssignmentsClause()));
if (null != ctx.whereClause()) {
result.setWhere((WhereSegment) visit(ctx.whereClause()));
Expand Down Expand Up @@ -1276,9 +1276,9 @@ public ASTNode visitBlobValue(final BlobValueContext ctx) {
public ASTNode visitDelete(final DeleteContext ctx) {
MySQLDeleteStatement result = new MySQLDeleteStatement();
if (null != ctx.multipleTablesClause()) {
result.setTableSegment((TableSegment) visit(ctx.multipleTablesClause()));
result.setTable((TableSegment) visit(ctx.multipleTablesClause()));
} else {
result.setTableSegment((TableSegment) visit(ctx.singleTableClause()));
result.setTable((TableSegment) visit(ctx.singleTableClause()));
}
if (null != ctx.whereClause()) {
result.setWhere((WhereSegment) visit(ctx.whereClause()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ public ASTNode visitRelationExprOptAlias(final RelationExprOptAliasContext ctx)
public ASTNode visitUpdate(final UpdateContext ctx) {
OpenGaussUpdateStatement result = new OpenGaussUpdateStatement();
SimpleTableSegment tableSegment = (SimpleTableSegment) visit(ctx.relationExprOptAlias());
result.setTableSegment(tableSegment);
result.setTable(tableSegment);
result.setSetAssignment((SetAssignmentSegment) visit(ctx.setClauseList()));
if (null != ctx.whereOrCurrentClause()) {
result.setWhere((WhereSegment) visit(ctx.whereOrCurrentClause()));
Expand All @@ -802,7 +802,7 @@ public ASTNode visitSetClauseList(final SetClauseListContext ctx) {
public ASTNode visitDelete(final DeleteContext ctx) {
OpenGaussDeleteStatement result = new OpenGaussDeleteStatement();
SimpleTableSegment tableSegment = (SimpleTableSegment) visit(ctx.relationExprOptAlias());
result.setTableSegment(tableSegment);
result.setTable(tableSegment);
if (null != ctx.whereOrCurrentClause()) {
result.setWhere((WhereSegment) visit(ctx.whereOrCurrentClause()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ public ASTNode visitMultiTableElement(final MultiTableElementContext ctx) {
@Override
public ASTNode visitUpdate(final UpdateContext ctx) {
OracleUpdateStatement result = new OracleUpdateStatement();
result.setTableSegment((TableSegment) visit(ctx.updateSpecification()));
result.setTable((TableSegment) visit(ctx.updateSpecification()));
if (null != ctx.alias()) {
result.getTableSegment().setAlias((AliasSegment) visit(ctx.alias()));
result.getTable().setAlias((AliasSegment) visit(ctx.alias()));
}
result.setSetAssignment((SetAssignmentSegment) visit(ctx.updateSetClause()));
if (null != ctx.whereClause()) {
Expand Down Expand Up @@ -424,9 +424,9 @@ public ASTNode visitAssignmentValue(final AssignmentValueContext ctx) {
@Override
public ASTNode visitDelete(final DeleteContext ctx) {
OracleDeleteStatement result = new OracleDeleteStatement();
result.setTableSegment((TableSegment) visit(ctx.deleteSpecification()));
result.setTable((TableSegment) visit(ctx.deleteSpecification()));
if (null != ctx.alias()) {
result.getTableSegment().setAlias((AliasSegment) visit(ctx.alias()));
result.getTable().setAlias((AliasSegment) visit(ctx.alias()));
}
if (null != ctx.whereClause()) {
result.setWhere((WhereSegment) visit(ctx.whereClause()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ public ASTNode visitRelationExprOptAlias(final RelationExprOptAliasContext ctx)
public ASTNode visitUpdate(final UpdateContext ctx) {
PostgreSQLUpdateStatement result = new PostgreSQLUpdateStatement();
SimpleTableSegment tableSegment = (SimpleTableSegment) visit(ctx.relationExprOptAlias());
result.setTableSegment(tableSegment);
result.setTable(tableSegment);
result.setSetAssignment((SetAssignmentSegment) visit(ctx.setClauseList()));
if (null != ctx.whereOrCurrentClause()) {
result.setWhere((WhereSegment) visit(ctx.whereOrCurrentClause()));
Expand All @@ -771,7 +771,7 @@ public ASTNode visitSetClauseList(final SetClauseListContext ctx) {
public ASTNode visitDelete(final DeleteContext ctx) {
PostgreSQLDeleteStatement result = new PostgreSQLDeleteStatement();
SimpleTableSegment tableSegment = (SimpleTableSegment) visit(ctx.relationExprOptAlias());
result.setTableSegment(tableSegment);
result.setTable(tableSegment);
if (null != ctx.whereOrCurrentClause()) {
result.setWhere((WhereSegment) visit(ctx.whereOrCurrentClause()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private Collection<InsertValuesSegment> createInsertValuesSegments(final Collect
@Override
public ASTNode visitUpdate(final UpdateContext ctx) {
SQL92UpdateStatement result = new SQL92UpdateStatement();
result.setTableSegment((TableSegment) visit(ctx.tableReferences()));
result.setTable((TableSegment) visit(ctx.tableReferences()));
result.setSetAssignment((SetAssignmentSegment) visit(ctx.setAssignmentsClause()));
if (null != ctx.whereClause()) {
result.setWhere((WhereSegment) visit(ctx.whereClause()));
Expand Down Expand Up @@ -197,7 +197,7 @@ public ASTNode visitAssignmentValue(final AssignmentValueContext ctx) {
@Override
public ASTNode visitDelete(final DeleteContext ctx) {
SQL92DeleteStatement result = new SQL92DeleteStatement();
result.setTableSegment((TableSegment) visit(ctx.singleTableClause()));
result.setTable((TableSegment) visit(ctx.singleTableClause()));
if (null != ctx.whereClause()) {
result.setWhere((WhereSegment) visit(ctx.whereClause()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ public ASTNode visitUpdate(final UpdateContext ctx) {
if (null != ctx.withClause()) {
result.setWithSegment((WithSegment) visit(ctx.withClause()));
}
result.setTableSegment((TableSegment) visit(ctx.tableReferences()));
result.setTable((TableSegment) visit(ctx.tableReferences()));
result.setSetAssignment((SetAssignmentSegment) visit(ctx.setAssignmentsClause()));
if (null != ctx.whereClause()) {
result.setWhere((WhereSegment) visit(ctx.whereClause()));
Expand Down Expand Up @@ -1044,9 +1044,9 @@ public ASTNode visitDelete(final DeleteContext ctx) {
result.setWithSegment((WithSegment) visit(ctx.withClause()));
}
if (null != ctx.multipleTablesClause()) {
result.setTableSegment((TableSegment) visit(ctx.multipleTablesClause()));
result.setTable((TableSegment) visit(ctx.multipleTablesClause()));
} else {
result.setTableSegment((TableSegment) visit(ctx.singleTableClause()));
result.setTable((TableSegment) visit(ctx.singleTableClause()));
}
if (null != ctx.outputClause()) {
result.setOutputSegment((OutputSegment) visit(ctx.outputClause()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private void extractTablesFromLock(final LockSegment lockSegment) {
* @param deleteStatement delete statement
*/
public void extractTablesFromDelete(final DeleteStatement deleteStatement) {
extractTablesFromTableSegment(deleteStatement.getTableSegment());
extractTablesFromTableSegment(deleteStatement.getTable());
if (deleteStatement.getWhere().isPresent()) {
extractTablesFromExpression(deleteStatement.getWhere().get().getExpr());
}
Expand Down Expand Up @@ -248,7 +248,7 @@ private void extractTablesFromColumnSegments(final Collection<ColumnSegment> col
* @param updateStatement update statement.
*/
public void extractTablesFromUpdate(final UpdateStatement updateStatement) {
extractTablesFromTableSegment(updateStatement.getTableSegment());
extractTablesFromTableSegment(updateStatement.getTable());
updateStatement.getSetAssignment().getAssignments().forEach(each -> extractTablesFromExpression(each.getColumns().get(0)));
if (updateStatement.getWhere().isPresent()) {
extractTablesFromExpression(updateStatement.getWhere().get().getExpr());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public abstract class DeleteStatement extends AbstractSQLStatement implements DMLStatement {

@Getter
private TableSegment tableSegment;
private TableSegment table;

private WhereSegment where;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@ToString(callSuper = true)
public abstract class UpdateStatement extends AbstractSQLStatement implements DMLStatement {

private TableSegment tableSegment;
private TableSegment table;

private SetAssignmentSegment setAssignment;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ private static void assertWithClause(final SQLCaseAssertContext assertContext, f

private static void assertTable(final SQLCaseAssertContext assertContext, final DeleteStatement actual, final DeleteStatementTestCase expected) {
if (null != expected.getTables() && !expected.getTables().isEmpty()) {
assertNotNull(assertContext.getText("Actual table segment should exist."), actual.getTableSegment());
assertNotNull(assertContext.getText("Actual table segment should exist."), actual.getTable());
List<SimpleTableSegment> actualTableSegments = new LinkedList<>();
if (actual.getTableSegment() instanceof SimpleTableSegment) {
actualTableSegments.add((SimpleTableSegment) actual.getTableSegment());
} else if (actual.getTableSegment() instanceof DeleteMultiTableSegment) {
DeleteMultiTableSegment deleteMultiTableSegment = (DeleteMultiTableSegment) actual.getTableSegment();
if (actual.getTable() instanceof SimpleTableSegment) {
actualTableSegments.add((SimpleTableSegment) actual.getTable());
} else if (actual.getTable() instanceof DeleteMultiTableSegment) {
DeleteMultiTableSegment deleteMultiTableSegment = (DeleteMultiTableSegment) actual.getTable();
actualTableSegments.addAll(deleteMultiTableSegment.getActualDeleteTables());
}
TableAssert.assertIs(assertContext, actualTableSegments, expected.getTables());
} else if (null != expected.getSubqueryTable()) {
assertNotNull(assertContext.getText("Actual subquery table segment should exist."), actual.getTableSegment());
TableAssert.assertIs(assertContext, (SubqueryTableSegment) actual.getTableSegment(), expected.getSubqueryTable());
assertNotNull(assertContext.getText("Actual subquery table segment should exist."), actual.getTable());
TableAssert.assertIs(assertContext, (SubqueryTableSegment) actual.getTable(), expected.getSubqueryTable());
} else {
assertNull(assertContext.getText("Actual table should not exist."), actual.getTableSegment());
assertNull(assertContext.getText("Actual table should not exist."), actual.getTable());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final Upda

private static void assertTable(final SQLCaseAssertContext assertContext, final UpdateStatement actual, final UpdateStatementTestCase expected) {
if (null != expected.getTable()) {
TableAssert.assertIs(assertContext, actual.getTableSegment(), expected.getTable());
TableAssert.assertIs(assertContext, actual.getTable(), expected.getTable());
} else {
assertNull(assertContext.getText("Actual from should not exist."), actual.getTableSegment());
assertNull(assertContext.getText("Actual from should not exist."), actual.getTable());
}
}

Expand Down

0 comments on commit 2e65417

Please sign in to comment.