[Fix](Nereids) check the tableName in catalog (#19695)

# Proposed changes
In the nereids. Before this PR: when we access some unexists tables. It will report the exception as follows:
```
mysql> select * from tt;
ERROR 1105 (HY000): errCode = 2, detailMessage = Unexpected exception: null
```

After this PR, it will get the following results:
```
mysql> select * from tt;
ERROR 1105 (HY000): errCode = 2, detailMessage = Unexpected exception: Table [tt] does not exist in database [default_cluster:test].
```

## Problem summary
It is because in this [function](f5af07f7b2/fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java (L328)), we ignore the exception. So the size of `tables` in `CascadesContext` is zero not null. So we can only get null after `table = cascadesContext.getTableByName(tableName);`.
This commit is contained in:
Chengpeng Yan
2023-05-17 19:48:30 +08:00
committed by GitHub
parent 9b6b847745
commit 05d47d43bd
2 changed files with 39 additions and 3 deletions

View File

@ -139,9 +139,15 @@ public class BindRelation extends OneAnalysisRuleFactory {
}
String catalogName = cascadesContext.getConnectContext().getCurrentCatalog().getName();
String dbName = cascadesContext.getConnectContext().getDatabase();
TableIf table = cascadesContext.getTables() != null
? cascadesContext.getTableByName(tableName)
: getTable(catalogName, dbName, tableName, cascadesContext.getConnectContext().getEnv());
TableIf table = null;
if (cascadesContext.getTables() != null) {
table = cascadesContext.getTableByName(tableName);
}
if (table == null) {
// In some cases even if we have already called the "cascadesContext.getTableByName",
// it also gets the null. So, we just check it in the catalog again for safety.
table = getTable(catalogName, dbName, tableName, cascadesContext.getConnectContext().getEnv());
}
// TODO: should generate different Scan sub class according to table's type
List<String> tableQualifier = Lists.newArrayList(catalogName, dbName, tableName);