Merge pull request #34357 from kssenii/fix-clickhouse-local-use-db

Fix USE database for clickhouse-local
This commit is contained in:
alexey-milovidov 2022-02-06 20:29:26 +03:00 committed by GitHub
commit 4b1e1314b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 2 deletions

View File

@ -74,6 +74,8 @@ void LocalConnection::sendQuery(
query_context->setProgressCallback([this] (const Progress & value) { return this->updateProgress(value); });
query_context->setFileProgressCallback([this](const FileProgress & value) { this->updateProgress(Progress(value)); });
}
if (!current_database.empty())
query_context->setCurrentDatabase(current_database);
CurrentThread::QueryScope query_scope_holder(query_context);
@ -427,9 +429,9 @@ void LocalConnection::getServerVersion(
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Not implemented");
}
void LocalConnection::setDefaultDatabase(const String &)
void LocalConnection::setDefaultDatabase(const String & database)
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Not implemented");
current_database = database;
}
UInt64 LocalConnection::getServerRevision(const ConnectionTimeouts &)

View File

@ -142,5 +142,7 @@ private:
/// Last "server" packet.
std::optional<UInt64> next_packet_type;
String current_database;
};
}

View File

@ -0,0 +1,12 @@
SHOW TABLES;
CREATE DATABASE test1;
CREATE TABLE test1.table1 (a Int32) ENGINE=Memory;
USE test1;
SHOW TABLES;
table1
CREATE DATABASE test2;
USE test2;
SHOW TABLES;
USE test1;
SHOW TABLES;
table1

View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
$CLICKHOUSE_LOCAL --echo --multiline --multiquery -q """
SHOW TABLES;
CREATE DATABASE test1;
CREATE TABLE test1.table1 (a Int32) ENGINE=Memory;
USE test1;
SHOW TABLES;
CREATE DATABASE test2;
USE test2;
SHOW TABLES;
USE test1;
SHOW TABLES;
"""