dbms: add override to AST types

This commit is contained in:
Andrey Mironov 2014-12-17 18:26:24 +03:00
parent 497ff4b9e9
commit e7301a4050
28 changed files with 140 additions and 119 deletions

View File

@ -87,9 +87,9 @@ public:
ASTAlterQuery(StringRange range_ = StringRange()) : IAST(range_) {};
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return ("AlterQuery_" + database + "_" + table); };
String getID() const override { return ("AlterQuery_" + database + "_" + table); };
ASTPtr clone() const
ASTPtr clone() const override
{
ASTAlterQuery * res = new ASTAlterQuery(*this);
for (ParameterContainer::size_type i = 0; i < parameters.size(); ++i)

View File

@ -11,11 +11,11 @@ namespace DB
class ASTAsterisk : public IAST
{
public:
ASTAsterisk() {}
ASTAsterisk() = default;
ASTAsterisk(StringRange range_) : IAST(range_) {}
String getID() const { return "Asterisk"; }
ASTPtr clone() const { return new ASTAsterisk(*this); }
String getColumnName() const { return "*"; }
String getID() const override { return "Asterisk"; }
ASTPtr clone() const override { return new ASTAsterisk(*this); }
String getColumnName() const override { return "*"; }
};
}

View File

@ -8,12 +8,11 @@ namespace DB
struct ASTCheckQuery : public IAST
{
ASTCheckQuery(StringRange range_ = StringRange()) : IAST(range_) {};
ASTCheckQuery(const ASTCheckQuery & ast) = default;
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return ("CheckQuery_" + database + "_" + table); };
String getID() const override { return ("CheckQuery_" + database + "_" + table); };
ASTPtr clone() const
ASTPtr clone() const override
{
return new ASTCheckQuery(*this);
}

View File

@ -17,13 +17,15 @@ public:
ASTPtr default_expression;
ASTColumnDeclaration() = default;
ASTColumnDeclaration(StringRange range) : IAST{range} {}
ASTColumnDeclaration(const StringRange range) : IAST{range} {}
String getID() const { return "ColumnDeclaration_" + name; }
String getID() const override { return "ColumnDeclaration_" + name; }
ASTPtr clone() const
ASTPtr clone() const override
{
const auto res = new ASTColumnDeclaration{*this};
ASTPtr ptr{res};
res->children.clear();
if (type) {
@ -36,7 +38,7 @@ public:
res->children.push_back(res->default_expression);
}
return res;
return ptr;
}
};

View File

@ -13,12 +13,12 @@ namespace DB
class ASTCreateQuery : public IAST
{
public:
bool attach; /// Запрос ATTACH TABLE, а не CREATE TABLE.
bool if_not_exists;
bool is_view;
bool is_materialized_view;
bool is_populate;
bool is_temporary;
bool attach{false}; /// Запрос ATTACH TABLE, а не CREATE TABLE.
bool if_not_exists{false};
bool is_view{false};
bool is_materialized_view{false};
bool is_populate{false};
bool is_temporary{false};
String database;
String table;
ASTPtr columns;
@ -28,15 +28,17 @@ public:
String as_table;
ASTPtr select;
ASTCreateQuery() : attach(false), if_not_exists(false), is_view(false), is_materialized_view(false), is_populate(false), is_temporary(false) {}
ASTCreateQuery(StringRange range_) : IAST(range_), attach(false), if_not_exists(false), is_view(false), is_materialized_view(false), is_populate(false), is_temporary(false) {}
ASTCreateQuery() = default;
ASTCreateQuery(const StringRange range_) : IAST(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return (attach ? "AttachQuery_" : "CreateQuery_") + database + "_" + table; };
String getID() const override { return (attach ? "AttachQuery_" : "CreateQuery_") + database + "_" + table; };
ASTPtr clone() const
ASTPtr clone() const override
{
ASTCreateQuery * res = new ASTCreateQuery(*this);
ASTPtr ptr{res};
res->children.clear();
if (columns) { res->columns = columns->clone(); res->children.push_back(res->columns); }
@ -44,7 +46,7 @@ public:
if (select) { res->select = select->clone(); res->children.push_back(res->select); }
if (inner_storage) { res->inner_storage = inner_storage->clone(); res->children.push_back(res->inner_storage); }
return res;
return ptr;
}
};

