aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Interpreters/processColumnTransformers.cpp
blob: 2a704d4a93729195cf66243784f1211336edb554 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <Interpreters/processColumnTransformers.h>

#include <Interpreters/DatabaseAndTableWithAlias.h>
#include <Interpreters/TranslateQualifiedNamesVisitor.h>
#include <Interpreters/getTableExpressions.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTTablesInSelectQuery.h>
#include <Parsers/IAST.h>
#include <Storages/IStorage.h>
#include <Storages/StorageInMemoryMetadata.h>

namespace DB
{

ASTPtr processColumnTransformers(
        const String & current_database,
        const StoragePtr & table,
        const StorageMetadataPtr & metadata_snapshot,
        ASTPtr query_columns)
{
    const auto & columns = metadata_snapshot->getColumns();
    auto names_and_types = columns.getOrdinary();
    removeDuplicateColumns(names_and_types);

    TablesWithColumns tables_with_columns;
    {
        auto table_expr = std::make_shared<ASTTableExpression>();
        table_expr->database_and_table_name = std::make_shared<ASTTableIdentifier>(table->getStorageID());
        table_expr->children.push_back(table_expr->database_and_table_name);
        tables_with_columns.emplace_back(DatabaseAndTableWithAlias(*table_expr, current_database), names_and_types);
    }

    tables_with_columns[0].addHiddenColumns(columns.getMaterialized());
    tables_with_columns[0].addHiddenColumns(columns.getAliases());
    tables_with_columns[0].addHiddenColumns(table->getVirtuals());

    NameSet source_columns_set;
    for (const auto & identifier : query_columns->children)
        source_columns_set.insert(identifier->getColumnName());

    TranslateQualifiedNamesVisitor::Data visitor_data(source_columns_set, tables_with_columns);
    TranslateQualifiedNamesVisitor visitor(visitor_data);
    auto columns_ast = query_columns->clone();
    visitor.visit(columns_ast);

    return columns_ast;
}

}