Add asterisk_include_materialized_columns and asterisk_include_materialized_columns switches to include materialized columns and alias columns respectively for wildcard query

This commit is contained in:
Ken Chen 2020-11-27 03:25:19 +00:00
parent cd825e4fd9
commit 349571a458
4 changed files with 42 additions and 5 deletions

View File

@ -397,6 +397,8 @@ class IColumn;
M(Bool, allow_non_metadata_alters, true, "Allow to execute alters which affects not only tables metadata, but also data on disk", 0) \
M(Bool, enable_global_with_statement, false, "Propagate WITH statements to UNION queries and all subqueries", 0) \
M(Bool, aggregate_functions_null_for_empty, false, "Rewrite all aggregate functions in a query, adding -OrNull suffix to them", 0) \
M(Bool, asterisk_include_materialized_columns, false, "Include MATERIALIZED columns for wildcard query", 0) \
M(Bool, asterisk_include_alias_columns, false, "Include ALIAS columns for wildcard query", 0) \
\
/** Obsolete settings that do nothing but left for compatibility reasons. Remove each one after half a year of obsolescence. */ \
\

View File

@ -49,7 +49,9 @@ struct TableWithColumnNamesAndTypes
{
DatabaseAndTableWithAlias table;
NamesAndTypesList columns;
NamesAndTypesList hidden_columns; /// Not general columns like MATERIALIZED and ALIAS. They are omitted in * and t.* results.
NamesAndTypesList hidden_columns; /// Not general columns like MATERIALIZED, ALIAS, VIRTUAL. They are omitted in * and t.* results by default.
NamesAndTypesList alias_columns;
NamesAndTypesList materialized_columns;
TableWithColumnNamesAndTypes(const DatabaseAndTableWithAlias & table_, const NamesAndTypesList & columns_)
: table(table_)
@ -63,11 +65,28 @@ struct TableWithColumnNamesAndTypes
void addHiddenColumns(const NamesAndTypesList & addition)
{
hidden_columns.insert(hidden_columns.end(), addition.begin(), addition.end());
addAdditionalColumns(hidden_columns, addition);
}
void addAliasColumns(const NamesAndTypesList & addition)
{
addAdditionalColumns(alias_columns, addition);
}
void addMaterializedColumns(const NamesAndTypesList & addition)
{
addAdditionalColumns(alias_columns, addition);
}
private:
void addAdditionalColumns(NamesAndTypesList & target, const NamesAndTypesList & addition)
{
target.insert(target.end(), addition.begin(), addition.end());
for (auto & col : addition)
names.insert(col.name);
}
private:
NameSet names;
};

View File

@ -222,11 +222,15 @@ void TranslateQualifiedNamesMatcher::visit(ASTExpressionList & node, const ASTPt
bool first_table = true;
for (const auto & table : tables_with_columns)
{
for (const auto & column : table.columns)
auto all_columns = {&table.columns, &table.alias_columns, &table.materialized_columns};
for (const auto cols: all_columns)
{
if (first_table || !data.join_using_columns.count(column.name))
for (const auto & column : *cols)
{
addIdentifier(columns, table.table, column.name);
if (first_table || !data.join_using_columns.count(column.name))
{
addIdentifier(columns, table.table, column.name);
}
}
}

View File

@ -124,6 +124,8 @@ TablesWithColumns getDatabaseAndTablesWithColumns(const std::vector<const ASTTab
if (!table_expressions.empty())
{
String current_database = context.getCurrentDatabase();
bool include_alias_cols = context.getSettingsRef().asterisk_include_alias_columns;
bool include_materialized_cols = context.getSettingsRef().asterisk_include_materialized_columns;
for (const ASTTableExpression * table_expression : table_expressions)
{
@ -141,6 +143,16 @@ TablesWithColumns getDatabaseAndTablesWithColumns(const std::vector<const ASTTab
table.addHiddenColumns(materialized);
table.addHiddenColumns(aliases);
table.addHiddenColumns(virtuals);
if (include_alias_cols)
{
table.addAliasColumns(aliases);
}
if (include_materialized_cols)
{
table.addMaterializedColumns(materialized);
}
}
}