Do not break DROP DICTIONARY after DROP TABLE executed on dictionary

This commit is contained in:
Azat Khuzhin 2020-04-10 02:25:52 +03:00
parent 4a73fe7477
commit 5b3c635200
5 changed files with 29 additions and 2 deletions

View File

@ -70,8 +70,6 @@ StoragePtr DatabaseWithOwnTablesBase::detachTable(const String & table_name)
StoragePtr DatabaseWithOwnTablesBase::detachTableUnlocked(const String & table_name)
{
StoragePtr res;
if (dictionaries.count(table_name))
throw Exception("Cannot detach dictionary " + database_name + "." + table_name + " as table, use DETACH DICTIONARY query.", ErrorCodes::UNKNOWN_TABLE);
auto it = tables.find(table_name);
if (it == tables.end())

View File

@ -11,6 +11,7 @@
#include <Parsers/ASTLiteral.h>
#include <common/logger_useful.h>
#include <Common/typeid_cast.h>
#include <Common/quoteString.h>
#include <Processors/Sources/SourceFromInputStream.h>
#include <Processors/Pipe.h>
@ -22,6 +23,7 @@ namespace ErrorCodes
{
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
extern const int THERE_IS_NO_COLUMN;
extern const int UNKNOWN_TABLE;
}
@ -45,6 +47,11 @@ StorageDictionary::StorageDictionary(
}
}
void StorageDictionary::checkTableCanBeDropped() const
{
throw Exception("Cannot detach dictionary " + backQuoteIfNeed(dictionary_name) + " as table, use DETACH DICTIONARY query.", ErrorCodes::UNKNOWN_TABLE);
}
Pipes StorageDictionary::read(
const Names & column_names,
const SelectQueryInfo & /*query_info*/,

View File

@ -25,6 +25,8 @@ class StorageDictionary final : public ext::shared_ptr_helper<StorageDictionary>
public:
std::string getName() const override { return "Dictionary"; }
void checkTableCanBeDropped() const override;
Pipes read(const Names & column_names,
const SelectQueryInfo & query_info,
const Context & context,

View File

@ -0,0 +1,20 @@
DROP DATABASE IF EXISTS dict_db_01225;
CREATE DATABASE dict_db_01225;
CREATE TABLE dict_db_01225.dict_data (key UInt64, val UInt64) Engine=Memory();
CREATE DICTIONARY dict_db_01225.dict
(
key UInt64 DEFAULT 0,
val UInt64 DEFAULT 10
)
PRIMARY KEY key
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'dict_data' PASSWORD '' DB 'dict_db_01225'))
LIFETIME(MIN 0 MAX 0)
LAYOUT(FLAT());
SYSTEM RELOAD DICTIONARY dict_db_01225.dict;
DROP TABLE dict_db_01225.dict; -- { serverError 60; }
-- Regression:
-- Code: 1000. DB::Exception: Received from localhost:9000. DB::Exception: File not found: ./metadata/dict_db_01225/dict.sql.
DROP DICTIONARY dict_db_01225.dict;
DROP DATABASE dict_db_01225;