aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Analyzer/Passes/IfTransformStringsToEnumPass.h
blob: a4a014967e0f69e94c6165269a8c19fa80393f7f (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
#pragma once

#include <Analyzer/IQueryTreePass.h>

namespace DB
{

/**
 * This pass replaces string-type arguments in If and Transform to enum.
 *
 * E.g.
 * -------------------------------
 * SELECT if(number > 5, 'a', 'b')
 * FROM system.numbers;
 *
 * will be transformed into
 *
 * SELECT if(number > 5, _CAST('a', 'Enum8(\'a\' = 1, \'b\' = 2)'), _CAST('b', 'Enum8(\'a\' = 1, \'b\' = 2)'))
 * FROM system.numbers;
 * -------------------------------
 * SELECT transform(number, [2, 4], ['a', 'b'], 'c') FROM system.numbers;
 *
 * will be transformed into
 *
 * SELECT transform(number, [2, 4], _CAST(['a', 'b'], 'Array(Enum8(\'a\' = 1, \'b\' = 2, \'c\' = 3)'), _CAST('c', 'Enum8(\'a\' = 1, \'b\' = 2, \'c\' = 3)'))
 * FROM system.numbers;
 * -------------------------------
 */
class IfTransformStringsToEnumPass final : public IQueryTreePass
{
public:
    String getName() override { return "IfTransformStringsToEnumPass"; }

    String getDescription() override { return "Replaces string-type arguments in If and Transform to enum"; }

    void run(QueryTreeNodePtr query_tree_node, ContextPtr context) override;
};

}