2018-08-22 06:42:37 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-09-28 15:01:13 +00:00
|
|
|
#include <memory>
|
2018-11-01 11:32:44 +00:00
|
|
|
#include <optional>
|
2018-09-28 15:01:13 +00:00
|
|
|
#include <Core/Types.h>
|
2018-11-10 20:09:07 +00:00
|
|
|
#include <Parsers/ASTSelectQuery.h>
|
2018-08-22 06:42:37 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-09-27 19:25:18 +00:00
|
|
|
class IAST;
|
|
|
|
using ASTPtr = std::shared_ptr<IAST>;
|
|
|
|
|
2018-10-26 15:13:02 +00:00
|
|
|
class ASTSelectQuery;
|
2018-09-27 19:25:18 +00:00
|
|
|
class ASTIdentifier;
|
|
|
|
struct ASTTableExpression;
|
|
|
|
|
|
|
|
|
2018-10-30 16:31:21 +00:00
|
|
|
/// Extracts database name (and/or alias) from table expression or identifier
|
2018-08-22 06:42:37 +00:00
|
|
|
struct DatabaseAndTableWithAlias
|
|
|
|
{
|
|
|
|
String database;
|
|
|
|
String table;
|
|
|
|
String alias;
|
|
|
|
|
2019-01-10 18:58:55 +00:00
|
|
|
DatabaseAndTableWithAlias() = default;
|
2019-01-14 18:15:04 +00:00
|
|
|
DatabaseAndTableWithAlias(const ASTPtr & identifier_node, const String & current_database = "");
|
2018-10-30 16:31:21 +00:00
|
|
|
DatabaseAndTableWithAlias(const ASTIdentifier & identifier, const String & current_database = "");
|
|
|
|
DatabaseAndTableWithAlias(const ASTTableExpression & table_expression, const String & current_database);
|
|
|
|
|
2018-08-22 06:42:37 +00:00
|
|
|
/// "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;
|
|
|
|
};
|
|
|
|
|
|
|
|
void stripIdentifier(DB::ASTPtr & ast, size_t num_qualifiers_to_strip);
|
|
|
|
|
|
|
|
size_t getNumComponentsToStripInOrderToTranslateQualifiedName(const ASTIdentifier & identifier,
|
|
|
|
const DatabaseAndTableWithAlias & names);
|
|
|
|
|
2018-10-30 16:31:21 +00:00
|
|
|
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);
|
2018-10-26 15:13:02 +00:00
|
|
|
|
2018-10-30 16:31:21 +00:00
|
|
|
std::vector<const ASTTableExpression *> getSelectTablesExpression(const ASTSelectQuery & select_query);
|
2018-10-29 19:04:28 +00:00
|
|
|
ASTPtr getTableFunctionOrSubquery(const ASTSelectQuery & select, size_t table_number);
|
|
|
|
|
2018-09-27 19:25:18 +00:00
|
|
|
}
|