View File

@ -12,18 +12,18 @@ namespace DB
class ASTDropQuery : public IAST
{
public:
bool detach; /// Запрос DETACH, а не DROP.
bool if_exists;
bool detach{false}; /// Запрос DETACH, а не DROP.
bool if_exists{false};
String database;
String table;
ASTDropQuery() : detach(false), if_exists(false) {}
ASTDropQuery(StringRange range_) : IAST(range_), detach(false), if_exists(false) {}
ASTDropQuery() = default;
ASTDropQuery(const StringRange range_) : IAST(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return (detach ? "DetachQuery_" : "DropQuery_") + database + "_" + table; };
String getID() const override { return (detach ? "DetachQuery_" : "DropQuery_") + database + "_" + table; };
ASTPtr clone() const { return new ASTDropQuery(*this); }
ASTPtr clone() const override { return new ASTDropQuery(*this); }
};
}

View File

@ -15,7 +15,7 @@ class ASTExpressionList : public IAST
{
public:
ASTExpressionList() = default;
ASTExpressionList(StringRange range_) : IAST(range_) {}
ASTExpressionList(const StringRange range_) : IAST(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const override { return "ExpressionList"; }

View File

@ -32,12 +32,12 @@ public:
/// параметры - для параметрических агрегатных функций. Пример: quantile(0.9)(x) - то, что в первых скобках - параметры.
ASTPtr parameters;
FunctionKind kind;
FunctionKind kind{UNKNOWN};
ASTFunction() : kind(UNKNOWN) {}
ASTFunction(StringRange range_) : ASTWithAlias(range_), kind(UNKNOWN) {}
ASTFunction() = default;
ASTFunction(const StringRange range_) : ASTWithAlias(range_) {}
String getColumnName() const
String getColumnName() const override
{
String res;
WriteBufferFromString wb(res);
@ -68,17 +68,19 @@ public:
}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return "Function_" + name; }
String getID() const override { return "Function_" + name; }
ASTPtr clone() const
ASTPtr clone() const override
{
ASTFunction * res = new ASTFunction(*this);
ASTPtr ptr{res};
res->children.clear();
if (arguments) { res->arguments = arguments->clone(); res->children.push_back(res->arguments); }
if (parameters) { res->parameters = parameters->clone(); res->children.push_back(res->parameters); }
return res;
return ptr;
}
};

View File

@ -26,17 +26,18 @@ public:
/// чего идентифицирует этот идентификатор
Kind kind;
ASTIdentifier() {}
ASTIdentifier(StringRange range_, const String & name_, Kind kind_ = Column) : ASTWithAlias(range_), name(name_), kind(kind_) {}
ASTIdentifier() = default;
ASTIdentifier(const StringRange range_, const String & name_, const Kind kind_ = Column)
: ASTWithAlias(range_), name(name_), kind(kind_) {}
String getColumnName() const { return name; }
String getColumnName() const override { return name; }
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return "Identifier_" + name; }
String getID() const override { return "Identifier_" + name; }
ASTPtr clone() const { return new ASTIdentifier(*this); }
ASTPtr clone() const override { return new ASTIdentifier(*this); }
void collectIdentifierNames(IdentifierNameSet & set) const
void collectIdentifierNames(IdentifierNameSet & set) const override
{
set.insert(name);
}

View File

@ -24,21 +24,23 @@ public:
const char * data = nullptr;
const char * end = nullptr;
ASTInsertQuery() {}
ASTInsertQuery(StringRange range_) : IAST(range_) {}
ASTInsertQuery() = default;
ASTInsertQuery(const StringRange range_) : IAST(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return "InsertQuery_" + database + "_" + table; };
String getID() const override { return "InsertQuery_" + database + "_" + table; };
ASTPtr clone() const
ASTPtr clone() const override
{
ASTInsertQuery * res = new ASTInsertQuery(*this);
ASTPtr ptr{res};
res->children.clear();
if (columns) { res->columns = columns->clone(); res->children.push_back(res->columns); }
if (select) { res->select = select->clone(); res->children.push_back(res->select); }
return res;
return ptr;
}
};

