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>
|
2019-01-16 17:26:14 +00:00
|
|
|
|
2018-09-28 15:01:13 +00:00
|
|
|
#include <Core/Types.h>
|
2019-02-07 19:18:40 +00:00
|
|
|
#include <Core/Names.h>
|
2019-01-16 17:26:14 +00:00
|
|
|
|
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;
|
2019-02-07 19:18:40 +00:00
|
|
|
class Context;
|
2018-09-27 19:25:18 +00:00
|
|
|
|
|
|
|
|
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 = "");
|
2019-02-01 16:36:40 +00:00
|
|
|
DatabaseAndTableWithAlias(const ASTTableExpression & table_expression, const String & current_database = "");
|
2018-10-30 16:31:21 +00:00
|
|
|
|
2019-01-25 15:42:24 +00:00
|
|
|
/// "alias." or "table." if alias is empty
|
2018-08-22 06:42:37 +00:00
|
|
|
String getQualifiedNamePrefix() 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);
|
2018-08-22 06:42:37 +00:00
|
|
|
};
|
|
|
|
|
2019-02-07 19:18:40 +00:00
|
|
|
using TableWithColumnNames = std::pair<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
|
|
|
|
2019-02-07 19:18:40 +00:00
|
|
|
std::vector<TableWithColumnNames> getDatabaseAndTablesWithColumnNames(const ASTSelectQuery & select_query, const Context & context);
|
|
|
|
|
2018-10-30 16:31:21 +00:00
|
|
|
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);
|
2018-10-29 19:04:28 +00:00
|
|
|
|
2018-09-27 19:25:18 +00:00
|
|
|
}
|