ClickHouse/src/Parsers/ASTColumnsTransformers.h

117 lines
3.4 KiB
C++
Raw Normal View History

2020-08-29 05:33:46 +00:00
#pragma once
#include <Parsers/IAST.h>
2021-01-03 16:45:27 +00:00
namespace re2
{
class RE2;
}
2020-08-29 05:33:46 +00:00
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);
2020-11-02 03:10:20 +00:00
if (parameters)
res->parameters = parameters->clone();
2021-08-20 06:44:51 +00:00
if (lambda)
res->lambda = lambda->clone();
2020-08-29 05:33:46 +00:00
return res;
}
void transform(ASTs & nodes) const override;
void appendColumnName(WriteBuffer & ostr) const override;
void updateTreeHashImpl(SipHash & hash_state) const override;
2021-08-20 06:44:51 +00:00
// Case 1 APPLY (quantile(0.9))
2020-08-29 05:33:46 +00:00
String func_name;
2020-11-02 03:10:20 +00:00
ASTPtr parameters;
2020-08-29 05:33:46 +00:00
2021-08-20 06:44:51 +00:00
// Case 2 APPLY (x -> quantile(0.9)(x))
ASTPtr lambda;
String lambda_arg;
String column_name_prefix;
2020-08-29 05:33:46 +00:00
protected:
void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
};
class ASTColumnsExceptTransformer : public IASTColumnsTransformer
{
public:
bool is_strict = false;
2020-08-29 05:33:46 +00:00
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;
2021-01-03 16:45:27 +00:00
void setPattern(String pattern);
bool isColumnMatching(const String & column_name) const;
void appendColumnName(WriteBuffer & ostr) const override;
void updateTreeHashImpl(SipHash & hash_state) const override;
2020-08-29 05:33:46 +00:00
protected:
void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
2021-01-03 16:45:27 +00:00
std::shared_ptr<re2::RE2> column_matcher;
String original_pattern;
2020-08-29 05:33:46 +00:00
};
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);
replacement->expr = expr->clone();
return replacement;
}
void appendColumnName(WriteBuffer & ostr) const override;
void updateTreeHashImpl(SipHash & hash_state) const override;
2020-08-29 05:33:46 +00:00
String name;
ASTPtr expr;
protected:
void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
};
bool is_strict = false;
2020-08-29 05:33:46 +00:00
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;
void appendColumnName(WriteBuffer & ostr) const override;
void updateTreeHashImpl(SipHash & hash_state) const override;
2020-08-29 05:33:46 +00:00
protected:
void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
private:
static void replaceChildren(ASTPtr & node, const ASTPtr & replacement, const String & name);
};
}