mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Allow parameterized functions in APPLY
This commit is contained in:
parent
30325689c4
commit
13fee19778
@ -30,16 +30,21 @@ void IASTColumnsTransformer::transform(const ASTPtr & transformer, ASTs & nodes)
|
||||
}
|
||||
}
|
||||
|
||||
void ASTColumnsApplyTransformer::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
|
||||
void ASTColumnsApplyTransformer::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
||||
{
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << "APPLY" << (settings.hilite ? hilite_none : "") << "(" << func_name << ")";
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << "APPLY" << (settings.hilite ? hilite_none : "") << "(" << func_name;
|
||||
if (parameters)
|
||||
parameters->formatImpl(settings, state, frame);
|
||||
settings.ostr << ")";
|
||||
}
|
||||
|
||||
void ASTColumnsApplyTransformer::transform(ASTs & nodes) const
|
||||
{
|
||||
for (auto & column : nodes)
|
||||
{
|
||||
column = makeASTFunction(func_name, column);
|
||||
auto function = makeASTFunction(func_name, column);
|
||||
function->parameters = parameters;
|
||||
column = function;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,10 +18,13 @@ public:
|
||||
ASTPtr clone() const override
|
||||
{
|
||||
auto res = std::make_shared<ASTColumnsApplyTransformer>(*this);
|
||||
if (parameters)
|
||||
res->parameters = parameters->clone();
|
||||
return res;
|
||||
}
|
||||
void transform(ASTs & nodes) const override;
|
||||
String func_name;
|
||||
ASTPtr parameters;
|
||||
|
||||
protected:
|
||||
void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
|
||||
|
@ -1229,16 +1229,29 @@ bool ParserColumnsTransformers::parseImpl(Pos & pos, ASTPtr & node, Expected & e
|
||||
return false;
|
||||
++pos;
|
||||
|
||||
String func_name;
|
||||
if (!parseIdentifierOrStringLiteral(pos, expected, func_name))
|
||||
ASTPtr func_name;
|
||||
if (!ParserIdentifier().parse(pos, func_name, expected))
|
||||
return false;
|
||||
|
||||
ASTPtr expr_list_args;
|
||||
if (pos->type == TokenType::OpeningRoundBracket)
|
||||
{
|
||||
++pos;
|
||||
if (!ParserExpressionList(false).parse(pos, expr_list_args, expected))
|
||||
return false;
|
||||
|
||||
if (pos->type != TokenType::ClosingRoundBracket)
|
||||
return false;
|
||||
++pos;
|
||||
}
|
||||
|
||||
if (pos->type != TokenType::ClosingRoundBracket)
|
||||
return false;
|
||||
++pos;
|
||||
|
||||
auto res = std::make_shared<ASTColumnsApplyTransformer>();
|
||||
res->func_name = func_name;
|
||||
res->func_name = getIdentifierName(func_name);
|
||||
res->parameters = expr_list_args;
|
||||
node = std::move(res);
|
||||
return true;
|
||||
}
|
||||
|
@ -77,3 +77,9 @@ SELECT
|
||||
toFloat64(k),
|
||||
j
|
||||
FROM columns_transformers
|
||||
[110] [9] [173.5]
|
||||
SELECT
|
||||
quantiles(0.5)(i),
|
||||
quantiles(0.5)(j),
|
||||
quantiles(0.5)(k)
|
||||
FROM columns_transformers
|
||||
|
@ -41,4 +41,8 @@ EXPLAIN SYNTAX SELECT COLUMNS(i, j, k) APPLY(sum) from columns_transformers;
|
||||
SELECT i, j, COLUMNS(i, j, k) APPLY(toFloat64), COLUMNS(i, j) EXCEPT (i) from columns_transformers;
|
||||
EXPLAIN SYNTAX SELECT i, j, COLUMNS(i, j, k) APPLY(toFloat64), COLUMNS(i, j) EXCEPT (i) from columns_transformers;
|
||||
|
||||
-- APPLY with parameterized function
|
||||
SELECT COLUMNS(i, j, k) APPLY(quantiles(0.5)) from columns_transformers;
|
||||
EXPLAIN SYNTAX SELECT COLUMNS(i, j, k) APPLY(quantiles(0.5)) from columns_transformers;
|
||||
|
||||
DROP TABLE columns_transformers;
|
||||
|
Loading…
Reference in New Issue
Block a user