[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);

View File

@ -0,0 +1,30 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
suite("test_analyzer_exception") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
def tbName = "test_analyzer_exception"
def dbName = "test_analyzer_db"
sql "CREATE DATABASE IF NOT EXISTS ${dbName}"
sql "USE ${dbName}"
test {
sql "SELECT id FROM ${tbName}"
exception "errCode = 2, detailMessage = Unexpected exception: Table [test_analyzer_exception] does not exist in database [default_cluster:test_analyzer_db]."
}
}