Move StorageFactory to top of doCreateTable for temp tables

This commit is contained in:
Roman Vasin 2023-01-24 07:39:29 +00:00
parent 78c0a6ab12
commit 640bb66065

View File

@ -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());
@ -1368,35 +1375,13 @@ bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create,
} }
else else
{ {
if (create.temporary) res = StorageFactory::instance().get(create,
{ data_path,
String temporary_table_name = create.getTable(); getContext(),
// ASTPtr original_create = create.clone(); getContext()->getGlobalContext(),
auto creator = [&](const StorageID & table_id) properties.columns,
{ properties.constraints,
return StorageFactory::instance().get(create, false);
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,
data_path,
getContext(),
getContext()->getGlobalContext(),
properties.columns,
properties.constraints,
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);