| 1932 | } |
| 1933 | |
| 1934 | bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create, |
| 1935 | const InterpreterCreateQuery::TableProperties & properties, |
| 1936 | DDLGuardPtr & ddl_guard, LoadingStrictnessLevel mode) |
| 1937 | { |
| 1938 | if (create.isTemporary()) |
| 1939 | { |
| 1940 | if (create.if_not_exists && getContext()->tryResolveStorageID({"", create.getTable()}, Context::ResolveExternal)) |
| 1941 | return false; |
| 1942 | |
| 1943 | DatabasePtr database = DatabaseCatalog::instance().getDatabase(DatabaseCatalog::TEMPORARY_DATABASE); |
| 1944 | |
| 1945 | String temporary_table_name = create.getTable(); |
| 1946 | auto creator = [&](const StorageID & table_id) |
| 1947 | { |
| 1948 | auto res = StorageFactory::instance().get(create, |
| 1949 | database->getTableDataPath(table_id.getTableName()), |
| 1950 | getContext(), |
| 1951 | getContext()->getGlobalContext(), |
| 1952 | properties.columns, |
| 1953 | properties.constraints, |
| 1954 | mode, |
| 1955 | is_restore_from_backup); |
| 1956 | validateStorage(*res, mode, getContext()); |
| 1957 | return res; |
| 1958 | }; |
| 1959 | auto temporary_table = TemporaryTableHolder(getContext(), creator, query_ptr); |
| 1960 | |
| 1961 | getContext()->getSessionContext()->addExternalTable(temporary_table_name, std::move(temporary_table)); |
| 1962 | return true; |
| 1963 | } |
| 1964 | |
| 1965 | if (!ddl_guard && likely(need_ddl_guard)) |
| 1966 | ddl_guard = DatabaseCatalog::instance().getDDLGuard(create.getDatabase(), create.getTable(), nullptr); |
| 1967 | |
| 1968 | String data_path; |
| 1969 | DatabasePtr database; |
| 1970 | |
| 1971 | database = DatabaseCatalog::instance().getDatabase(create.getDatabase()); |
| 1972 | assertOrSetUUID(create, database); |
| 1973 | |
| 1974 | String storage_name = create.is_dictionary ? "Dictionary" : "Table"; |
| 1975 | auto storage_already_exists_error_code = create.is_dictionary ? ErrorCodes::DICTIONARY_ALREADY_EXISTS : ErrorCodes::TABLE_ALREADY_EXISTS; |
| 1976 | |
| 1977 | /// Table can be created before or it can be created concurrently in another thread, while we were waiting in DDLGuard. |
| 1978 | if (database->isTableExist(create.getTable(), getContext())) |
| 1979 | { |
| 1980 | /// TODO Check structure of table |
| 1981 | if (create.if_not_exists) |
| 1982 | return false; |
| 1983 | if (create.replace_view) |
| 1984 | { |
| 1985 | /// when executing CREATE OR REPLACE VIEW, drop current existing view |
| 1986 | auto drop_ast = make_intrusive<ASTDropQuery>(); |
| 1987 | drop_ast->setDatabase(create.getDatabase()); |
| 1988 | drop_ast->setTable(create.getTable()); |
| 1989 | drop_ast->no_ddl_lock = true; |
| 1990 | |
| 1991 | auto drop_context = Context::createCopy(context); |
no test coverage detected