ClickHouse/dbms/src/Parsers/ASTSetQuery.h

49 lines
1.1 KiB
C++
Raw Normal View History

2012-08-02 19:04:26 +00:00
#pragma once
#include <Core/Field.h>
#include <Common/FieldVisitors.h>
#include <Parsers/IAST.h>
2012-08-02 19:04:26 +00:00
namespace DB
{
2017-05-27 17:27:16 +00:00
/** SET query
2012-08-02 19:04:26 +00:00
*/
class ASTSetQuery : public IAST
{
public:
bool is_standalone = true; /// If false, this AST is a part of another query, such as SELECT.
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
2017-05-27 17:27:16 +00:00
/** Get the text that identifies this element. */
String getID() const override { return "Set"; }
2012-08-02 19:04:26 +00:00
ASTPtr clone() const override { return std::make_shared<ASTSetQuery>(*this); }
2017-12-01 18:36:55 +00:00
void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override
{
if (is_standalone)
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SET " << (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
};
}