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:
|
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.
|
2017-04-01 07:20:54 +00:00
|
|
|
String name;
|
2020-03-12 18:04:29 +00:00
|
|
|
UUID uuid = UUIDHelpers::Nil;
|
2011-08-28 02:22:23 +00:00
|
|
|
|
2019-01-25 15:42:24 +00:00
|
|
|
ASTIdentifier(const String & name_, std::vector<String> && name_parts_ = {});
|
2019-03-04 19:40:58 +00:00
|
|
|
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. */
|
2018-12-07 12:34:40 +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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void collectIdentifierNames(IdentifierNameSet & set) const override
|
|
|
|
{
|
|
|
|
set.insert(name);
|
|
|
|
}
|
2015-08-05 21:38:31 +00:00
|
|
|
|
2019-01-25 15:42:24 +00:00
|
|
|
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);
|
2019-07-26 17:43:42 +00:00
|
|
|
void restoreCompoundName();
|
2019-01-25 15:42:24 +00:00
|
|
|
|
2019-02-07 19:18:40 +00:00
|
|
|
const String & shortName() const
|
|
|
|
{
|
|
|
|
if (!name_parts.empty())
|
|
|
|
return name_parts.back();
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2020-03-26 09:07:10 +00:00
|
|
|
void resetTable(const String & database_name, const String & table_name);
|
|
|
|
|
2015-08-05 21:38:31 +00:00
|
|
|
protected:
|
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::vector<String> name_parts;
|
|
|
|
std::shared_ptr<IdentifierSemanticImpl> semantic; /// pimpl
|
2019-01-14 18:15:04 +00:00
|
|
|
|
2019-01-25 15:42:24 +00:00
|
|
|
static std::shared_ptr<ASTIdentifier> createSpecial(const String & name, std::vector<String> && name_parts = {});
|
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);
|
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);
|
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
|
|
|
}
|