2011-08-28 02:22:23 +00:00
|
|
|
#pragma once
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2019-01-14 18:15:04 +00:00
|
|
|
#include <optional>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#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
|
|
|
|
{
|
|
|
|
|
2019-01-25 15:42:24 +00:00
|
|
|
struct IdentifierSemantic;
|
|
|
|
struct IdentifierSemanticImpl;
|
2020-03-12 18:04:29 +00:00
|
|
|
struct StorageID;
|
2019-01-25 15:42:24 +00:00
|
|
|
|
|
|
|
|
2019-01-14 18:15:04 +00:00
|
|
|
/// 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
|
|
|
|
2020-10-24 18:46:10 +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. */
|
2020-10-24 18:46:10 +00:00
|
|
|
String getID(char delim) const override { return "Identifier" + (delim + name()); }
|
2011-12-12 06:15:34 +00:00
|
|
|
|
2019-02-13 15:18:02 +00:00
|
|
|
ASTPtr clone() const override;
|
2013-08-13 08:54:28 +00:00
|
|
|
|
2020-10-24 18:46:10 +00:00
|
|
|
void collectIdentifierNames(IdentifierNameSet & set) const override { set.insert(name()); }
|
2015-08-05 21:38:31 +00:00
|
|
|
|
2020-10-24 18:46:10 +00:00
|
|
|
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-01-25 15:42:24 +00:00
|
|
|
|
2019-02-12 15:08:21 +00:00
|
|
|
void setShortName(const String & new_name);
|
2020-04-14 14:43:09 +00:00
|
|
|
|
2020-10-24 18:46:10 +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;
|
2019-01-25 15:42:24 +00:00
|
|
|
|
2020-10-24 18:46:10 +00:00
|
|
|
void restoreTable(); // TODO(ilezhankin): get rid of this
|
2019-02-07 19:18:40 +00:00
|
|
|
|
2020-10-24 18:46:10 +00:00
|
|
|
// 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-03-26 09:07:10 +00:00
|
|
|
|
2020-08-20 02:01:40 +00:00
|
|
|
void updateTreeHashImpl(SipHash & hash_state) const override;
|
|
|
|
|
2015-08-05 21:38:31 +00:00
|
|
|
protected:
|
2020-10-24 18:46:10 +00:00
|
|
|
String full_name;
|
|
|
|
std::vector<String> name_parts;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
|
2018-06-27 16:34:11 +00:00
|
|
|
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
|
|
|
|
|
2019-01-25 15:42:24 +00:00
|
|
|
std::shared_ptr<IdentifierSemanticImpl> semantic; /// pimpl
|
2019-01-14 18:15:04 +00:00
|
|
|
|
2019-01-25 15:42:24 +00:00
|
|
|
friend struct IdentifierSemantic;
|
2020-03-12 18:04:29 +00:00
|
|
|
friend ASTPtr createTableIdentifier(const StorageID & table_id);
|
2019-01-25 15:42:24 +00:00
|
|
|
friend void setIdentifierSpecial(ASTPtr & ast);
|
2020-04-07 14:05:51 +00:00
|
|
|
friend StorageID getTableIdentifier(const ASTPtr & ast);
|
2020-10-24 18:46:10 +00:00
|
|
|
|
|
|
|
void resetFullName();
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
2019-01-14 18:15:04 +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);
|
2019-01-25 15:42:24 +00:00
|
|
|
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); }
|
2019-01-14 18:15:04 +00:00
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
}
|