aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Storages/extractKeyExpressionList.cpp
blob: cd03d0d512313b72ab9bcb5ffbcf58b7947b6393 (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
#include <Storages/extractKeyExpressionList.h>
#include <Parsers/ASTFunction.h>
#include <Parsers/ASTExpressionList.h>

namespace DB
{
    ASTPtr extractKeyExpressionList(const ASTPtr & node)
    {
        if (!node)
            return std::make_shared<ASTExpressionList>();

        const auto * expr_func = node->as<ASTFunction>();

        if (expr_func && expr_func->name == "tuple")
        {
            if (expr_func->arguments)
                /// Primary key is specified in tuple, extract its arguments.
                return expr_func->arguments->clone();
            else
                return std::make_shared<ASTExpressionList>();
        }
        else
        {
            /// Primary key consists of one column.
            auto res = std::make_shared<ASTExpressionList>();
            res->children.push_back(node);
            return res;
        }
    }
}