mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
dbms: support ALIAS in table declaration
This commit is contained in:
parent
f7ce30aa9d
commit
220ce78326
@ -210,9 +210,11 @@ private:
|
||||
*/
|
||||
void collectJoinedColumns(NameSet & joined_columns, NamesAndTypesList & joined_columns_name_type);
|
||||
|
||||
void addStorageAliases();
|
||||
|
||||
/** Создать словарь алиасов.
|
||||
*/
|
||||
void createAliasesDict(ASTPtr & ast, int ignore_levels = 0);
|
||||
void addASTAliases(ASTPtr & ast, int ignore_levels = 0);
|
||||
|
||||
/** Для узлов-звёздочек - раскрыть их в список всех столбцов.
|
||||
* Для узлов-литералов - подставить алиасы.
|
||||
|
@ -27,6 +27,7 @@ public:
|
||||
static ASTPtr formatColumns(const NamesAndTypesList & columns);
|
||||
static ASTPtr formatColumns(
|
||||
NamesAndTypesList columns,
|
||||
const NamesAndTypesList & materialized_columns,
|
||||
const NamesAndTypesList & alias_columns,
|
||||
const ColumnDefaults & column_defaults);
|
||||
|
||||
@ -35,8 +36,8 @@ private:
|
||||
using ColumnsAndDefaults = std::pair<NamesAndTypesList, ColumnDefaults>;
|
||||
ColumnsAndDefaults parseColumns(ASTPtr expression_list);
|
||||
|
||||
/// removes alias columns from the columns list and return them in a separate list
|
||||
static NamesAndTypesList removeAliasColumns(ColumnsAndDefaults & columns_and_defaults);
|
||||
/// removes columns from the columns list and return them in a separate list
|
||||
static NamesAndTypesList removeAndReturnColumns(ColumnsAndDefaults & columns_and_defaults, ColumnDefaultType type);
|
||||
|
||||
ASTPtr query_ptr;
|
||||
Context context;
|
||||
|
@ -87,6 +87,7 @@ private:
|
||||
StoragePtr table = context.getTable(ast.database, ast.table);
|
||||
auto table_lock = table->lockStructure(false);
|
||||
columns = table->getColumnsList();
|
||||
columns.insert(std::end(columns), std::begin(table->materialized_columns), std::end(table->materialized_columns));
|
||||
columns.insert(std::end(columns), std::begin(table->alias_columns), std::end(table->alias_columns));
|
||||
column_defaults = table->column_defaults;
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ public:
|
||||
*/
|
||||
virtual bool hasRealColumn(const String & column_name) const;
|
||||
|
||||
NameAndTypePair getAliasColumn(const String & column_name) const;
|
||||
bool hasAliasColumn(const String & column_name) const;
|
||||
NameAndTypePair getMaterializedColumn(const String & column_name) const;
|
||||
bool hasMaterializedColumn(const String & column_name) const;
|
||||
|
||||
/** Получить описание любого столбца по его имени.
|
||||
*/
|
||||
@ -57,29 +57,36 @@ public:
|
||||
/** Проверить, что все запрошенные имена есть в таблице и заданы корректно.
|
||||
* (список имён не пустой и имена не повторяются)
|
||||
*/
|
||||
void check(const Names & column_names) const;
|
||||
void check(const Names & column_names, bool all_columns = false) const;
|
||||
|
||||
/** Проверить, что все запрошенные имена есть в таблице и имеют правильные типы.
|
||||
*/
|
||||
void check(const NamesAndTypesList & columns) const;
|
||||
void check(const NamesAndTypesList & columns, bool all_columns = false) const;
|
||||
|
||||
/** Проверить, что все имена из пересечения names и columns есть в таблице и имеют одинаковые типы.
|
||||
*/
|
||||
void check(const NamesAndTypesList & columns, const Names & column_names) const;
|
||||
void check(const NamesAndTypesList & columns, const Names & column_names, bool all_columns = false) const;
|
||||
|
||||
/** Проверить, что блок с данными для записи содержит все столбцы таблицы с правильными типами,
|
||||
* содержит только столбцы таблицы, и все столбцы различны.
|
||||
* Если need_all, еще проверяет, что все столбцы таблицы есть в блоке.
|
||||
*/
|
||||
void check(const Block & block, bool need_all = false) const;
|
||||
void check(const Block & block, bool need_all = false, bool all_columns = false) const;
|
||||
|
||||
|
||||
virtual ~ITableDeclaration() = default;
|
||||
|
||||
ITableDeclaration() = default;
|
||||
ITableDeclaration(const NamesAndTypesList & alias_columns, const ColumnDefaults & column_defaults)
|
||||
: alias_columns{alias_columns}, column_defaults{column_defaults}
|
||||
ITableDeclaration(
|
||||
const NamesAndTypesList & materialized_columns,
|
||||
const NamesAndTypesList & alias_columns,
|
||||
const ColumnDefaults & column_defaults)
|
||||
: materialized_columns{materialized_columns},
|
||||
alias_columns{alias_columns},
|
||||
column_defaults{column_defaults}
|
||||
{}
|
||||
|
||||
NamesAndTypesList materialized_columns{};
|
||||
NamesAndTypesList alias_columns{};
|
||||
ColumnDefaults column_defaults{};
|
||||
};
|
||||
|
@ -583,6 +583,7 @@ public:
|
||||
* require_part_metadata - обязательно ли в директории с куском должны быть checksums.txt и columns.txt
|
||||
*/
|
||||
MergeTreeData( const String & full_path_, NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const Context & context_,
|
||||
|
@ -21,6 +21,7 @@ public:
|
||||
const std::string & this_database_,/// Имя БД для этой таблицы.
|
||||
const std::string & name_, /// Имя таблицы.
|
||||
NamesAndTypesListPtr columns_, /// Список столбцов.
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const String & source_database_, /// В какой БД искать таблицы-источники.
|
||||
@ -74,6 +75,7 @@ private:
|
||||
const std::string & this_database_,
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const String & source_database_,
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
const std::string & name_,
|
||||
const std::string & database_name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
Context & context_,
|
||||
@ -98,6 +99,7 @@ private:
|
||||
const std::string & name_,
|
||||
const std::string & database_name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
Context & context_,
|
||||
|
@ -25,6 +25,7 @@ public:
|
||||
static StoragePtr create(
|
||||
const std::string & name_, /// Имя таблицы.
|
||||
NamesAndTypesListPtr columns_, /// Список столбцов.
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const String & remote_database_, /// БД на удалённых серверах.
|
||||
@ -93,6 +94,7 @@ private:
|
||||
StorageDistributed(
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const String & remote_database_,
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
Context & context,
|
||||
ASTPtr & query,
|
||||
NamesAndTypesListPtr columns,
|
||||
const NamesAndTypesList & materialized_columns,
|
||||
const NamesAndTypesList & alias_columns,
|
||||
const ColumnDefaults & column_defaults,
|
||||
bool attach) const;
|
||||
|
@ -143,6 +143,7 @@ public:
|
||||
const std::string & path_,
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
size_t max_compress_block_size_ = DEFAULT_MAX_COMPRESS_BLOCK_SIZE);
|
||||
@ -203,6 +204,7 @@ protected:
|
||||
const std::string & path_,
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
size_t max_compress_block_size_);
|
||||
|
@ -15,6 +15,7 @@ public:
|
||||
Context & context_,
|
||||
ASTPtr & query_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
bool attach_);
|
||||
@ -46,6 +47,7 @@ private:
|
||||
Context & context_,
|
||||
ASTPtr & query_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
bool attach_);
|
||||
|
@ -69,6 +69,7 @@ public:
|
||||
static StoragePtr create(
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_);
|
||||
|
||||
@ -109,6 +110,7 @@ private:
|
||||
StorageMemory(
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_);
|
||||
|
||||
|
@ -28,6 +28,7 @@ public:
|
||||
static StoragePtr create(
|
||||
const std::string & name_, /// Имя таблицы.
|
||||
NamesAndTypesListPtr columns_, /// Список столбцов.
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const String & source_database_, /// В какой БД искать таблицы-источники.
|
||||
@ -78,6 +79,7 @@ private:
|
||||
StorageMerge(
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const String & source_database_,
|
||||
|
@ -29,6 +29,7 @@ public:
|
||||
const String & database_name_,
|
||||
const String & table_name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
Context & context_,
|
||||
@ -163,6 +164,7 @@ private:
|
||||
const String & database_name_,
|
||||
const String & table_name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
Context & context_,
|
||||
|
@ -18,10 +18,11 @@ public:
|
||||
static StoragePtr create(
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_)
|
||||
{
|
||||
return (new StorageNull{name_, columns_, alias_columns_, column_defaults_})->thisPtr();
|
||||
return (new StorageNull{name_, columns_, materialized_columns_, alias_columns_, column_defaults_})->thisPtr();
|
||||
}
|
||||
|
||||
std::string getName() const { return "Null"; }
|
||||
@ -55,9 +56,10 @@ private:
|
||||
StorageNull(
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_)
|
||||
: IStorage{alias_columns_, column_defaults_}, name(name_), columns(columns_) {}
|
||||
: IStorage{materialized_columns_, alias_columns_, column_defaults_}, name(name_), columns(columns_) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ public:
|
||||
bool attach,
|
||||
const String & path_, const String & database_name_, const String & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
Context & context_,
|
||||
@ -321,6 +322,7 @@ private:
|
||||
bool attach,
|
||||
const String & path_, const String & database_name_, const String & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
Context & context_,
|
||||
|
@ -115,6 +115,7 @@ public:
|
||||
const std::string & path_,
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
bool attach,
|
||||
@ -170,6 +171,7 @@ private:
|
||||
const std::string & path_,
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
bool attach,
|
||||
|
@ -16,6 +16,7 @@ public:
|
||||
Context & context_,
|
||||
ASTPtr & query_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_);
|
||||
|
||||
@ -49,6 +50,7 @@ protected:
|
||||
Context & context_,
|
||||
ASTPtr & query_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_);
|
||||
};
|
||||
|
@ -63,8 +63,10 @@ void ExpressionAnalyzer::init()
|
||||
{
|
||||
select_query = typeid_cast<ASTSelectQuery *>(&*ast);
|
||||
|
||||
addStorageAliases();
|
||||
|
||||
/// Создаёт словарь aliases: alias -> ASTPtr
|
||||
createAliasesDict(ast);
|
||||
addASTAliases(ast);
|
||||
|
||||
/// Common subexpression elimination. Rewrite rules.
|
||||
normalizeTree();
|
||||
@ -235,9 +237,19 @@ NamesAndTypesList::iterator ExpressionAnalyzer::findColumn(const String & name,
|
||||
}
|
||||
|
||||
|
||||
void ExpressionAnalyzer::addStorageAliases()
|
||||
{
|
||||
if (!storage)
|
||||
return;
|
||||
|
||||
for (const auto & alias : storage->alias_columns)
|
||||
aliases[alias.name] = storage->column_defaults[alias.name].expression;
|
||||
}
|
||||
|
||||
|
||||
/// ignore_levels - алиасы в скольки верхних уровнях поддерева нужно игнорировать.
|
||||
/// Например, при ignore_levels=1 ast не может быть занесен в словарь, но его дети могут.
|
||||
void ExpressionAnalyzer::createAliasesDict(ASTPtr & ast, int ignore_levels)
|
||||
void ExpressionAnalyzer::addASTAliases(ASTPtr & ast, int ignore_levels)
|
||||
{
|
||||
ASTSelectQuery * select = typeid_cast<ASTSelectQuery *>(&*ast);
|
||||
|
||||
@ -252,7 +264,7 @@ void ExpressionAnalyzer::createAliasesDict(ASTPtr & ast, int ignore_levels)
|
||||
new_ignore_levels = 2;
|
||||
|
||||
if (!typeid_cast<ASTSelectQuery *>(&*child))
|
||||
createAliasesDict(child, new_ignore_levels);
|
||||
addASTAliases(child, new_ignore_levels);
|
||||
}
|
||||
|
||||
if (ignore_levels > 0)
|
||||
@ -1683,18 +1695,34 @@ void ExpressionAnalyzer::collectUsedColumns()
|
||||
++it;
|
||||
}
|
||||
|
||||
/// Возможно, среди неизвестных столбцов есть виртуальные. Удаляем их из списка неизвестных и добавляем
|
||||
/// в columns list, чтобы при дальнейшей обработке запроса они воспринимались как настоящие.
|
||||
for (NameSet::iterator it = unknown_required_columns.begin(); it != unknown_required_columns.end();)
|
||||
for (NamesAndTypesList::iterator it = columns.begin(); it != columns.end();)
|
||||
{
|
||||
if (storage && storage->hasColumn(*it))
|
||||
unknown_required_columns.erase(it->name);
|
||||
|
||||
if (!required.count(it->name))
|
||||
{
|
||||
columns.push_back(storage->getColumn(*it));
|
||||
unknown_required_columns.erase(it++);
|
||||
required.erase(it->name);
|
||||
columns.erase(it++);
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
/// Возможно, среди неизвестных столбцов есть виртуальные. Удаляем их из списка неизвестных и добавляем
|
||||
/// в columns list, чтобы при дальнейшей обработке запроса они воспринимались как настоящие.
|
||||
if (storage)
|
||||
{
|
||||
for (auto it = unknown_required_columns.begin(); it != unknown_required_columns.end();)
|
||||
{
|
||||
if (storage->hasColumn(*it))
|
||||
{
|
||||
columns.push_back(storage->getColumn(*it));
|
||||
unknown_required_columns.erase(it++);
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExpressionAnalyzer::collectJoinedColumns(NameSet & joined_columns, NamesAndTypesList & joined_columns_name_type)
|
||||
|
@ -89,6 +89,7 @@ StoragePtr InterpreterCreateQuery::execute(bool assume_metadata_exists)
|
||||
StoragePtr res;
|
||||
String storage_name;
|
||||
NamesAndTypesListPtr columns = new NamesAndTypesList;
|
||||
NamesAndTypesList materialized_columns{};
|
||||
NamesAndTypesList alias_columns{};
|
||||
ColumnDefaults column_defaults{};
|
||||
|
||||
@ -120,7 +121,8 @@ StoragePtr InterpreterCreateQuery::execute(bool assume_metadata_exists)
|
||||
if (create.columns)
|
||||
{
|
||||
auto && columns_and_defaults = parseColumns(create.columns);
|
||||
alias_columns = removeAliasColumns(columns_and_defaults);
|
||||
materialized_columns = removeAndReturnColumns(columns_and_defaults, ColumnDefaultType::Materialized);
|
||||
alias_columns = removeAndReturnColumns(columns_and_defaults, ColumnDefaultType::Alias);
|
||||
columns = new NamesAndTypesList{std::move(columns_and_defaults.first)};
|
||||
column_defaults = std::move(columns_and_defaults.second);
|
||||
}
|
||||
@ -136,7 +138,7 @@ StoragePtr InterpreterCreateQuery::execute(bool assume_metadata_exists)
|
||||
throw Exception("Incorrect CREATE query: required list of column descriptions or AS section or SELECT.", ErrorCodes::INCORRECT_QUERY);
|
||||
|
||||
/// Даже если в запросе был список столбцов, на всякий случай приведем его к стандартному виду (развернем Nested).
|
||||
ASTPtr new_columns = formatColumns(*columns, alias_columns, column_defaults);
|
||||
ASTPtr new_columns = formatColumns(*columns, materialized_columns, alias_columns, column_defaults);
|
||||
if (create.columns)
|
||||
{
|
||||
auto it = std::find(create.children.begin(), create.children.end(), create.columns);
|
||||
@ -185,8 +187,8 @@ StoragePtr InterpreterCreateQuery::execute(bool assume_metadata_exists)
|
||||
|
||||
res = context.getStorageFactory().get(
|
||||
storage_name, data_path, table_name, database_name, context,
|
||||
context.getGlobalContext(), query_ptr,
|
||||
columns, alias_columns, column_defaults, create.attach);
|
||||
context.getGlobalContext(), query_ptr, columns,
|
||||
materialized_columns, alias_columns, column_defaults, create.attach);
|
||||
|
||||
/// Проверка наличия метаданных таблицы на диске и создание метаданных
|
||||
if (!assume_metadata_exists && !create.is_temporary)
|
||||
@ -342,26 +344,27 @@ InterpreterCreateQuery::ColumnsAndDefaults InterpreterCreateQuery::parseColumns(
|
||||
return { *DataTypeNested::expandNestedColumns(columns), defaults };
|
||||
}
|
||||
|
||||
NamesAndTypesList InterpreterCreateQuery::removeAliasColumns(ColumnsAndDefaults & columns_and_defaults)
|
||||
NamesAndTypesList InterpreterCreateQuery::removeAndReturnColumns(ColumnsAndDefaults & columns_and_defaults,
|
||||
const ColumnDefaultType type)
|
||||
{
|
||||
auto & columns = columns_and_defaults.first;
|
||||
auto & defaults = columns_and_defaults.second;
|
||||
|
||||
NamesAndTypesList alias_columns{};
|
||||
NamesAndTypesList removed{};
|
||||
|
||||
for (auto it = std::begin(columns); it != std::end(columns);)
|
||||
{
|
||||
const auto jt = defaults.find(it->name);
|
||||
if (jt != std::end(defaults) && jt->second.type != ColumnDefaultType::Default)
|
||||
if (jt != std::end(defaults) && jt->second.type == type)
|
||||
{
|
||||
alias_columns.push_back(*it);
|
||||
removed.push_back(*it);
|
||||
it = columns.erase(it);
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
return alias_columns;
|
||||
return removed;
|
||||
}
|
||||
|
||||
ASTPtr InterpreterCreateQuery::formatColumns(const NamesAndTypesList & columns)
|
||||
@ -393,9 +396,11 @@ ASTPtr InterpreterCreateQuery::formatColumns(const NamesAndTypesList & columns)
|
||||
}
|
||||
|
||||
ASTPtr InterpreterCreateQuery::formatColumns(NamesAndTypesList columns,
|
||||
const NamesAndTypesList & materialized_columns,
|
||||
const NamesAndTypesList & alias_columns,
|
||||
const ColumnDefaults & column_defaults)
|
||||
{
|
||||
columns.insert(std::end(columns), std::begin(materialized_columns), std::end(materialized_columns));
|
||||
columns.insert(std::end(columns), std::begin(alias_columns), std::end(alias_columns));
|
||||
|
||||
ASTPtr columns_list_ptr{new ASTExpressionList};
|
||||
|
@ -40,18 +40,18 @@ NameAndTypePair ITableDeclaration::getRealColumn(const String & column_name) con
|
||||
throw Exception("There is no column " + column_name + " in table.", ErrorCodes::NO_SUCH_COLUMN_IN_TABLE);
|
||||
}
|
||||
|
||||
NameAndTypePair ITableDeclaration::getAliasColumn(const String & column_name) const
|
||||
NameAndTypePair ITableDeclaration::getMaterializedColumn(const String & column_name) const
|
||||
{
|
||||
for (auto & column : alias_columns)
|
||||
for (auto & column : materialized_columns)
|
||||
if (column.name == column_name)
|
||||
return column;
|
||||
|
||||
throw Exception("There is no column " + column_name + " in table.", ErrorCodes::NO_SUCH_COLUMN_IN_TABLE);
|
||||
}
|
||||
|
||||
bool ITableDeclaration::hasAliasColumn(const String & column_name) const
|
||||
bool ITableDeclaration::hasMaterializedColumn(const String & column_name) const
|
||||
{
|
||||
for (auto & column : alias_columns)
|
||||
for (auto & column : materialized_columns)
|
||||
if (column.name == column_name)
|
||||
return true;
|
||||
|
||||
@ -60,7 +60,7 @@ bool ITableDeclaration::hasAliasColumn(const String & column_name) const
|
||||
|
||||
bool ITableDeclaration::hasColumn(const String & column_name) const
|
||||
{
|
||||
return hasRealColumn(column_name) || hasAliasColumn(column_name); /// По умолчанию считаем, что виртуальных столбцов в сторадже нет.
|
||||
return hasRealColumn(column_name) || hasMaterializedColumn(column_name); /// По умолчанию считаем, что виртуальных столбцов в сторадже нет.
|
||||
}
|
||||
|
||||
NameAndTypePair ITableDeclaration::getColumn(const String & column_name) const
|
||||
@ -70,16 +70,19 @@ NameAndTypePair ITableDeclaration::getColumn(const String & column_name) const
|
||||
if (it == std::end(column_defaults) || it->second.type == ColumnDefaultType::Default)
|
||||
return getRealColumn(column_name); /// По умолчанию считаем, что виртуальных столбцов в сторадже нет.
|
||||
|
||||
return getAliasColumn(column_name);
|
||||
return getMaterializedColumn(column_name);
|
||||
}
|
||||
|
||||
|
||||
const DataTypePtr ITableDeclaration::getDataTypeByName(const String & column_name) const
|
||||
{
|
||||
const NamesAndTypesList & names_and_types = getColumnsList();
|
||||
for (NamesAndTypesList::const_iterator it = names_and_types.begin(); it != names_and_types.end(); ++it)
|
||||
if (it->name == column_name)
|
||||
return it->type;
|
||||
for (const auto & column : getColumnsList())
|
||||
if (column.name == column_name)
|
||||
return column.type;
|
||||
|
||||
for (const auto & column : materialized_columns)
|
||||
if (column.name == column_name)
|
||||
return column.type;
|
||||
|
||||
throw Exception("There is no column " + column_name + " in table.", ErrorCodes::NO_SUCH_COLUMN_IN_TABLE);
|
||||
}
|
||||
@ -118,20 +121,30 @@ static std::string listOfColumns(const NamesAndTypesList & available_columns)
|
||||
|
||||
typedef google::dense_hash_map<StringRef, const IDataType *, StringRefHash> NamesAndTypesMap;
|
||||
|
||||
static NamesAndTypesMap & getColumnsMapImpl(NamesAndTypesMap & res) { return res; }
|
||||
|
||||
static NamesAndTypesMap getColumnsMap(const NamesAndTypesList & available_columns)
|
||||
template <typename Arg, typename... Args>
|
||||
static NamesAndTypesMap & getColumnsMapImpl(NamesAndTypesMap & res, const Arg & arg, const Args &... args)
|
||||
{
|
||||
static_assert(std::is_same<Arg, NamesAndTypesList>::value, "getColumnsMap requires arguments of type NamesAndTypesList");
|
||||
|
||||
for (const auto & column : arg)
|
||||
res.insert({column.name, column.type.get()});
|
||||
|
||||
return getColumnsMapImpl(res, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
static NamesAndTypesMap getColumnsMap(const Args &... args)
|
||||
{
|
||||
NamesAndTypesMap res;
|
||||
res.set_empty_key(StringRef());
|
||||
|
||||
for (NamesAndTypesList::const_iterator it = available_columns.begin(); it != available_columns.end(); ++it)
|
||||
res.insert(NamesAndTypesMap::value_type(it->name, &*it->type));
|
||||
|
||||
return res;
|
||||
return getColumnsMapImpl(res, args...);
|
||||
}
|
||||
|
||||
|
||||
void ITableDeclaration::check(const Names & column_names) const
|
||||
void ITableDeclaration::check(const Names & column_names, const bool all_columns) const
|
||||
{
|
||||
const NamesAndTypesList & available_columns = getColumnsList();
|
||||
|
||||
@ -139,7 +152,9 @@ void ITableDeclaration::check(const Names & column_names) const
|
||||
throw Exception("Empty list of columns queried. There are columns: " + listOfColumns(available_columns),
|
||||
ErrorCodes::EMPTY_LIST_OF_COLUMNS_QUERIED);
|
||||
|
||||
const NamesAndTypesMap & columns_map = getColumnsMap(available_columns);
|
||||
const auto columns_map = all_columns ?
|
||||
getColumnsMap(available_columns, materialized_columns) :
|
||||
getColumnsMap(available_columns);
|
||||
|
||||
typedef google::dense_hash_set<StringRef, StringRefHash> UniqueStrings;
|
||||
UniqueStrings unique_names;
|
||||
@ -159,10 +174,12 @@ void ITableDeclaration::check(const Names & column_names) const
|
||||
}
|
||||
|
||||
|
||||
void ITableDeclaration::check(const NamesAndTypesList & columns) const
|
||||
void ITableDeclaration::check(const NamesAndTypesList & columns, const bool all_columns) const
|
||||
{
|
||||
const NamesAndTypesList & available_columns = getColumnsList();
|
||||
const NamesAndTypesMap & columns_map = getColumnsMap(available_columns);
|
||||
const auto columns_map = all_columns ?
|
||||
getColumnsMap(available_columns, materialized_columns) :
|
||||
getColumnsMap(available_columns);
|
||||
|
||||
typedef google::dense_hash_set<StringRef, StringRefHash> UniqueStrings;
|
||||
UniqueStrings unique_names;
|
||||
@ -187,10 +204,12 @@ void ITableDeclaration::check(const NamesAndTypesList & columns) const
|
||||
}
|
||||
|
||||
|
||||
void ITableDeclaration::check(const NamesAndTypesList & columns, const Names & column_names) const
|
||||
void ITableDeclaration::check(const NamesAndTypesList & columns, const Names & column_names, const bool all_columns) const
|
||||
{
|
||||
const NamesAndTypesList & available_columns = getColumnsList();
|
||||
const NamesAndTypesMap & available_columns_map = getColumnsMap(available_columns);
|
||||
const auto available_columns_map = all_columns ?
|
||||
getColumnsMap(available_columns, materialized_columns) :
|
||||
getColumnsMap(available_columns);
|
||||
const NamesAndTypesMap & provided_columns_map = getColumnsMap(columns);
|
||||
|
||||
if (column_names.empty())
|
||||
@ -224,10 +243,13 @@ void ITableDeclaration::check(const NamesAndTypesList & columns, const Names & c
|
||||
}
|
||||
|
||||
|
||||
void ITableDeclaration::check(const Block & block, bool need_all) const
|
||||
void ITableDeclaration::check(const Block & block, bool need_all, const bool all_columns) const
|
||||
{
|
||||
const NamesAndTypesList & available_columns = getColumnsList();
|
||||
const NamesAndTypesMap & columns_map = getColumnsMap(available_columns);
|
||||
const auto columns_map = all_columns ?
|
||||
getColumnsMap(available_columns, materialized_columns) :
|
||||
getColumnsMap(available_columns);
|
||||
|
||||
|
||||
typedef std::unordered_set<String> NameSet;
|
||||
NameSet names_in_block;
|
||||
|
@ -21,6 +21,7 @@ namespace DB
|
||||
|
||||
MergeTreeData::MergeTreeData(
|
||||
const String & full_path_, NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const Context & context_,
|
||||
@ -33,7 +34,7 @@ MergeTreeData::MergeTreeData(
|
||||
const String & log_name_,
|
||||
bool require_part_metadata_,
|
||||
BrokenPartCallback broken_part_callback_)
|
||||
: ITableDeclaration{alias_columns_, column_defaults_}, context(context_),
|
||||
: ITableDeclaration{materialized_columns_, alias_columns_, column_defaults_}, context(context_),
|
||||
date_column_name(date_column_name_), sampling_expression(sampling_expression_),
|
||||
index_granularity(index_granularity_),
|
||||
mode(mode_), sign_column(sign_column_),
|
||||
|
@ -30,6 +30,7 @@ StoragePtr StorageChunkMerger::create(
|
||||
const std::string & this_database_,
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const String & source_database_,
|
||||
@ -39,7 +40,7 @@ StoragePtr StorageChunkMerger::create(
|
||||
Context & context_)
|
||||
{
|
||||
return (new StorageChunkMerger{
|
||||
this_database_, name_, columns_, alias_columns_, column_defaults_,
|
||||
this_database_, name_, columns_, materialized_columns_, alias_columns_, column_defaults_,
|
||||
source_database_, table_name_regexp_, destination_name_prefix_,
|
||||
chunks_to_merge_, context_
|
||||
})->thisPtr();
|
||||
@ -227,6 +228,7 @@ StorageChunkMerger::StorageChunkMerger(
|
||||
const std::string & this_database_,
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const String & source_database_,
|
||||
@ -234,7 +236,7 @@ StorageChunkMerger::StorageChunkMerger(
|
||||
const std::string & destination_name_prefix_,
|
||||
size_t chunks_to_merge_,
|
||||
Context & context_)
|
||||
: IStorage{alias_columns_, column_defaults_},
|
||||
: IStorage{materialized_columns_, alias_columns_, column_defaults_},
|
||||
this_database(this_database_), name(name_), columns(columns_), source_database(source_database_),
|
||||
table_name_regexp(table_name_regexp_), destination_name_prefix(destination_name_prefix_), chunks_to_merge(chunks_to_merge_),
|
||||
context(context_), settings(context.getSettings()),
|
||||
|
@ -16,14 +16,15 @@ StoragePtr StorageChunks::create(
|
||||
const std::string & name_,
|
||||
const std::string & database_name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
Context & context_,
|
||||
bool attach)
|
||||
{
|
||||
return (new StorageChunks{
|
||||
path_, name_, database_name_,
|
||||
columns_, alias_columns_, column_defaults_,
|
||||
path_, name_, database_name_, columns_,
|
||||
materialized_columns_, alias_columns_, column_defaults_,
|
||||
context_, attach
|
||||
})->thisPtr();
|
||||
}
|
||||
@ -136,12 +137,15 @@ StorageChunks::StorageChunks(
|
||||
const std::string & name_,
|
||||
const std::string & database_name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
Context & context_,
|
||||
bool attach)
|
||||
:
|
||||
StorageLog(path_, name_, columns_, alias_columns_, column_defaults_, context_.getSettings().max_compress_block_size),
|
||||
StorageLog(path_, name_, columns_,
|
||||
materialized_columns_, alias_columns_, column_defaults_,
|
||||
context_.getSettings().max_compress_block_size),
|
||||
database_name(database_name_),
|
||||
reference_counter(path_ + escapeForFileName(name_) + "/refcount.txt"),
|
||||
context(context_),
|
||||
@ -179,7 +183,7 @@ NameAndTypePair StorageChunks::getColumn(const String &column_name) const
|
||||
bool StorageChunks::hasColumn(const String &column_name) const
|
||||
{
|
||||
if (column_name == _table_column_name) return true;
|
||||
return hasRealColumn(column_name);
|
||||
return IStorage::hasColumn(column_name);
|
||||
}
|
||||
|
||||
std::pair<String, size_t> StorageChunks::getTableFromMark(size_t mark) const
|
||||
|
@ -72,6 +72,7 @@ StorageDistributed::StorageDistributed(
|
||||
StorageDistributed::StorageDistributed(
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const String & remote_database_,
|
||||
@ -80,7 +81,7 @@ StorageDistributed::StorageDistributed(
|
||||
Context & context_,
|
||||
const ASTPtr & sharding_key_,
|
||||
const String & data_path_)
|
||||
: IStorage{alias_columns_, column_defaults_},
|
||||
: IStorage{materialized_columns_, alias_columns_, column_defaults_},
|
||||
name(name_), columns(columns_),
|
||||
remote_database(remote_database_), remote_table(remote_table_),
|
||||
context(context_), cluster(cluster_),
|
||||
@ -95,6 +96,7 @@ StorageDistributed::StorageDistributed(
|
||||
StoragePtr StorageDistributed::create(
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const String & remote_database_,
|
||||
@ -107,7 +109,8 @@ StoragePtr StorageDistributed::create(
|
||||
context_.initClusters();
|
||||
|
||||
return (new StorageDistributed{
|
||||
name_, columns_, alias_columns_, column_defaults_,
|
||||
name_, columns_,
|
||||
materialized_columns_, alias_columns_, column_defaults_,
|
||||
remote_database_, remote_table_,
|
||||
context_.getCluster(cluster_name), context_,
|
||||
sharding_key_, data_path_
|
||||
@ -219,7 +222,7 @@ NameAndTypePair StorageDistributed::getColumn(const String & column_name) const
|
||||
|
||||
bool StorageDistributed::hasColumn(const String & column_name) const
|
||||
{
|
||||
return VirtualColumnFactory::hasColumn(column_name) || hasRealColumn(column_name);
|
||||
return VirtualColumnFactory::hasColumn(column_name) || IStorage::hasColumn(column_name);
|
||||
}
|
||||
|
||||
void StorageDistributed::createDirectoryMonitor(const std::string & name)
|
||||
|
@ -72,6 +72,7 @@ StoragePtr StorageFactory::get(
|
||||
Context & context,
|
||||
ASTPtr & query,
|
||||
NamesAndTypesListPtr columns,
|
||||
const NamesAndTypesList & materialized_columns,
|
||||
const NamesAndTypesList & alias_columns,
|
||||
const ColumnDefaults & column_defaults,
|
||||
bool attach) const
|
||||
@ -79,15 +80,15 @@ StoragePtr StorageFactory::get(
|
||||
if (name == "Log")
|
||||
{
|
||||
return StorageLog::create(
|
||||
data_path, table_name,
|
||||
columns, alias_columns, column_defaults,
|
||||
data_path, table_name, columns,
|
||||
materialized_columns, alias_columns, column_defaults,
|
||||
context.getSettings().max_compress_block_size);
|
||||
}
|
||||
else if (name == "Chunks")
|
||||
{
|
||||
return StorageChunks::create(
|
||||
data_path, table_name, database_name,
|
||||
columns, alias_columns, column_defaults,
|
||||
data_path, table_name, database_name, columns,
|
||||
materialized_columns, alias_columns, column_defaults,
|
||||
context, attach);
|
||||
}
|
||||
else if (name == "ChunkRef")
|
||||
@ -97,14 +98,14 @@ StoragePtr StorageFactory::get(
|
||||
else if (name == "View")
|
||||
{
|
||||
return StorageView::create(
|
||||
table_name, database_name, context, query,
|
||||
columns, alias_columns, column_defaults);
|
||||
table_name, database_name, context, query, columns,
|
||||
materialized_columns, alias_columns, column_defaults);
|
||||
}
|
||||
else if (name == "MaterializedView")
|
||||
{
|
||||
return StorageMaterializedView::create(
|
||||
table_name, database_name, context, query,
|
||||
columns, alias_columns, column_defaults,
|
||||
table_name, database_name, context, query, columns,
|
||||
materialized_columns, alias_columns, column_defaults,
|
||||
attach);
|
||||
}
|
||||
else if (name == "ChunkMerger")
|
||||
@ -132,8 +133,8 @@ StoragePtr StorageFactory::get(
|
||||
destination_name_prefix = typeid_cast<ASTIdentifier &>(*args[3]).name;
|
||||
|
||||
return StorageChunkMerger::create(
|
||||
database_name, table_name,
|
||||
columns, alias_columns, column_defaults,
|
||||
database_name, table_name, columns,
|
||||
materialized_columns, alias_columns, column_defaults,
|
||||
source_database, source_table_name_regexp,
|
||||
destination_name_prefix, chunks_to_merge, context);
|
||||
} while (false);
|
||||
@ -145,17 +146,17 @@ StoragePtr StorageFactory::get(
|
||||
else if (name == "TinyLog")
|
||||
{
|
||||
return StorageTinyLog::create(
|
||||
data_path, table_name,
|
||||
columns, alias_columns, column_defaults,
|
||||
data_path, table_name, columns,
|
||||
materialized_columns, alias_columns, column_defaults,
|
||||
attach, context.getSettings().max_compress_block_size);
|
||||
}
|
||||
else if (name == "Memory")
|
||||
{
|
||||
return StorageMemory::create(table_name, columns, alias_columns, column_defaults);
|
||||
return StorageMemory::create(table_name, columns, materialized_columns, alias_columns, column_defaults);
|
||||
}
|
||||
else if (name == "Null")
|
||||
{
|
||||
return StorageNull::create(table_name, columns, alias_columns, column_defaults);
|
||||
return StorageNull::create(table_name, columns, materialized_columns, alias_columns, column_defaults);
|
||||
}
|
||||
else if (name == "Merge")
|
||||
{
|
||||
@ -180,7 +181,8 @@ StoragePtr StorageFactory::get(
|
||||
String table_name_regexp = safeGet<const String &>(typeid_cast<ASTLiteral &>(*args[1]).value);
|
||||
|
||||
return StorageMerge::create(
|
||||
table_name, columns, alias_columns, column_defaults,
|
||||
table_name, columns,
|
||||
materialized_columns, alias_columns, column_defaults,
|
||||
source_database, table_name_regexp, context);
|
||||
}
|
||||
else if (name == "Distributed")
|
||||
@ -210,7 +212,8 @@ StoragePtr StorageFactory::get(
|
||||
const auto & sharding_key = args.size() == 4 ? args[3] : nullptr;
|
||||
|
||||
return StorageDistributed::create(
|
||||
table_name, columns, alias_columns, column_defaults,
|
||||
table_name, columns,
|
||||
materialized_columns, alias_columns, column_defaults,
|
||||
remote_database, remote_table, cluster_name,
|
||||
context, sharding_key, data_path);
|
||||
}
|
||||
@ -328,13 +331,13 @@ StoragePtr StorageFactory::get(
|
||||
if (replicated)
|
||||
return StorageReplicatedMergeTree::create(
|
||||
zookeeper_path, replica_name, attach, data_path, database_name, table_name,
|
||||
columns, alias_columns, column_defaults,
|
||||
columns, materialized_columns, alias_columns, column_defaults,
|
||||
context, primary_expr_list, date_column_name,
|
||||
sampling_expression, index_granularity, mode, sign_column_name);
|
||||
else
|
||||
return StorageMergeTree::create(
|
||||
data_path, database_name, table_name,
|
||||
columns, alias_columns, column_defaults,
|
||||
columns, materialized_columns, alias_columns, column_defaults,
|
||||
context, primary_expr_list, date_column_name,
|
||||
sampling_expression, index_granularity, mode, sign_column_name);
|
||||
}
|
||||
|
@ -413,10 +413,11 @@ StorageLog::StorageLog(
|
||||
const std::string & path_,
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
size_t max_compress_block_size_)
|
||||
: IStorage{alias_columns_, column_defaults_},
|
||||
: IStorage{materialized_columns_, alias_columns_, column_defaults_},
|
||||
path(path_), name(name_), columns(columns_),
|
||||
loaded_marks(false), max_compress_block_size(max_compress_block_size_),
|
||||
file_checker(path + escapeForFileName(name) + '/' + "sizes.json", *this)
|
||||
@ -437,13 +438,14 @@ StoragePtr StorageLog::create(
|
||||
const std::string & path_,
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
size_t max_compress_block_size_)
|
||||
{
|
||||
return (new StorageLog{
|
||||
path_, name_,
|
||||
columns_, alias_columns_, column_defaults_,
|
||||
path_, name_, columns_,
|
||||
materialized_columns_, alias_columns_, column_defaults_,
|
||||
max_compress_block_size_
|
||||
})->thisPtr();
|
||||
}
|
||||
|
@ -17,13 +17,14 @@ StoragePtr StorageMaterializedView::create(
|
||||
Context & context_,
|
||||
ASTPtr & query_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
bool attach_)
|
||||
{
|
||||
return (new StorageMaterializedView{
|
||||
table_name_, database_name_, context_, query_,
|
||||
columns_, alias_columns_, column_defaults_,
|
||||
columns_, materialized_columns_, alias_columns_, column_defaults_,
|
||||
attach_
|
||||
})->thisPtr();
|
||||
}
|
||||
@ -34,10 +35,11 @@ StorageMaterializedView::StorageMaterializedView(
|
||||
Context & context_,
|
||||
ASTPtr & query_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
bool attach_)
|
||||
: StorageView{table_name_, database_name_, context_, query_, columns_, alias_columns_, column_defaults_}
|
||||
: StorageView{table_name_, database_name_, context_, query_, columns_, materialized_columns_, alias_columns_, column_defaults_}
|
||||
{
|
||||
ASTCreateQuery & create = typeid_cast<ASTCreateQuery &>(*query_);
|
||||
|
||||
@ -91,7 +93,7 @@ NameAndTypePair StorageMaterializedView::getColumn(const String & column_name) c
|
||||
|
||||
bool StorageMaterializedView::hasColumn(const String & column_name) const
|
||||
{
|
||||
return VirtualColumnFactory::hasColumn(column_name) || hasRealColumn(column_name);
|
||||
return VirtualColumnFactory::hasColumn(column_name) || IStorage::hasColumn(column_name);
|
||||
}
|
||||
|
||||
BlockInputStreams StorageMaterializedView::read(
|
||||
|
@ -64,9 +64,10 @@ StorageMemory::StorageMemory(
|
||||
StorageMemory::StorageMemory(
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_)
|
||||
: IStorage{alias_columns_, column_defaults_},
|
||||
: IStorage{materialized_columns_, alias_columns_, column_defaults_},
|
||||
name(name_), columns(columns_)
|
||||
{
|
||||
}
|
||||
@ -84,12 +85,13 @@ StoragePtr StorageMemory::create(
|
||||
StoragePtr StorageMemory::create(
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_)
|
||||
{
|
||||
return (new StorageMemory{
|
||||
name_, columns_,
|
||||
alias_columns_, column_defaults_
|
||||
materialized_columns_, alias_columns_, column_defaults_
|
||||
})->thisPtr();
|
||||
}
|
||||
|
||||
|
@ -21,12 +21,13 @@ StorageMerge::StorageMerge(
|
||||
StorageMerge::StorageMerge(
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const String & source_database_,
|
||||
const String & table_name_regexp_,
|
||||
const Context & context_)
|
||||
: IStorage{alias_columns_, column_defaults_},
|
||||
: IStorage{materialized_columns_, alias_columns_, column_defaults_},
|
||||
name(name_), columns(columns_), source_database(source_database_),
|
||||
table_name_regexp(table_name_regexp_), context(context_)
|
||||
{
|
||||
@ -48,6 +49,7 @@ StoragePtr StorageMerge::create(
|
||||
StoragePtr StorageMerge::create(
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
const String & source_database_,
|
||||
@ -55,7 +57,7 @@ StoragePtr StorageMerge::create(
|
||||
const Context & context_)
|
||||
{
|
||||
return (new StorageMerge{
|
||||
name_, columns_, alias_columns_, column_defaults_,
|
||||
name_, columns_, materialized_columns_, alias_columns_, column_defaults_,
|
||||
source_database_, table_name_regexp_, context_
|
||||
})->thisPtr();
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ StorageMergeTree::StorageMergeTree(
|
||||
const String & database_name_,
|
||||
const String & table_name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
Context & context_,
|
||||
@ -22,11 +23,14 @@ StorageMergeTree::StorageMergeTree(
|
||||
MergeTreeData::Mode mode_,
|
||||
const String & sign_column_,
|
||||
const MergeTreeSettings & settings_)
|
||||
: IStorage{alias_columns_, column_defaults_},
|
||||
: IStorage{materialized_columns_, alias_columns_, column_defaults_},
|
||||
path(path_), database_name(database_name_), table_name(table_name_), full_path(path + escapeForFileName(table_name) + '/'),
|
||||
increment(full_path + "increment.txt"), context(context_), background_pool(context_.getBackgroundPool()),
|
||||
data(full_path, columns_, alias_columns_, column_defaults_, context_, primary_expr_ast_, date_column_name_, sampling_expression_,
|
||||
index_granularity_,mode_, sign_column_, settings_, database_name_ + "." + table_name, false),
|
||||
data(full_path, columns_,
|
||||
materialized_columns_, alias_columns_, column_defaults_,
|
||||
context_, primary_expr_ast_, date_column_name_,
|
||||
sampling_expression_, index_granularity_,mode_, sign_column_,
|
||||
settings_, database_name_ + "." + table_name, false),
|
||||
reader(data), writer(data), merger(data),
|
||||
log(&Logger::get(database_name_ + "." + table_name + " (StorageMergeTree)")),
|
||||
shutdown_called(false)
|
||||
@ -40,6 +44,7 @@ StorageMergeTree::StorageMergeTree(
|
||||
StoragePtr StorageMergeTree::create(
|
||||
const String & path_, const String & database_name_, const String & table_name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
Context & context_,
|
||||
@ -53,7 +58,7 @@ StoragePtr StorageMergeTree::create(
|
||||
{
|
||||
auto res = new StorageMergeTree{
|
||||
path_, database_name_, table_name_,
|
||||
columns_, alias_columns_, column_defaults_,
|
||||
columns_, materialized_columns_, alias_columns_, column_defaults_,
|
||||
context_, primary_expr_ast_, date_column_name_,
|
||||
sampling_expression_, index_granularity_, mode_, sign_column_, settings_
|
||||
};
|
||||
|
@ -46,6 +46,7 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree(
|
||||
bool attach,
|
||||
const String & path_, const String & database_name_, const String & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
Context & context_,
|
||||
@ -56,15 +57,17 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree(
|
||||
MergeTreeData::Mode mode_,
|
||||
const String & sign_column_,
|
||||
const MergeTreeSettings & settings_)
|
||||
: IStorage{alias_columns_, column_defaults_}, context(context_),
|
||||
: IStorage{materialized_columns_, alias_columns_, column_defaults_}, context(context_),
|
||||
zookeeper(context.getZooKeeper()), database_name(database_name_),
|
||||
table_name(name_), full_path(path_ + escapeForFileName(table_name) + '/'),
|
||||
zookeeper_path(context.getMacros().expand(zookeeper_path_)),
|
||||
replica_name(context.getMacros().expand(replica_name_)),
|
||||
data( full_path, columns_, alias_columns_, column_defaults_, context_,
|
||||
primary_expr_ast_, date_column_name_, sampling_expression_,
|
||||
index_granularity_, mode_, sign_column_, settings_, database_name_ + "." + table_name, true,
|
||||
std::bind(&StorageReplicatedMergeTree::enqueuePartForCheck, this, std::placeholders::_1)),
|
||||
data(full_path, columns_,
|
||||
materialized_columns_, alias_columns_, column_defaults_,
|
||||
context_, primary_expr_ast_, date_column_name_,
|
||||
sampling_expression_, index_granularity_, mode_, sign_column_,
|
||||
settings_, database_name_ + "." + table_name, true,
|
||||
std::bind(&StorageReplicatedMergeTree::enqueuePartForCheck, this, std::placeholders::_1)),
|
||||
reader(data), writer(data), merger(data), fetcher(data),
|
||||
log(&Logger::get(database_name_ + "." + table_name + " (StorageReplicatedMergeTree)")),
|
||||
shutdown_event(false)
|
||||
@ -116,7 +119,8 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree(
|
||||
{
|
||||
LOG_INFO(log, "Have unreplicated data");
|
||||
|
||||
unreplicated_data.reset(new MergeTreeData(unreplicated_path, columns_, alias_columns_, column_defaults_,
|
||||
unreplicated_data.reset(new MergeTreeData(unreplicated_path, columns_,
|
||||
materialized_columns_, alias_columns_, column_defaults_,
|
||||
context_, primary_expr_ast_,
|
||||
date_column_name_, sampling_expression_, index_granularity_, mode_, sign_column_, settings_,
|
||||
database_name_ + "." + table_name + "[unreplicated]", false));
|
||||
@ -140,6 +144,7 @@ StoragePtr StorageReplicatedMergeTree::create(
|
||||
bool attach,
|
||||
const String & path_, const String & database_name_, const String & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
Context & context_,
|
||||
@ -154,7 +159,7 @@ StoragePtr StorageReplicatedMergeTree::create(
|
||||
auto res = new StorageReplicatedMergeTree{
|
||||
zookeeper_path_, replica_name_, attach,
|
||||
path_, database_name_, name_,
|
||||
columns_, alias_columns_, column_defaults_,
|
||||
columns_, materialized_columns_, alias_columns_, column_defaults_,
|
||||
context_, primary_expr_ast_, date_column_name_,
|
||||
sampling_expression_, index_granularity_, mode_,
|
||||
sign_column_, settings_
|
||||
|
@ -28,7 +28,7 @@ BlockInputStreams StorageSystemDatabases::read(
|
||||
processed_stage = QueryProcessingStage::FetchColumns;
|
||||
|
||||
Block block;
|
||||
|
||||
|
||||
ColumnWithNameAndType col_name;
|
||||
col_name.name = "name";
|
||||
col_name.type = new DataTypeString;
|
||||
|
@ -36,7 +36,7 @@ BlockInputStreams StorageSystemOne::read(
|
||||
col.type = new DataTypeUInt8;
|
||||
col.column = new ColumnConstUInt8(1, 0);
|
||||
block.insert(col);
|
||||
|
||||
|
||||
return BlockInputStreams(1, new OneBlockInputStream(block));
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ BlockInputStreams StorageSystemTables::read(
|
||||
processed_stage = QueryProcessingStage::FetchColumns;
|
||||
|
||||
Block block;
|
||||
|
||||
|
||||
ColumnWithNameAndType col_db;
|
||||
col_db.name = "database";
|
||||
col_db.type = new DataTypeString;
|
||||
@ -50,7 +50,7 @@ BlockInputStreams StorageSystemTables::read(
|
||||
block.insert(col_engine);
|
||||
|
||||
Poco::ScopedLock<Poco::Mutex> lock(context.getMutex());
|
||||
|
||||
|
||||
for (Databases::const_iterator it = context.getDatabases().begin(); it != context.getDatabases().end(); ++it)
|
||||
{
|
||||
for (Tables::const_iterator jt = it->second.begin(); jt != it->second.end(); ++jt)
|
||||
@ -60,7 +60,7 @@ BlockInputStreams StorageSystemTables::read(
|
||||
col_engine.column->insert(jt->second->getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return BlockInputStreams(1, new OneBlockInputStream(block));
|
||||
}
|
||||
|
||||
|
@ -301,11 +301,13 @@ StorageTinyLog::StorageTinyLog(
|
||||
const std::string & path_,
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
bool attach,
|
||||
size_t max_compress_block_size_)
|
||||
: IStorage{alias_columns_, column_defaults_}, path(path_), name(name_), columns(columns_),
|
||||
: IStorage{materialized_columns_, alias_columns_, column_defaults_},
|
||||
path(path_), name(name_), columns(columns_),
|
||||
max_compress_block_size(max_compress_block_size_),
|
||||
file_checker(path + escapeForFileName(name) + '/' + "sizes.json", *this),
|
||||
log(&Logger::get("StorageTinyLog"))
|
||||
@ -329,14 +331,15 @@ StoragePtr StorageTinyLog::create(
|
||||
const std::string & path_,
|
||||
const std::string & name_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_,
|
||||
bool attach,
|
||||
size_t max_compress_block_size_)
|
||||
{
|
||||
return (new StorageTinyLog{
|
||||
path_, name_,
|
||||
columns_, alias_columns_, column_defaults_,
|
||||
path_, name_, columns_,
|
||||
materialized_columns_, alias_columns_, column_defaults_,
|
||||
attach, max_compress_block_size_
|
||||
})->thisPtr();
|
||||
}
|
||||
|
@ -16,12 +16,13 @@ StoragePtr StorageView::create(
|
||||
Context & context_,
|
||||
ASTPtr & query_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_)
|
||||
{
|
||||
return (new StorageView{
|
||||
table_name_, database_name_, context_, query_,
|
||||
columns_, alias_columns_, column_defaults_
|
||||
columns_, materialized_columns_, alias_columns_, column_defaults_
|
||||
})->thisPtr();
|
||||
}
|
||||
|
||||
@ -32,9 +33,10 @@ StorageView::StorageView(
|
||||
Context & context_,
|
||||
ASTPtr & query_,
|
||||
NamesAndTypesListPtr columns_,
|
||||
const NamesAndTypesList & materialized_columns_,
|
||||
const NamesAndTypesList & alias_columns_,
|
||||
const ColumnDefaults & column_defaults_)
|
||||
: IStorage{alias_columns_, column_defaults}, table_name(table_name_),
|
||||
: IStorage{materialized_columns_, alias_columns_, column_defaults}, table_name(table_name_),
|
||||
database_name(database_name_), context(context_), columns(columns_)
|
||||
{
|
||||
ASTCreateQuery & create = typeid_cast<ASTCreateQuery &>(*query_);
|
||||
|
Loading…
Reference in New Issue
Block a user