View File

@ -40,11 +40,11 @@ public:
ASTPtr table; /// "Правая" таблица для соединения - подзапрос или имя таблицы.
ASTPtr using_expr_list; /// По каким столбцам выполнять соединение.
ASTJoin() {}
ASTJoin(StringRange range_) : IAST(range_) {}
ASTJoin() = default;
ASTJoin(const StringRange range_) : IAST(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const
String getID() const override
{
String res;
{
@ -57,19 +57,21 @@ public:
writeString(kind == Inner ? "Inner" : "Left", wb);
writeString("Join", wb);
}
return res;
return res;
};
ASTPtr clone() const
ASTPtr clone() const override
{
ASTJoin * res = new ASTJoin(*this);
ASTPtr ptr{res};
res->children.clear();
if (table) { res->table = table->clone(); res->children.push_back(res->table); }
if (using_expr_list) { res->using_expr_list = using_expr_list->clone(); res->children.push_back(res->using_expr_list); }
return res;
return ptr;
}
};

View File

@ -17,15 +17,15 @@ public:
/// тип
DataTypePtr type;
ASTLiteral() {}
ASTLiteral(StringRange range_, const Field & value_) : ASTWithAlias(range_), value(value_) {}
ASTLiteral() = default;
ASTLiteral(const StringRange range_, const Field & value_) : ASTWithAlias(range_), value(value_) {}
String getColumnName() const { return apply_visitor(FieldVisitorToString(), value); }
String getColumnName() const override { return apply_visitor(FieldVisitorToString(), value); }
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return "Literal_" + apply_visitor(FieldVisitorDump(), value); }
String getID() const override { return "Literal_" + apply_visitor(FieldVisitorDump(), value); }
ASTPtr clone() const { return new ASTLiteral(*this); }
ASTPtr clone() const override { return new ASTLiteral(*this); }
};
}

View File

@ -17,20 +17,22 @@ public:
/// тип
ASTPtr type;
ASTNameTypePair() {}
ASTNameTypePair(StringRange range_) : IAST(range_) {}
ASTNameTypePair() = default;
ASTNameTypePair(const StringRange range_) : IAST(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return "NameTypePair_" + name; }
String getID() const override { return "NameTypePair_" + name; }
ASTPtr clone() const
ASTPtr clone() const override
{
ASTNameTypePair * res = new ASTNameTypePair(*this);
ASTPtr ptr{res};
res->children.clear();
if (type) { res->type = type->clone(); res->children.push_back(res->type); }
return res;
return ptr;
}
};

View File

@ -15,13 +15,13 @@ public:
String database;
String table;
ASTOptimizeQuery() {}
ASTOptimizeQuery(StringRange range_) : IAST(range_) {}
ASTOptimizeQuery() = default;
ASTOptimizeQuery(const StringRange range_) : IAST(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return "OptimizeQuery_" + database + "_" + table; };
String getID() const override { return "OptimizeQuery_" + database + "_" + table; };
ASTPtr clone() const { return new ASTOptimizeQuery(*this); }
ASTPtr clone() const override { return new ASTOptimizeQuery(*this); }
};
}

View File

@ -21,14 +21,14 @@ public:
*/
Poco::SharedPtr<Collator> collator;
ASTOrderByElement() {}
ASTOrderByElement(StringRange range_, int direction_, const Poco::SharedPtr<Collator> & collator_ = nullptr)
ASTOrderByElement() = default;
ASTOrderByElement(const StringRange range_, const int direction_, const Poco::SharedPtr<Collator> & collator_ = nullptr)
: IAST(range_), direction(direction_), collator(collator_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return "OrderByElement"; }
String getID() const override { return "OrderByElement"; }
ASTPtr clone() const { return new ASTOrderByElement(*this); }
ASTPtr clone() const override { return new ASTOrderByElement(*this); }
};
}

View File

