ClickHouse/src/Parsers/ASTIdentifier.h

91 lines
2.9 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:
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;
2020-03-12 18:04:29 +00:00
UUID uuid = UUIDHelpers::Nil;
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);
2020-04-14 14:43:09 +00:00
/// Restore name field from name_parts in case it was cropped by analyzer but we need a full form for future (re)analyze.
void restoreCompoundName();
const String & shortName() const
{
if (!name_parts.empty())
return name_parts.back();
return name;
}
void resetTable(const String & database_name, const String & table_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;
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);
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
}