[Fix](nereids) fix bind expression compare dbname ignore cluster (#39114) (#39142)

cherry-pick #39114 to branch-2.1
This commit is contained in:
feiniaofeiafei
2024-08-10 18:00:48 +08:00
committed by GitHub
parent 5e1e725cee
commit 3dc150a0da
4 changed files with 70 additions and 6 deletions

View File

@ -674,10 +674,10 @@ public class ExpressionAnalyzer extends SubExprAnalyzer<ExpressionRewriteContext
case 1: // bound slot is `table`.`column`
return false;
case 2:// bound slot is `db`.`table`.`column`
return compareDbName(qualifierStar.get(0), boundSlotQualifier.get(0))
return compareDbNameIgnoreClusterName(qualifierStar.get(0), boundSlotQualifier.get(0))
&& qualifierStar.get(1).equalsIgnoreCase(boundSlotQualifier.get(1));
case 3:// bound slot is `catalog`.`db`.`table`.`column`
return compareDbName(qualifierStar.get(0), boundSlotQualifier.get(1))
return compareDbNameIgnoreClusterName(qualifierStar.get(0), boundSlotQualifier.get(1))
&& qualifierStar.get(1).equalsIgnoreCase(boundSlotQualifier.get(2));
default:
throw new AnalysisException("Not supported qualifier: "
@ -693,7 +693,7 @@ public class ExpressionAnalyzer extends SubExprAnalyzer<ExpressionRewriteContext
return false;
case 3:// bound slot is `catalog`.`db`.`table`.`column`
return qualifierStar.get(0).equalsIgnoreCase(boundSlotQualifier.get(0))
&& compareDbName(qualifierStar.get(1), boundSlotQualifier.get(1))
&& compareDbNameIgnoreClusterName(qualifierStar.get(1), boundSlotQualifier.get(1))
&& qualifierStar.get(2).equalsIgnoreCase(boundSlotQualifier.get(2));
default:
throw new AnalysisException("Not supported qualifier: "
@ -861,7 +861,7 @@ public class ExpressionAnalyzer extends SubExprAnalyzer<ExpressionRewriteContext
List<String> boundSlotQualifier = boundSlot.getQualifier();
String boundSlotDb = boundSlotQualifier.get(boundSlotQualifier.size() - 2);
String boundSlotTable = boundSlotQualifier.get(boundSlotQualifier.size() - 1);
if (!compareDbName(boundSlotDb, db) || !sameTableName(boundSlotTable, table)) {
if (!compareDbNameIgnoreClusterName(boundSlotDb, db) || !sameTableName(boundSlotTable, table)) {
continue;
}
// set sql case as alias
@ -882,7 +882,7 @@ public class ExpressionAnalyzer extends SubExprAnalyzer<ExpressionRewriteContext
String boundSlotDb = boundSlotQualifier.get(boundSlotQualifier.size() - 2);
String boundSlotTable = boundSlotQualifier.get(boundSlotQualifier.size() - 1);
if (!boundSlotCatalog.equalsIgnoreCase(catalog)
|| !compareDbName(boundSlotDb, db)
|| !compareDbNameIgnoreClusterName(boundSlotDb, db)
|| !sameTableName(boundSlotTable, table)) {
continue;
}
@ -891,4 +891,22 @@ public class ExpressionAnalyzer extends SubExprAnalyzer<ExpressionRewriteContext
}
return usedSlots.build();
}
/**compareDbNameIgnoreClusterName.*/
public static boolean compareDbNameIgnoreClusterName(String name1, String name2) {
if (name1.equalsIgnoreCase(name2)) {
return true;
}
String ignoreClusterName1 = name1;
int idx1 = name1.indexOf(":");
if (idx1 > -1) {
ignoreClusterName1 = name1.substring(idx1 + 1);
}
String ignoreClusterName2 = name2;
int idx2 = name2.indexOf(":");
if (idx2 > -1) {
ignoreClusterName2 = name2.substring(idx2 + 1);
}
return ignoreClusterName1.equalsIgnoreCase(ignoreClusterName2);
}
}

View File

@ -213,7 +213,8 @@ public class UpdateCommand extends Command implements ForwardWithSync, Explainab
}
List<String> tableQualifier = RelationUtil.getQualifierName(ctx, nameParts);
if (!ExpressionAnalyzer.sameTableName(tableAlias == null ? tableQualifier.get(2) : tableAlias, tableName)
|| (dbName != null && ExpressionAnalyzer.compareDbName(tableQualifier.get(1), dbName))) {
|| (dbName != null
&& !ExpressionAnalyzer.compareDbNameIgnoreClusterName(tableQualifier.get(1), dbName))) {
throw new AnalysisException("column in assignment list is invalid, " + String.join(".", columnNameParts));
}
}