mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-03 13:02:00 +00:00
Merge pull request #31333 from azat/global-ctx-tmp-tables
Do not try to resolve temporary tables from global context
This commit is contained in:
commit
c3219a00aa
@ -1661,7 +1661,9 @@ void ClusterCopier::dropAndCreateLocalTable(const ASTPtr & create_ast)
|
||||
const auto & create = create_ast->as<ASTCreateQuery &>();
|
||||
dropLocalTableIfExists({create.database, create.table});
|
||||
|
||||
InterpreterCreateQuery interpreter(create_ast, getContext());
|
||||
auto create_context = Context::createCopy(getContext());
|
||||
|
||||
InterpreterCreateQuery interpreter(create_ast, create_context);
|
||||
interpreter.execute();
|
||||
}
|
||||
|
||||
@ -1672,7 +1674,9 @@ void ClusterCopier::dropLocalTableIfExists(const DatabaseAndTableName & table_na
|
||||
drop_ast->database = table_name.first;
|
||||
drop_ast->table = table_name.second;
|
||||
|
||||
InterpreterDropQuery interpreter(drop_ast, getContext());
|
||||
auto drop_context = Context::createCopy(getContext());
|
||||
|
||||
InterpreterDropQuery interpreter(drop_ast, drop_context);
|
||||
interpreter.execute();
|
||||
}
|
||||
|
||||
|
@ -167,10 +167,18 @@ void ClusterCopierApp::mainImpl()
|
||||
DatabaseCatalog::instance().attachDatabase(default_database, std::make_shared<DatabaseMemory>(default_database, context));
|
||||
context->setCurrentDatabase(default_database);
|
||||
|
||||
/// Initialize query scope just in case.
|
||||
CurrentThread::QueryScope query_scope(context);
|
||||
/// Disable queries logging, since:
|
||||
/// - There are bits that is not allowed for global context, like adding factories info (for the query_log)
|
||||
/// - And anyway it is useless for copier.
|
||||
context->setSetting("log_queries", false);
|
||||
|
||||
auto copier = std::make_unique<ClusterCopier>(task_path, host_id, default_database, context, log);
|
||||
auto local_context = Context::createCopy(context);
|
||||
|
||||
/// Initialize query scope just in case.
|
||||
CurrentThread::QueryScope query_scope(local_context);
|
||||
|
||||
auto copier = std::make_unique<ClusterCopier>(
|
||||
task_path, host_id, default_database, local_context, log);
|
||||
copier->setSafeMode(is_safe_mode);
|
||||
copier->setCopyFaultProbability(copy_fault_probability);
|
||||
copier->setMoveFaultProbability(move_fault_probability);
|
||||
|
@ -871,7 +871,9 @@ const Block * Context::tryGetLocalScalar(const String & name) const
|
||||
|
||||
Tables Context::getExternalTables() const
|
||||
{
|
||||
assert(!isGlobalContext() || getApplicationType() == ApplicationType::LOCAL);
|
||||
if (isGlobalContext())
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Global context cannot have external tables");
|
||||
|
||||
auto lock = getLock();
|
||||
|
||||
Tables res;
|
||||
@ -896,7 +898,9 @@ Tables Context::getExternalTables() const
|
||||
|
||||
void Context::addExternalTable(const String & table_name, TemporaryTableHolder && temporary_table)
|
||||
{
|
||||
assert(!isGlobalContext() || getApplicationType() == ApplicationType::LOCAL);
|
||||
if (isGlobalContext())
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Global context cannot have external tables");
|
||||
|
||||
auto lock = getLock();
|
||||
if (external_tables_mapping.end() != external_tables_mapping.find(table_name))
|
||||
throw Exception("Temporary table " + backQuoteIfNeed(table_name) + " already exists.", ErrorCodes::TABLE_ALREADY_EXISTS);
|
||||
@ -906,7 +910,9 @@ void Context::addExternalTable(const String & table_name, TemporaryTableHolder &
|
||||
|
||||
std::shared_ptr<TemporaryTableHolder> Context::removeExternalTable(const String & table_name)
|
||||
{
|
||||
assert(!isGlobalContext() || getApplicationType() == ApplicationType::LOCAL);
|
||||
if (isGlobalContext())
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Global context cannot have external tables");
|
||||
|
||||
std::shared_ptr<TemporaryTableHolder> holder;
|
||||
{
|
||||
auto lock = getLock();
|
||||
@ -922,21 +928,27 @@ std::shared_ptr<TemporaryTableHolder> Context::removeExternalTable(const String
|
||||
|
||||
void Context::addScalar(const String & name, const Block & block)
|
||||
{
|
||||
assert(!isGlobalContext() || getApplicationType() == ApplicationType::LOCAL);
|
||||
if (isGlobalContext())
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Global context cannot have scalars");
|
||||
|
||||
scalars[name] = block;
|
||||
}
|
||||
|
||||
|
||||
void Context::addLocalScalar(const String & name, const Block & block)
|
||||
{
|
||||
assert(!isGlobalContext() || getApplicationType() == ApplicationType::LOCAL);
|
||||
if (isGlobalContext())
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Global context cannot have local scalars");
|
||||
|
||||
local_scalars[name] = block;
|
||||
}
|
||||
|
||||
|
||||
bool Context::hasScalar(const String & name) const
|
||||
{
|
||||
assert(!isGlobalContext() || getApplicationType() == ApplicationType::LOCAL);
|
||||
if (isGlobalContext())
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Global context cannot have scalars");
|
||||
|
||||
return scalars.count(name);
|
||||
}
|
||||
|
||||
@ -948,7 +960,9 @@ void Context::addQueryAccessInfo(
|
||||
const String & projection_name,
|
||||
const String & view_name)
|
||||
{
|
||||
assert(!isGlobalContext() || getApplicationType() == ApplicationType::LOCAL);
|
||||
if (isGlobalContext())
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Global context cannot have query access info");
|
||||
|
||||
std::lock_guard<std::mutex> lock(query_access_info.mutex);
|
||||
query_access_info.databases.emplace(quoted_database_name);
|
||||
query_access_info.tables.emplace(full_quoted_table_name);
|
||||
@ -962,7 +976,9 @@ void Context::addQueryAccessInfo(
|
||||
|
||||
void Context::addQueryFactoriesInfo(QueryLogFactories factory_type, const String & created_object) const
|
||||
{
|
||||
assert(!isGlobalContext() || getApplicationType() == ApplicationType::LOCAL);
|
||||
if (isGlobalContext())
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Global context cannot have query factories info");
|
||||
|
||||
auto lock = getLock();
|
||||
|
||||
switch (factory_type)
|
||||
@ -2821,6 +2837,10 @@ StorageID Context::resolveStorageIDImpl(StorageID storage_id, StorageNamespace w
|
||||
}
|
||||
|
||||
bool look_for_external_table = where & StorageNamespace::ResolveExternal;
|
||||
/// Global context should not contain temporary tables
|
||||
if (isGlobalContext())
|
||||
look_for_external_table = false;
|
||||
|
||||
bool in_current_database = where & StorageNamespace::ResolveCurrentDatabase;
|
||||
bool in_specified_database = where & StorageNamespace::ResolveGlobal;
|
||||
|
||||
@ -2838,9 +2858,6 @@ StorageID Context::resolveStorageIDImpl(StorageID storage_id, StorageNamespace w
|
||||
|
||||
if (look_for_external_table)
|
||||
{
|
||||
/// Global context should not contain temporary tables
|
||||
assert(!isGlobalContext() || getApplicationType() == ApplicationType::LOCAL);
|
||||
|
||||
auto resolved_id = StorageID::createEmpty();
|
||||
auto try_resolve = [&](ContextPtr context) -> bool
|
||||
{
|
||||
|
@ -0,0 +1,5 @@
|
||||
-- { echo }
|
||||
SELECT * FROM remote('127.1', system.one, 1 IN id); -- { serverError UNKNOWN_TABLE }
|
||||
SELECT * FROM remote('127.1', system.one, 1 IN dummy); -- { serverError UNKNOWN_TABLE }
|
||||
SELECT * FROM remote('127.1', view(SELECT * FROM system.one), 1 IN id); -- { serverError UNKNOWN_TABLE }
|
||||
SELECT * FROM remote('127.1', view(SELECT number AS id FROM numbers(2)), 1 IN id); -- { serverError UNKNOWN_TABLE }
|
@ -0,0 +1,5 @@
|
||||
-- { echo }
|
||||
SELECT * FROM remote('127.1', system.one, 1 IN id); -- { serverError UNKNOWN_TABLE }
|
||||
SELECT * FROM remote('127.1', system.one, 1 IN dummy); -- { serverError UNKNOWN_TABLE }
|
||||
SELECT * FROM remote('127.1', view(SELECT * FROM system.one), 1 IN id); -- { serverError UNKNOWN_TABLE }
|
||||
SELECT * FROM remote('127.1', view(SELECT number AS id FROM numbers(2)), 1 IN id); -- { serverError UNKNOWN_TABLE }
|
Loading…
Reference in New Issue
Block a user