2011-08-28 02:22:23 +00:00
|
|
|
#pragma once
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2011-08-09 19:19:00 +00:00
|
|
|
#include <DB/DataTypes/IDataType.h>
|
2014-07-03 22:39:13 +00:00
|
|
|
#include <DB/Parsers/ASTWithAlias.h>
|
2015-08-05 21:38:31 +00:00
|
|
|
#include <DB/IO/WriteBufferFromOStream.h>
|
2010-06-24 19:12:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Идентификатор (столбца или алиас, или именованый элемент кортежа)
|
|
|
|
*/
|
2014-07-03 22:39:13 +00:00
|
|
|
class ASTIdentifier : public ASTWithAlias
|
2010-06-24 19:12:10 +00:00
|
|
|
{
|
|
|
|
public:
|
2011-08-28 02:22:23 +00:00
|
|
|
enum Kind
|
|
|
|
{
|
|
|
|
Column,
|
|
|
|
Database,
|
|
|
|
Table,
|
2011-10-30 05:19:41 +00:00
|
|
|
Format,
|
2011-08-28 02:22:23 +00:00
|
|
|
};
|
2014-07-03 22:39:13 +00:00
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
/// имя
|
|
|
|
String name;
|
2011-08-28 02:22:23 +00:00
|
|
|
|
|
|
|
/// чего идентифицирует этот идентификатор
|
|
|
|
Kind kind;
|
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
ASTIdentifier() = default;
|
|
|
|
ASTIdentifier(const StringRange range_, const String & name_, const Kind kind_ = Column)
|
|
|
|
: ASTWithAlias(range_), name(name_), kind(kind_) {}
|
2011-09-25 03:37:09 +00:00
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
String getColumnName() const override { return name; }
|
2011-11-06 04:21:09 +00:00
|
|
|
|
2011-08-09 19:19:00 +00:00
|
|
|
/** Получить текст, который идентифицирует этот элемент. */
|
2014-12-17 15:26:24 +00:00
|
|
|
String getID() const override { return "Identifier_" + name; }
|
2011-12-12 06:15:34 +00:00
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
ASTPtr clone() const override { return new ASTIdentifier(*this); }
|
2013-08-13 08:54:28 +00:00
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
void collectIdentifierNames(IdentifierNameSet & set) const override
|
2013-08-13 08:54:28 +00:00
|
|
|
{
|
|
|
|
set.insert(name);
|
|
|
|
}
|
2015-08-05 21:38:31 +00:00
|
|
|
|
|
|
|
protected:
|
2015-08-06 23:46:15 +00:00
|
|
|
void formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
|
2015-08-05 21:38:31 +00:00
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_identifier : "");
|
|
|
|
|
|
|
|
WriteBufferFromOStream wb(settings.ostr, 32);
|
|
|
|
writeProbablyBackQuotedString(name, wb);
|
|
|
|
wb.next();
|
|
|
|
|
|
|
|
settings.ostr << (settings.hilite ? hilite_none : "");
|
|
|
|
}
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|