ClickHouse/dbms/src/Parsers/ASTIndexDeclaration.h

61 lines
1.6 KiB
C++
Raw Normal View History

2018-12-25 18:42:43 +00:00
#pragma once
2019-01-02 16:04:44 +00:00
#include <Core/Field.h>
2018-12-25 18:42:43 +00:00
#include <Core/Types.h>
2019-01-02 16:04:44 +00:00
#include <Common/FieldVisitors.h>
2019-02-06 08:43:54 +00:00
#include <IO/WriteHelpers.h>
2018-12-25 18:42:43 +00:00
#include <Parsers/ASTExpressionList.h>
#include <Parsers/ASTFunction.h>
2019-01-02 16:04:44 +00:00
#include <Parsers/IAST.h>
2018-12-25 18:42:43 +00:00
#include <vector>
namespace DB
{
2019-01-08 11:04:25 +00:00
/** name BY expr TYPE typename(args) GRANULARITY int in create query
2018-12-25 18:42:43 +00:00
*/
2018-12-25 18:45:08 +00:00
class ASTIndexDeclaration : public IAST
2018-12-25 18:42:43 +00:00
{
public:
2018-12-25 18:45:08 +00:00
String name;
IAST * expr;
ASTFunction * type;
2019-02-06 08:43:54 +00:00
UInt64 granularity;
2018-12-25 18:42:43 +00:00
/** Get the text that identifies this element. */
String getID(char) const override { return "Index"; }
2019-01-26 06:26:49 +00:00
ASTPtr clone() const override
{
2019-01-08 09:38:46 +00:00
auto res = std::make_shared<ASTIndexDeclaration>();
res->name = name;
res->granularity = granularity;
2018-12-25 18:45:08 +00:00
if (expr)
res->set(res->expr, expr->clone());
if (type)
res->set(res->type, type->clone());
return res;
}
2018-12-25 18:42:43 +00:00
void formatImpl(const FormatSettings & s, FormatState &state, FormatStateStacked frame) const override
{
2019-01-20 11:34:13 +00:00
frame.need_parens = false;
std::string indent_str = s.one_line ? "" : std::string(4 * frame.indent, ' ');
2019-01-20 15:02:19 +00:00
s.ostr << s.nl_or_ws << indent_str;
s.ostr << backQuoteIfNeed(name);
s.ostr << " ";
2018-12-25 18:45:08 +00:00
expr->formatImpl(s, state, frame);
s.ostr << (s.hilite ? hilite_keyword : "") << " TYPE " << (s.hilite ? hilite_none : "");
type->formatImpl(s, state, frame);
2019-01-02 16:04:44 +00:00
s.ostr << (s.hilite ? hilite_keyword : "") << " GRANULARITY " << (s.hilite ? hilite_none : "");
2019-02-06 08:43:54 +00:00
s.ostr << toString(granularity);
2018-12-25 18:42:43 +00:00
}
};
}