-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Support Column rename for unique/foreign key constraints #47851
[Feature] Support Column rename for unique/foreign key constraints #47851
Conversation
for (Pair<String, String> pair : columnRefPairs) { | ||
List<Pair<ColumnId, ColumnId>> columnRefPairs = Streams.zip(childColumnIds.stream(), | ||
parentColumnIds.stream(), Pair::create).collect(Collectors.toList()); | ||
for (Pair<ColumnId, ColumnId> pair : columnRefPairs) { | ||
Column childColumn = childTable.getColumn(pair.first); | ||
Column parentColumn = parentTable.getColumn(pair.second); | ||
if (!childColumn.getType().equals(parentColumn.getType())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most risky bug in this code is:
Inconsistent unique constraint materialized view table name retrieval, which may cause NullPointerException
.
You can modify the code like this:
if (table.isMaterializedView()) {
Table uniqueConstraintTable = GlobalStateMgr.getCurrentState().getMetadataMgr().getTable(tableName.getCatalog(),
tableName.getDb(), tableName.getTbl());
if (uniqueConstraintTable == null) {
throw new SemanticException(
String.format("table: %s does not exist", tableName));
}
List<ColumnId> columnIds = MetaUtils.getColumnIdsByColumnNames(uniqueConstraintTable, columnNames);
analyzedUniqueConstraints.add(new UniqueConstraint(tableName.getCatalog(), tableName.getDb(), tableName.getTbl(), columnIds));
} else {
List<ColumnId> columnIds = MetaUtils.getColumnIdsByColumnNames(table, columnNames);
analyzedUniqueConstraints.add(new UniqueConstraint(table.getCatalogName(), db.getFullName(), table.getName(), columnIds));
}
@@ -172,6 +212,6 @@ private static void parseUniqueConstraintColumns(String defaultCatalogName, Stri | |||
tableName = defaultTableName; | |||
} | |||
|
|||
uniqueConstraints.add(new UniqueConstraint(catalogName, dbName, tableName, uniqueConstraintColumns)); | |||
return Pair.create(new TableName(catalogName, dbName, tableName), uniqueConstraintColumns); | |||
} | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most risky bug in this code is:
Using getUniqueColumns()
instead of getUniqueColumnNames()
in the toString
method.
You can modify the code like this:
public String toString() {
StringBuilder sb = new StringBuilder();
if (tableName != null) {
sb.append(tableName).append(".");
}
sb.append(Joiner.on(",").join(getUniqueColumnNames())); // Change from getUniqueColumns() to getUniqueColumnNames()
return sb.toString();
}
constraintSb.append(parentColumns); | ||
constraintSb.append(")"); | ||
constraintStrs.add(constraintSb.toString()); | ||
} | ||
|
||
sb.append(Joiner.on(";").join(constraintStrs)); | ||
return sb.toString(); | ||
return Joiner.on(";").join(constraintStrs); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most risky bug in this code is:
Potential NullPointerException
due to missing null checks for the tables returned by MetaUtils.getTable
.
You can modify the code like this:
private Table getParentTable() {
Table table;
if (parentTableInfo.isInternalCatalog()) {
table = MetaUtils.getTable(parentTableInfo.getDbId(), parentTableInfo.getTableId());
} else {
table = MetaUtils.getTable(parentTableInfo.getCatalogName(), parentTableInfo.getDbName(),
parentTableInfo.getTableName());
}
if (table == null) {
LOG.warn("Parent table {} not found", parentTableInfo);
throw new IllegalStateException("Parent table not found");
}
return table;
}
private Table getChildTable() {
Table table;
if (childTableInfo.isInternalCatalog()) {
table = MetaUtils.getTable(childTableInfo.getDbId(), childTableInfo.getTableId());
} else {
table = MetaUtils.getTable(childTableInfo.getCatalogName(), childTableInfo.getDbName(),
childTableInfo.getTableName());
}
if (table == null) {
LOG.warn("Child table {} not found", childTableInfo);
throw new IllegalStateException("Child table not found");
}
return table;
}
Signed-off-by: gengjun-git <[email protected]>
Signed-off-by: gengjun-git <[email protected]>
983a2a7
to
b668508
Compare
Signed-off-by: gengjun-git <[email protected]>
Signed-off-by: gengjun-git <[email protected]>
Signed-off-by: gengjun-git <[email protected]>
Signed-off-by: gengjun-git <[email protected]>
Quality Gate passedIssues Measures |
[FE Incremental Coverage Report]✅ pass : 130 / 147 (88.44%) file detail
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
@Mergifyio backport branch-3.3 |
✅ Backports have been created
|
…47851) Store the ColumnId in ForeignKeyConstraint and UniqueConstraint. Signed-off-by: gengjun-git <[email protected]> (cherry picked from commit ebcd369)
…ackport #47851) (#48278) Co-authored-by: gengjun-git <[email protected]>
ignore backport check: 3.2.10 |
Why I'm doing:
Store the ColumnId in ForeignKeyConstraint and UniqueConstraint.
What I'm doing:
Fixes #42783 #42782
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: