ClickHouse/dbms/src/Interpreters/DatabaseAndTableWithAlias.h

54 lines
1.8 KiB
C++
Raw Normal View History

#pragma once
2018-09-28 15:01:13 +00:00
#include <memory>
2018-11-01 11:32:44 +00:00
#include <optional>
2019-01-16 17:26:14 +00:00
2018-09-28 15:01:13 +00:00
#include <Core/Types.h>
2019-01-16 17:26:14 +00:00
namespace DB
{
class IAST;
using ASTPtr = std::shared_ptr<IAST>;
class ASTSelectQuery;
class ASTIdentifier;
struct ASTTableExpression;
/// Extracts database name (and/or alias) from table expression or identifier
struct DatabaseAndTableWithAlias
{
String database;
String table;
String alias;
2019-01-10 18:58:55 +00:00
DatabaseAndTableWithAlias() = default;
DatabaseAndTableWithAlias(const ASTPtr & identifier_node, const String & current_database = "");
DatabaseAndTableWithAlias(const ASTIdentifier & identifier, const String & current_database = "");
DatabaseAndTableWithAlias(const ASTTableExpression & table_expression, const String & current_database);
/// "alias." or "database.table." if alias is empty
String getQualifiedNamePrefix() const;
/// If ast is ASTIdentifier, prepend getQualifiedNamePrefix() to it's name.
void makeQualifiedName(const ASTPtr & ast) const;
2019-01-16 12:08:43 +00:00
/// Check if it satisfies another db_table name. @note opterion is not symmetric.
bool satisfies(const DatabaseAndTableWithAlias & table, bool table_may_be_an_alias);
};
void stripIdentifier(DB::ASTPtr & ast, size_t num_qualifiers_to_strip);
size_t getNumComponentsToStripInOrderToTranslateQualifiedName(const ASTIdentifier & identifier,
const DatabaseAndTableWithAlias & names);
std::vector<DatabaseAndTableWithAlias> getDatabaseAndTables(const ASTSelectQuery & select_query, const String & current_database);
2018-11-01 11:32:44 +00:00
std::optional<DatabaseAndTableWithAlias> getDatabaseAndTable(const ASTSelectQuery & select, size_t table_number);
std::vector<const ASTTableExpression *> getSelectTablesExpression(const ASTSelectQuery & select_query);
2019-01-15 18:29:54 +00:00
ASTPtr extractTableExpression(const ASTSelectQuery & select, size_t table_number);
}