mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-04 21:42:39 +00:00
Move StorageFactory to top of doCreateTable for temp tables
This commit is contained in:
parent
78c0a6ab12
commit
640bb66065
@ -1244,23 +1244,30 @@ bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create,
|
|||||||
const InterpreterCreateQuery::TableProperties & properties,
|
const InterpreterCreateQuery::TableProperties & properties,
|
||||||
DDLGuardPtr & ddl_guard)
|
DDLGuardPtr & ddl_guard)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
if (create.temporary)
|
if (create.temporary)
|
||||||
{
|
{
|
||||||
if (create.if_not_exists && getContext()->tryResolveStorageID({"", create.getTable()}, Context::ResolveExternal))
|
if (create.if_not_exists && getContext()->tryResolveStorageID({"", create.getTable()}, Context::ResolveExternal))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
create.setDatabase(DatabaseCatalog::TEMPORARY_DATABASE);
|
||||||
|
DatabasePtr database = DatabaseCatalog::instance().getDatabase(create.getDatabase());
|
||||||
|
|
||||||
String temporary_table_name = create.getTable();
|
String temporary_table_name = create.getTable();
|
||||||
auto temporary_table = TemporaryTableHolder(getContext(), properties.columns, properties.constraints, query_ptr);
|
auto creator = [&](const StorageID & table_id)
|
||||||
|
{
|
||||||
|
return StorageFactory::instance().get(create,
|
||||||
|
database->getTableDataPath(table_id.getTableName()),
|
||||||
|
getContext(),
|
||||||
|
getContext()->getGlobalContext(),
|
||||||
|
properties.columns,
|
||||||
|
properties.constraints,
|
||||||
|
false);
|
||||||
|
};
|
||||||
|
auto temporary_table = TemporaryTableHolder(getContext(), creator, query_ptr);
|
||||||
|
|
||||||
getContext()->getSessionContext()->addExternalTable(temporary_table_name, std::move(temporary_table));
|
getContext()->getSessionContext()->addExternalTable(temporary_table_name, std::move(temporary_table));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
if (create.temporary)
|
|
||||||
{
|
|
||||||
create.setDatabase(DatabaseCatalog::TEMPORARY_DATABASE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ddl_guard)
|
if (!ddl_guard)
|
||||||
ddl_guard = DatabaseCatalog::instance().getDDLGuard(create.getDatabase(), create.getTable());
|
ddl_guard = DatabaseCatalog::instance().getDDLGuard(create.getDatabase(), create.getTable());
|
||||||
@ -1367,27 +1374,6 @@ bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create,
|
|||||||
res->renameInMemory({create.getDatabase(), create.getTable(), create.uuid});
|
res->renameInMemory({create.getDatabase(), create.getTable(), create.uuid});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if (create.temporary)
|
|
||||||
{
|
|
||||||
String temporary_table_name = create.getTable();
|
|
||||||
// ASTPtr original_create = create.clone();
|
|
||||||
auto creator = [&](const StorageID & table_id)
|
|
||||||
{
|
|
||||||
return StorageFactory::instance().get(create,
|
|
||||||
database->getTableDataPath(table_id.getTableName()),
|
|
||||||
getContext(),
|
|
||||||
getContext()->getGlobalContext(),
|
|
||||||
properties.columns,
|
|
||||||
properties.constraints,
|
|
||||||
false);
|
|
||||||
};
|
|
||||||
auto temporary_table = TemporaryTableHolder(getContext(), creator, query_ptr);
|
|
||||||
|
|
||||||
getContext()->getSessionContext()->addExternalTable(temporary_table_name, std::move(temporary_table));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
res = StorageFactory::instance().get(create,
|
res = StorageFactory::instance().get(create,
|
||||||
data_path,
|
data_path,
|
||||||
@ -1396,7 +1382,6 @@ bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create,
|
|||||||
properties.columns,
|
properties.columns,
|
||||||
properties.constraints,
|
properties.constraints,
|
||||||
false);
|
false);
|
||||||
}
|
|
||||||
|
|
||||||
/// If schema wes inferred while storage creation, add columns description to create query.
|
/// If schema wes inferred while storage creation, add columns description to create query.
|
||||||
addColumnsDescriptionToCreateQueryIfNecessary(query_ptr->as<ASTCreateQuery &>(), res);
|
addColumnsDescriptionToCreateQueryIfNecessary(query_ptr->as<ASTCreateQuery &>(), res);
|
||||||
|
Loading…
Reference in New Issue
Block a user