@ -14,8 +14,8 @@ class ASTQueryWithOutput : public IAST
public:
ASTPtr format;
ASTQueryWithOutput() {}
ASTQueryWithOutput(StringRange range_) : IAST(range_) {}
ASTQueryWithOutput() = default;
ASTQueryWithOutput(const StringRange range_) : IAST(range_) {}
};
@ -26,18 +26,19 @@ class Name : public ASTQueryWithOutput \
public: \
Name() {} \
Name(StringRange range_) : ASTQueryWithOutput(range_) {} \
String getID() const { return ID; }; \
String getID() const override { return ID; }; \
\
ASTPtr clone() const \
ASTPtr clone() const override \
{ \
Name * res = new Name(*this); \
ASTPtr ptr{res}; \
res->children.clear(); \
if (format) \
{ \
res->format = format->clone(); \
res->children.push_back(res->format); \
} \
return res; \
return ptr; \
} \
};

View File

@ -16,8 +16,8 @@ namespace DB
String database;
String table;
ASTQueryWithTableAndOutput() {}
ASTQueryWithTableAndOutput(StringRange range_) : ASTQueryWithOutput(range_) {}
ASTQueryWithTableAndOutput() = default;
ASTQueryWithTableAndOutput(const StringRange range_) : ASTQueryWithOutput(range_) {}
};
@ -26,20 +26,21 @@ namespace DB
class Name : public ASTQueryWithTableAndOutput \
{ \
public: \
Name() {} \
Name(StringRange range_) : ASTQueryWithTableAndOutput(range_) {} \
String getID() const { return ID"_" + database + "_" + table; }; \
Name() = default; \
Name(const StringRange range_) : ASTQueryWithTableAndOutput(range_) {} \
String getID() const override { return ID"_" + database + "_" + table; }; \
\
ASTPtr clone() const \
ASTPtr clone() const override \
{ \
Name * res = new Name(*this); \
ASTPtr ptr{res}; \
res->children.clear(); \
if (format) \
{ \
res->format = format->clone(); \
res->children.push_back(res->format); \
} \
return res; \
return ptr; \
} \
};
}

View File

@ -27,13 +27,13 @@ public:
typedef std::vector<Element> Elements;
Elements elements;
ASTRenameQuery() {}
ASTRenameQuery(StringRange range_) : IAST(range_) {}
ASTRenameQuery() = default;
ASTRenameQuery(const StringRange range_) : IAST(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return "Rename"; };
String getID() const override { return "Rename"; };
ASTPtr clone() const { return new ASTRenameQuery(*this); }
ASTPtr clone() const override { return new ASTRenameQuery(*this); }
};
}

View File

@ -32,11 +32,11 @@ public:
ASTPtr limit_length;
ASTPtr next_union_all; /// Следующий запрос SELECT в цепочке UNION ALL, если такой есть
ASTSelectQuery() {}
ASTSelectQuery(StringRange range_) : ASTQueryWithOutput(range_) {}
ASTSelectQuery() = default;
ASTSelectQuery(const StringRange range_) : ASTQueryWithOutput(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return "SelectQuery"; };
String getID() const override { return "SelectQuery"; };
/// Проверить наличие функции arrayJoin. (Не большого ARRAY JOIN.)
static bool hasArrayJoin(const ASTPtr & ast)
@ -103,9 +103,11 @@ public:
*/
}
ASTPtr clone() const
ASTPtr clone() const override
{
ASTSelectQuery * res = new ASTSelectQuery(*this);
ASTPtr ptr{res};
res->children.clear();
#define CLONE(member) if (member) { res->member = member->clone(); res->children.push_back(res->member); }
@ -128,7 +130,7 @@ public:
#undef CLONE
return res;
return ptr;
}
};

View File

