Fix support for complex parameters of parametric aggregate functions, #30975

This commit is contained in:
Alexey Milovidov 2022-12-19 07:26:54 +01:00
parent f3a4163c87
commit 8b6092b321
5 changed files with 14 additions and 5 deletions

View File

@ -461,6 +461,7 @@ public:
bool keepKey(const T &) const { return true; }
};
template <typename T, bool overflow, bool tuple_argument>
class AggregateFunctionSumMapFiltered final :
public AggregateFunctionMapBase<T,
@ -495,14 +496,15 @@ public:
"Aggregate function {} requires an Array as a parameter",
getName());
this->parameters = params_;
keys_to_keep.reserve(keys_to_keep_values.size());
for (const Field & f : keys_to_keep_values)
keys_to_keep.emplace(f.safeGet<T>());
}
String getName() const override
{ return overflow ? "sumMapFilteredWithOverflow" : "sumMapFiltered"; }
String getName() const override { return overflow ? "sumMapFilteredWithOverflow" : "sumMapFiltered"; }
bool keepKey(const T & key) const { return keys_to_keep.count(key); }
};

View File

@ -67,7 +67,7 @@ String DataTypeAggregateFunction::getNameImpl(bool with_version) const
if (!parameters.empty())
{
stream << '(';
for (size_t i = 0; i < parameters.size(); ++i)
for (size_t i = 0, size = parameters.size(); i < size; ++i)
{
if (i)
stream << ", ";

View File

@ -27,7 +27,7 @@ private:
{
ParserNestedTable nested_parser;
ParserDataType data_type_parser;
ParserLiteral literal_parser;
ParserAllCollectionsOfLiterals literal_parser;
const char * operators[] = {"=", "equals", nullptr};
ParserLeftAssociativeBinaryOperatorList enum_parser(operators, std::make_unique<ParserLiteral>());
@ -145,4 +145,3 @@ bool ParserDataType::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
}
}

View File

@ -0,0 +1,4 @@
AggregateFunction(1, sumMapFiltered([1, 2]), Array(UInt8), Array(UInt8))
02010A00000000000000020A00000000000000
02010A00000000000000020A00000000000000
([1,2],[20,20])

View File

@ -0,0 +1,4 @@
SELECT toTypeName(sumMapFilteredState([1, 2])([1, 2, 3], [10, 10, 10]));
SELECT hex(sumMapFilteredState([1, 2])([1, 2, 3], [10, 10, 10]));
SELECT hex(unhex('02010A00000000000000020A00000000000000')::AggregateFunction(1, sumMapFiltered([1, 2]), Array(UInt8), Array(UInt8)));
SELECT sumMapFilteredMerge([1, 2])(*) FROM remote('127.0.0.{1,2}', view(SELECT sumMapFilteredState([1, 2])([1, 2, 3], [10, 10, 10])));