Uh oh!
There was an error while loading. Please reload this page.
[chore](nereids) Added compatibility with mysql alias conflict - #38104
Conversation
This reverts commit 1131d2f.
doris-robot
commented
Jul 18, 2024
Thank you for your contribution to Apache Doris. Since 2024-03-18, the Document has been moved to doris-website. |
Toms1999
commented
Jul 18, 2024
buildall |
| sql """ DROP TABLE IF EXISTS `test3` """ | ||
| sql """ | ||
| CREATE TABLE `test1` ( |
There was a problem hiding this comment.
test1 table conflict to nereids_syntax_p0/test_limit.groovy, please rename to other table name, e.g. test_alias_tbl1, test_alias_tbl2
| // get table name | ||
| } else if (child instanceof LogicalFilter) { | ||
| Plan grandChild = child.children().get(0); | ||
| if (grandChild instanceof LogicalOlapScan) { |
There was a problem hiding this comment.
you should support other table type, for example, LogicalFileScan for hive table, so LogicalCatalogRelation is more suitable
| Set<String> tableNames = new HashSet<>(); | ||
| List<Plan> children = join.children(); | ||
| for (Plan child : children) { |
There was a problem hiding this comment.
this seems only check one level alias, can you support check conflict names between multiple level?
| sql "select * from (select * from test1) a, (select * from test1) a;" | ||
| exception "Not unique table/alias: 'a'" | ||
| } | ||
There was a problem hiding this comment.
Add more cases
multi_sql """ DROP TABLE IF EXISTS test_alias_tbl1; CREATE TABLE IF NOT EXISTS `test_alias_tbl1 ` ( `id` varchar(64) NULL ) DISTRIBUTED BY HASH(`id`) PROPERTIES ( "replication_num"="1" );"""
test {
sql "select * from test_alias_tbl1, test_alias_tbl1 b, test_alias_tbl1 c, test_alias_tbl1"
exception "Not unique table/alias: 'test_alias_tbl1'"
}
test {
sql """select * from test_alias_tbl1 join test_alias_tbl1 b on test_alias_tbl1.id = b.id join test_alias_tbl1 c on b.id = c.id join test_alias_tbl1 on true"""
exception "Not unique table/alias: 'test_alias_tbl1'"
}924060929
commented
Jul 19, 2024
run buildall |
924060929
commented
Jul 19, 2024
run buildall |
| // Recursive method to check for duplicate table names or aliases | ||
| private void checkPlan(Plan plan, Set<String> tableNames) throws AnalysisException { | ||
| if (plan instanceof LogicalSubQueryAlias) { | ||
| LogicalSubQueryAlias subQueryAlias = (LogicalSubQueryAlias) plan; | ||
| String alias = subQueryAlias.getAlias(); | ||
| if (!tableNames.add(alias)) { | ||
| throw new AnalysisException("Not unique table/alias: '" + alias + "'"); | ||
| } | ||
| } else if (plan instanceof LogicalCatalogRelation) { | ||
| LogicalCatalogRelation relation = (LogicalCatalogRelation) plan; | ||
| String tableName = relation.getTable().getName(); | ||
| if (!tableNames.add(tableName)) { | ||
| throw new AnalysisException("Not unique table/alias: '" + tableName + "'"); | ||
| } | ||
| } else { | ||
| // Recursively check the children of the current plan | ||
| for (Plan child : plan.children()) { | ||
| checkPlan(child, tableNames); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
how about refactor to
privatevoidcheckConflictAlias(Planplan) {
Set<String> existsTableNames = Sets.newLinkedHashSet();
Consumer<String> checkAlias = tableAliasName -> {
if (!existsTableNames.add(tableAliasName)) {
thrownewAnalysisException("Not unique table/alias: '" + tableAliasName + "'");
}
};
booleanstopCheckChildren = true;
plan.foreach(p -> {
if (pinstanceofLogicalSubQueryAlias) {
checkAlias.accept(((LogicalSubQueryAlias<?>) p).getAlias());
returnstopCheckChildren;
} elseif (pinstanceofLogicalCatalogRelation) {
TableIftable = ((LogicalCatalogRelation) p).getTable();
checkAlias.accept(table.getName());
returnstopCheckChildren;
} else {
return !stopCheckChildren;
}
});
}924060929
commented
Jul 22, 2024
run buildall |
Toms1999
commented
Jul 22, 2024
run buildall |
doris-robot
commented
Jul 22, 2024
TPC-H: Total hot run time: 39863 ms |
doris-robot
commented
Jul 22, 2024
TPC-DS: Total hot run time: 172241 ms |
doris-robot
commented
Jul 22, 2024
ClickBench: Total hot run time: 30.51 s |
Toms1999
commented
Jul 22, 2024
run buildall |
doris-robot
commented
Jul 25, 2024
TPC-H: Total hot run time: 39332 ms |
doris-robot
commented
Jul 25, 2024
TPC-DS: Total hot run time: 173539 ms |
doris-robot
commented
Jul 25, 2024
ClickBench: Total hot run time: 30.42 s |
Toms1999
commented
Jul 26, 2024
run buildall |
Toms1999
commented
Jul 26, 2024
run buildall |
doris-robot
commented
Jul 26, 2024
TPC-H: Total hot run time: 39276 ms |
924060929
commented
Jul 26, 2024
run buildall |
doris-robot
commented
Jul 26, 2024
TPC-H: Total hot run time: 39432 ms |
doris-robot
commented
Jul 26, 2024
TPC-DS: Total hot run time: 172368 ms |
doris-robot
commented
Jul 26, 2024
ClickBench: Total hot run time: 31.19 s |
PR approved by at least one committer and no changes requested. |
throw table name/alias conflict exception to keep same behavior with mysql for example: ```sql select * from test.a b, test.b ``` error: ``` Not unique table/alias: 'b' ```
throw table name/alias conflict exception to keep same behavior with mysql for example: ```sql select * from test.a b, test.b ``` error: ``` Not unique table/alias: 'b' ```
… (#38440) throw table name/alias conflict exception to keep same behavior with mysql for example: ```sql select * from test.a b, test.b ``` error: ``` Not unique table/alias: 'b' ```
…e#38104) throw table name/alias conflict exception to keep same behavior with mysql for example: ```sql select * from test.a b, test.b ``` error: ``` Not unique table/alias: 'b' ```
…e#38104) throw table name/alias conflict exception to keep same behavior with mysql for example: ```sql select * from test.a b, test.b ``` error: ``` Not unique table/alias: 'b' ```
Proposed changes
throw table name/alias conflict exception to keep same behavior with mysql
for example:
error: