#include #include #include #include namespace DB { void ASTIdentifier::formatImplWithoutAlias(const FormatSettings & settings, FormatState &, FormatStateStacked) const { auto format_element = [&](const String & elem_name) { settings.ostr << (settings.hilite ? hilite_identifier : ""); settings.writeIdentifier(elem_name); settings.ostr << (settings.hilite ? hilite_none : ""); }; /// A simple or compound identifier? if (children.size() > 1) { for (size_t i = 0, size = children.size(); i < size; ++i) { if (i != 0) settings.ostr << '.'; format_element(static_cast(*children[i].get()).name); } } else { format_element(name); } } void ASTIdentifier::appendColumnNameImpl(WriteBuffer & ostr) const { writeString(name, ostr); } ASTPtr createTableIdentifier(const String & database_name, const String & table_name) { if (database_name.empty()) return ASTIdentifier::createSpecial(table_name); ASTPtr database = ASTIdentifier::createSpecial(database_name); ASTPtr table = ASTIdentifier::createSpecial(table_name); ASTPtr database_and_table = ASTIdentifier::createSpecial(database_name + "." + table_name); database_and_table->children = {database, table}; return database_and_table; } bool isIdentifier(const IAST * const ast) { if (ast) return typeid_cast(ast); return false; } std::optional getIdentifierName(const IAST * const ast) { if (ast) if (auto node = typeid_cast(ast)) return node->name; return {}; } bool getIdentifierName(const ASTPtr & ast, String & name) { if (ast) if (auto node = typeid_cast(ast.get())) { name = node->name; return true; } return false; } std::optional getColumnIdentifierName(const ASTIdentifier & node) { if (!node.special) return node.name; return {}; } std::optional getColumnIdentifierName(const ASTPtr & ast) { if (ast) if (auto id = typeid_cast(ast.get())) if (!id->special) return id->name; return {}; } std::optional getTableIdentifierName(const ASTIdentifier & node) { if (node.special) return node.name; return {}; } std::optional getTableIdentifierName(const ASTPtr & ast) { if (ast) if (auto id = typeid_cast(ast.get())) if (id->special) return id->name; return {}; } void setIdentifierSpecial(ASTPtr & ast) { if (ast) if (ASTIdentifier * id = typeid_cast(ast.get())) id->setSpecial(); } }