ClickHouse/dbms/src/Parsers/ASTSetQuery.h

52 lines
1.3 KiB
C++
Raw Normal View History

2012-08-02 19:04:26 +00:00
#pragma once
#include <Core/Field.h>
#include <Core/FieldVisitors.h>
#include <Parsers/IAST.h>
2012-08-02 19:04:26 +00:00
namespace DB
{
/** SET запрос
*/
class ASTSetQuery : public IAST
{
public:
struct Change
{
String name;
Field value;
};
2012-08-02 19:04:26 +00:00
using Changes = std::vector<Change>;
Changes changes;
2012-08-02 19:04:26 +00:00
bool global; /// Если запрос SET GLOBAL.
2012-08-02 19:04:26 +00:00
ASTSetQuery() = default;
ASTSetQuery(const StringRange range_) : IAST(range_) {}
/** Получить текст, который идентифицирует этот элемент. */
String getID() const override { return "Set"; };
2012-08-02 19:04:26 +00:00
ASTPtr clone() const override { return std::make_shared<ASTSetQuery>(*this); }
protected:
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SET " << (global ? "GLOBAL " : "") << (settings.hilite ? hilite_none : "");
for (ASTSetQuery::Changes::const_iterator it = changes.begin(); it != changes.end(); ++it)
{
if (it != changes.begin())
settings.ostr << ", ";
settings.ostr << it->name << " = " << applyVisitor(FieldVisitorToString(), it->value);
}
}
2012-08-02 19:04:26 +00:00
};
}