unique names

This commit is contained in:
Nikita Vasilev 2019-01-08 12:38:46 +03:00
parent 541c641b24
commit 48e136f029
3 changed files with 28 additions and 4 deletions

View File

@ -27,8 +27,10 @@ public:
String getID(char) const override { return "Index"; } String getID(char) const override { return "Index"; }
ASTPtr clone() const override { ASTPtr clone() const override {
auto res = std::make_shared<ASTIndexDeclaration>(*this); auto res = std::make_shared<ASTIndexDeclaration>();
res->children.clear();
res->name = name;
res->granularity = granularity;
if (expr) if (expr)
res->set(res->expr, expr->clone()); res->set(res->expr, expr->clone());

View File

@ -47,6 +47,7 @@
#include <algorithm> #include <algorithm>
#include <iomanip> #include <iomanip>
#include <set>
#include <thread> #include <thread>
#include <typeinfo> #include <typeinfo>
#include <typeindex> #include <typeindex>
@ -351,15 +352,27 @@ void MergeTreeData::setPrimaryKeyAndColumns(
void MergeTreeData::setSkipIndexes(const ASTs & indexes_asts, bool only_check) void MergeTreeData::setSkipIndexes(const ASTs & indexes_asts, bool only_check)
{ {
if (!only_check) { indexes.clear();
for (const auto &index_ast : indexes_asts) { std::set<String> names;
if (!only_check)
{
for (const auto &index_ast : indexes_asts)
{
indexes.push_back( indexes.push_back(
std::move(MergeTreeIndexFactory::instance().get( std::move(MergeTreeIndexFactory::instance().get(
*this, *this,
std::dynamic_pointer_cast<ASTIndexDeclaration>(index_ast), std::dynamic_pointer_cast<ASTIndexDeclaration>(index_ast),
global_context))); global_context)));
if (names.find(indexes.back()->name) != names.end())
{
throw Exception(
"Index with name `" + indexes.back()->name + "` already exsists",
ErrorCodes::LOGICAL_ERROR);
}
LOG_DEBUG(log, "new index init : " << indexes.back()->name);
} }
} }
LOG_DEBUG(log, "Indexes size: " << indexes.size());
} }

View File

@ -12,6 +12,12 @@
namespace DB { namespace DB {
namespace ErrorCodes
{
extern const int FILE_DOESNT_EXIST;
}
class MergeTreeTestIndex; class MergeTreeTestIndex;
struct MergeTreeTestGranule : public MergeTreeIndexGranule { struct MergeTreeTestGranule : public MergeTreeIndexGranule {
@ -24,6 +30,9 @@ struct MergeTreeTestGranule : public MergeTreeIndexGranule {
void deserializeBinary(ReadBuffer &istr) override { void deserializeBinary(ReadBuffer &istr) override {
readIntBinary(emp, istr); readIntBinary(emp, istr);
if (emp != 10) {
throw Exception("kek bad read", ErrorCodes::FILE_DOESNT_EXIST);
}
//std::cerr << "TESTINDEX: read " << emp << "\n"; //std::cerr << "TESTINDEX: read " << emp << "\n";
} }