1#pragma once
2
3#include <Core/Field.h>
4#include <Common/FieldVisitors.h>
5#include <Parsers/ASTWithAlias.h>
6#include <Parsers/TokenIterator.h>
7#include <optional>
8
9
10namespace DB
11{
12
13/** Literal (atomic) - number, string, NULL
14 */
15class ASTLiteral : public ASTWithAlias
16{
17public:
18 Field value;
19
20 /// For ConstantExpressionTemplate
21 std::optional<TokenIterator> begin;
22 std::optional<TokenIterator> end;
23
24 ASTLiteral(const Field & value_) : value(value_) {}
25
26 /** Get the text that identifies this element. */
27 String getID(char delim) const override { return "Literal" + (delim + applyVisitor(FieldVisitorDump(), value)); }
28
29 ASTPtr clone() const override { return std::make_shared<ASTLiteral>(*this); }
30
31 void updateTreeHashImpl(SipHash & hash_state) const override;
32
33protected:
34 void formatImplWithoutAlias(const FormatSettings & settings, FormatState &, FormatStateStacked) const override
35 {
36 settings.ostr << applyVisitor(FieldVisitorToString(), value);
37 }
38
39 void appendColumnNameImpl(WriteBuffer & ostr) const override;
40};
41
42}
43