2019-01-25 15:42:24 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Parsers/ASTIdentifier.h>
|
|
|
|
#include <Interpreters/DatabaseAndTableWithAlias.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
struct IdentifierSemanticImpl
|
|
|
|
{
|
2019-02-13 15:18:02 +00:00
|
|
|
bool special = false; /// for now it's 'not a column': tables, subselects and some special stuff like FORMAT
|
|
|
|
bool need_long_name = false;/// if column presents in multiple tables we need qualified names
|
|
|
|
bool can_be_alias = true; /// if it's a cropped name it could not be an alias
|
|
|
|
size_t membership = 0; /// table position in join (starting from 1) detected by qualifier or 0 if not detected.
|
2019-01-25 15:42:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Static calss to manipulate IdentifierSemanticImpl via ASTIdentifier
|
|
|
|
struct IdentifierSemantic
|
|
|
|
{
|
|
|
|
/// @returns name for column identifiers
|
|
|
|
static std::optional<String> getColumnName(const ASTIdentifier & node);
|
|
|
|
static std::optional<String> getColumnName(const ASTPtr & ast);
|
|
|
|
|
|
|
|
/// @returns name for 'not a column' identifiers
|
|
|
|
static std::optional<String> getTableName(const ASTIdentifier & node);
|
|
|
|
static std::optional<String> getTableName(const ASTPtr & ast);
|
|
|
|
static std::pair<String, String> extractDatabaseAndTable(const ASTIdentifier & identifier);
|
|
|
|
|
|
|
|
static size_t canReferColumnToTable(const ASTIdentifier & identifier, const DatabaseAndTableWithAlias & db_and_table);
|
2019-02-08 15:37:43 +00:00
|
|
|
static String columnNormalName(const ASTIdentifier & identifier, const DatabaseAndTableWithAlias & db_and_table);
|
2019-02-20 12:12:36 +00:00
|
|
|
static String columnLongName(const ASTIdentifier & identifier, const DatabaseAndTableWithAlias & db_and_table);
|
2019-02-07 19:18:40 +00:00
|
|
|
static void setColumnNormalName(ASTIdentifier & identifier, const DatabaseAndTableWithAlias & db_and_table);
|
2019-02-20 12:12:36 +00:00
|
|
|
static void setColumnLongName(ASTIdentifier & identifier, const DatabaseAndTableWithAlias & db_and_table);
|
2019-02-07 19:18:40 +00:00
|
|
|
static void setNeedLongName(ASTIdentifier & identifier, bool); /// if set setColumnNormalName makes qualified name
|
2019-02-11 19:14:57 +00:00
|
|
|
static bool canBeAlias(const ASTIdentifier & identifier);
|
2019-02-13 15:18:02 +00:00
|
|
|
static void setMembership(ASTIdentifier & identifier, size_t table_no);
|
|
|
|
static size_t getMembership(const ASTIdentifier & identifier);
|
2019-01-25 15:42:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static bool doesIdentifierBelongTo(const ASTIdentifier & identifier, const String & database, const String & table);
|
|
|
|
static bool doesIdentifierBelongTo(const ASTIdentifier & identifier, const String & table);
|
2019-02-07 19:18:40 +00:00
|
|
|
static void setColumnShortName(ASTIdentifier & identifier, size_t match);
|
2019-01-25 15:42:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|