Merge pull request #47573 from azat/odbc-fix

Change error code in case of columns definitions was empty in ODBC
This commit is contained in:
robot-ch-test-poll3 2023-03-15 12:31:54 +01:00 committed by GitHub
commit 9d14c14a54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,7 +30,7 @@ namespace DB
namespace ErrorCodes namespace ErrorCodes
{ {
extern const int LOGICAL_ERROR; extern const int UNKNOWN_TABLE;
extern const int BAD_ARGUMENTS; extern const int BAD_ARGUMENTS;
} }
@ -180,8 +180,19 @@ void ODBCColumnsInfoHandler::handleRequest(HTTPServerRequest & request, HTTPServ
columns.emplace_back(column_name, std::move(column_type)); columns.emplace_back(column_name, std::move(column_type));
} }
/// Usually this should not happen, since in case of table does not
/// exists, the call should be succeeded.
/// However it is possible sometimes because internally there are two
/// queries in ClickHouse ODBC bridge:
/// - system.tables
/// - system.columns
/// And if between this two queries the table will be removed, them
/// there will be no columns
///
/// Also sometimes system.columns can return empty result because of
/// the cached value of total tables to scan.
if (columns.empty()) if (columns.empty())
throw Exception(ErrorCodes::LOGICAL_ERROR, "Columns definition was not returned"); throw Exception(ErrorCodes::UNKNOWN_TABLE, "Columns definition was not returned");
WriteBufferFromHTTPServerResponse out( WriteBufferFromHTTPServerResponse out(
response, response,