@ -18,10 +18,10 @@ public:
bool is_explicit = false;
ASTSet(const String & column_name_) : column_name(column_name_) {}
ASTSet(StringRange range_, const String & column_name_) : IAST(range_), column_name(column_name_) {}
String getID() const { return "Set_" + getColumnName(); }
ASTPtr clone() const { return new ASTSet(*this); }
String getColumnName() const { return column_name; }
ASTSet(const StringRange range_, const String & column_name_) : IAST(range_), column_name(column_name_) {}
String getID() const override { return "Set_" + getColumnName(); }
ASTPtr clone() const override { return new ASTSet(*this); }
String getColumnName() const override { return column_name; }
};
}

View File

@ -24,13 +24,13 @@ public:
bool global; /// Если запрос SET GLOBAL.
ASTSetQuery() {}
ASTSetQuery(StringRange range_) : IAST(range_) {}
ASTSetQuery() = default;
ASTSetQuery(const StringRange range_) : IAST(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return "Set"; };
String getID() const override { return "Set"; };
ASTPtr clone() const { return new ASTSetQuery(*this); }
ASTPtr clone() const override { return new ASTSetQuery(*this); }
};
}

View File

@ -13,20 +13,22 @@ namespace DB
class ASTShowTablesQuery : public ASTQueryWithOutput
{
public:
bool databases;
bool databases{false};
String from;
String like;
bool not_like;
bool not_like{false};
ASTShowTablesQuery() : databases(false), not_like(false) {}
ASTShowTablesQuery(StringRange range_) : ASTQueryWithOutput(range_), databases(false), not_like(false) {}
ASTShowTablesQuery() = default;
ASTShowTablesQuery(const StringRange range_) : ASTQueryWithOutput(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return "ShowTables"; };
String getID() const override { return "ShowTables"; };
ASTPtr clone() const
ASTPtr clone() const override
{
ASTShowTablesQuery * res = new ASTShowTablesQuery(*this);
ASTPtr ptr{res};
res->children.clear();
if (format)
@ -35,7 +37,7 @@ public:
res->children.push_back(res->format);
}
return res;
return ptr;
}
};

View File

@ -15,7 +15,7 @@ class ASTSubquery : public IAST
{
public:
ASTSubquery() = default;
ASTSubquery(StringRange range_) : IAST(range_) {}
ASTSubquery(const StringRange range_) : IAST(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const override { return "Subquery"; }
@ -24,6 +24,7 @@ public:
{
const auto res = new ASTSubquery{*this};
ASTPtr ptr{res};
res->children.clear();
for (const auto & child : children)

View File

@ -14,13 +14,13 @@ class ASTUseQuery : public IAST
public:
String database;
ASTUseQuery() {}
ASTUseQuery(StringRange range_) : IAST(range_) {}
ASTUseQuery() = default;
ASTUseQuery(const StringRange range_) : IAST(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const { return "UseQuery_" + database; };
String getID() const override { return "UseQuery_" + database; };
ASTPtr clone() const { return new ASTUseQuery(*this); }
ASTPtr clone() const override { return new ASTUseQuery(*this); }
};
}

View File

@ -23,8 +23,7 @@ public:
/// helper for setting aliases and chaining result to other functions
inline ASTPtr setAlias(ASTPtr ast, const String & alias) {
dynamic_cast<ASTWithAlias &>(*ast).alias = alias;
ast->setAlias(alias);
return ast;
};

View File

@ -38,9 +38,9 @@ public:
*/
StringPtr query_string;
IAST() {}
IAST(StringRange range_) : range(range_) {}
virtual ~IAST() {}
IAST() = default;
IAST(const StringRange range_) : range(range_) {}
virtual ~IAST() = default;
/** Получить каноническое имя столбца, если элемент является столбцом */
virtual String getColumnName() const { throw Exception("Trying to get name of not a column: " + getID(), ErrorCodes::NOT_A_COLUMN); }

View File

@ -32,6 +32,8 @@
#include <DB/Parsers/formatAST.h>
#include <DB/Functions/FunctionFactory.h>
#include <statdaemons/ext/range.hpp>

View File

@ -13,6 +13,7 @@
#include <DB/IO/WriteBufferFromFile.h>
#include <DB/DataTypes/DataTypeDate.h>
#include <DB/Common/localBackup.h>
#include <DB/Functions/FunctionFactory.h>
#include <algorithm>
#include <iomanip>