ASTColumnsTransformers.h 2.6 KB
Newer Older
A
Amos Bird 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#pragma once

#include <Parsers/IAST.h>

namespace DB
{
class IASTColumnsTransformer : public IAST
{
public:
    virtual void transform(ASTs & nodes) const = 0;
    static void transform(const ASTPtr & transformer, ASTs & nodes);
};

class ASTColumnsApplyTransformer : public IASTColumnsTransformer
{
public:
    String getID(char) const override { return "ColumnsApplyTransformer"; }
    ASTPtr clone() const override
    {
        auto res = std::make_shared<ASTColumnsApplyTransformer>(*this);
A
Amos Bird 已提交
21 22
        if (parameters)
            res->parameters = parameters->clone();
A
Amos Bird 已提交
23 24 25 26
        return res;
    }
    void transform(ASTs & nodes) const override;
    String func_name;
27
    String column_name_prefix;
A
Amos Bird 已提交
28
    ASTPtr parameters;
A
Amos Bird 已提交
29 30 31 32 33 34 35 36

protected:
    void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
};

class ASTColumnsExceptTransformer : public IASTColumnsTransformer
{
public:
37
    bool is_strict = false;
A
Amos Bird 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    String getID(char) const override { return "ColumnsExceptTransformer"; }
    ASTPtr clone() const override
    {
        auto clone = std::make_shared<ASTColumnsExceptTransformer>(*this);
        clone->cloneChildren();
        return clone;
    }
    void transform(ASTs & nodes) const override;

protected:
    void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
};

class ASTColumnsReplaceTransformer : public IASTColumnsTransformer
{
public:
    class Replacement : public IAST
    {
    public:
        String getID(char) const override { return "ColumnsReplaceTransformer::Replacement"; }
        ASTPtr clone() const override
        {
            auto replacement = std::make_shared<Replacement>(*this);
T
tavplubix 已提交
61
            replacement->children.clear();
A
Amos Bird 已提交
62 63 64 65 66 67 68 69 70 71 72 73
            replacement->expr = expr->clone();
            replacement->children.push_back(replacement->expr);
            return replacement;
        }

        String name;
        ASTPtr expr;

    protected:
        void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
    };

74
    bool is_strict = false;
A
Amos Bird 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
    String getID(char) const override { return "ColumnsReplaceTransformer"; }
    ASTPtr clone() const override
    {
        auto clone = std::make_shared<ASTColumnsReplaceTransformer>(*this);
        clone->cloneChildren();
        return clone;
    }
    void transform(ASTs & nodes) const override;

protected:
    void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;

private:
    static void replaceChildren(ASTPtr & node, const ASTPtr & replacement, const String & name);
};

}