ClickHouse/dbms/src/Parsers/ASTIdentifier.h

83 lines
2.4 KiB
C++
Raw Normal View History

2011-08-28 02:22:23 +00:00
#pragma once
2010-06-24 19:12:10 +00:00
#include <optional>
#include <Parsers/ASTWithAlias.h>
2010-06-24 19:12:10 +00:00
namespace DB
{
struct IdentifierSemantic;
struct IdentifierSemanticImpl;
struct DatabaseAndTableWithAlias;
/// Identifier (column, table or alias)
2014-07-03 22:39:13 +00:00
class ASTIdentifier : public ASTWithAlias
2010-06-24 19:12:10 +00:00
{
2018-09-20 13:13:33 +00:00
public:
2019-01-17 17:01:48 +00:00
/// The composite identifier will have a concatenated name (of the form a.b.c),
/// and individual components will be available inside the name_parts.
String name;
2011-08-28 02:22:23 +00:00
ASTIdentifier(const String & name_, std::vector<String> && name_parts_ = {});
ASTIdentifier(std::vector<String> && name_parts_);
2011-09-25 03:37:09 +00:00
2017-05-27 17:27:16 +00:00
/** Get the text that identifies this element. */
String getID(char delim) const override { return "Identifier" + (delim + name); }
2011-12-12 06:15:34 +00:00
ASTPtr clone() const override;
void collectIdentifierNames(IdentifierNameSet & set) const override
{
set.insert(name);
}
bool compound() const { return !name_parts.empty(); }
bool isShort() const { return name_parts.empty() || name == name_parts.back(); }
2019-02-12 15:08:21 +00:00
void setShortName(const String & new_name);
void restoreCompoundName();
const String & shortName() const
{
if (!name_parts.empty())
return name_parts.back();
return name;
}
protected:
void formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
void appendColumnNameImpl(WriteBuffer & ostr) const override;
2018-09-20 13:13:33 +00:00
private:
2019-01-17 17:01:48 +00:00
using ASTWithAlias::children; /// ASTIdentifier is child free
std::vector<String> name_parts;
std::shared_ptr<IdentifierSemanticImpl> semantic; /// pimpl
static std::shared_ptr<ASTIdentifier> createSpecial(const String & name, std::vector<String> && name_parts = {});
friend struct IdentifierSemantic;
2019-01-15 12:28:17 +00:00
friend ASTPtr createTableIdentifier(const String & database_name, const String & table_name);
friend void setIdentifierSpecial(ASTPtr & ast);
2010-06-24 19:12:10 +00:00
};
/// ASTIdentifier Helpers: hide casts and semantic.
2019-01-15 12:28:17 +00:00
ASTPtr createTableIdentifier(const String & database_name, const String & table_name);
void setIdentifierSpecial(ASTPtr & ast);
2019-01-15 12:28:17 +00:00
2019-08-08 20:02:30 +00:00
String getIdentifierName(const IAST * ast);
std::optional<String> tryGetIdentifierName(const IAST * ast);
inline String getIdentifierName(const ASTPtr & ast) { return getIdentifierName(ast.get()); }
inline std::optional<String> tryGetIdentifierName(const ASTPtr & ast) { return tryGetIdentifierName(ast.get()); }
bool tryGetIdentifierNameInto(const ASTPtr & ast, String & name);
2010-06-24 19:12:10 +00:00
}