ClickHouse/src/Parsers/ASTIdentifier.h

88 lines
3.0 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>
2020-03-12 18:04:29 +00:00
#include <Core/UUID.h>
2010-06-24 19:12:10 +00:00
namespace DB
{
struct IdentifierSemantic;
struct IdentifierSemanticImpl;
2020-03-12 18:04:29 +00:00
struct StorageID;
/// 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:
2020-03-12 18:04:29 +00:00
UUID uuid = UUIDHelpers::Nil;
2011-08-28 02:22:23 +00:00
explicit ASTIdentifier(const String & short_name);
explicit ASTIdentifier(std::vector<String> && name_parts, bool special = false);
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.size() > 1; }
bool isShort() const { return name_parts.size() == 1; }
bool supposedToBeCompound() const; // TODO(ilezhankin): get rid of this
2019-02-12 15:08:21 +00:00
void setShortName(const String & new_name);
2020-04-14 14:43:09 +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.
const String & shortName() const { return name_parts.back(); }
const String & name() const;
void restoreTable(); // TODO(ilezhankin): get rid of this
// FIXME: used only when it's needed to rewrite distributed table name to real remote table name.
void resetTable(const String & database_name, const String & table_name); // TODO(ilezhankin): get rid of this
2020-08-20 02:01:40 +00:00
void updateTreeHashImpl(SipHash & hash_state) const override;
protected:
String full_name;
std::vector<String> name_parts;
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::shared_ptr<IdentifierSemanticImpl> semantic; /// pimpl
friend struct IdentifierSemantic;
2020-03-12 18:04:29 +00:00
friend ASTPtr createTableIdentifier(const StorageID & table_id);
friend void setIdentifierSpecial(ASTPtr & ast);
2020-04-07 14:05:51 +00:00
friend StorageID getTableIdentifier(const ASTPtr & ast);
void resetFullName();
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);
2020-03-12 18:04:29 +00:00
ASTPtr createTableIdentifier(const StorageID & table_id);
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);
2019-08-08 20:26:42 +00:00
bool tryGetIdentifierNameInto(const IAST * ast, String & name);
2020-04-07 14:05:51 +00:00
StorageID getTableIdentifier(const ASTPtr & ast);
2019-08-08 20:02:30 +00:00
inline String getIdentifierName(const ASTPtr & ast) { return getIdentifierName(ast.get()); }
inline std::optional<String> tryGetIdentifierName(const ASTPtr & ast) { return tryGetIdentifierName(ast.get()); }
2019-08-08 20:26:42 +00:00
inline bool tryGetIdentifierNameInto(const ASTPtr & ast, String & name) { return tryGetIdentifierNameInto(ast.get(), name); }
2010-06-24 19:12:10 +00:00
}