Merge pull request #43118 from kitaisreal/analyzer-aggregation-crash-fix

Analyzer aggregation crash fix
This commit is contained in:
Maksim Kita 2022-11-12 01:15:22 +03:00 committed by GitHub
commit ebde28bc50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 5 deletions

View File

@ -33,18 +33,27 @@ public:
if (function_node->getFunctionName() == "count" && !first_argument_constant_literal.isNull())
{
resolveAsCountAggregateFunction(*function_node);
function_node->getArguments().getNodes().clear();
}
else if (function_node->getFunctionName() == "sum" && first_argument_constant_literal.getType() == Field::Types::UInt64 &&
else if (function_node->getFunctionName() == "sum" &&
first_argument_constant_literal.getType() == Field::Types::UInt64 &&
first_argument_constant_literal.get<UInt64>() == 1)
{
auto result_type = function_node->getResultType();
AggregateFunctionProperties properties;
auto aggregate_function = AggregateFunctionFactory::instance().get("count", {}, {}, properties);
function_node->resolveAsAggregateFunction(std::move(aggregate_function), std::move(result_type));
resolveAsCountAggregateFunction(*function_node);
function_node->getArguments().getNodes().clear();
}
}
private:
static inline void resolveAsCountAggregateFunction(FunctionNode & function_node)
{
auto function_result_type = function_node.getResultType();
AggregateFunctionProperties properties;
auto aggregate_function = AggregateFunctionFactory::instance().get("count", {}, {}, properties);
function_node.resolveAsAggregateFunction(std::move(aggregate_function), std::move(function_result_type));
}
};
}

View File

@ -0,0 +1,2 @@
10 123456789
10 123456789

View File

@ -0,0 +1,13 @@
SET allow_experimental_analyzer = 1;
SET compile_aggregate_expressions = 1;
SET min_count_to_compile_aggregate_expression = 0;
DROP TABLE IF EXISTS lc_00906__fuzz_46;
CREATE TABLE lc_00906__fuzz_46 (`b` Int64) ENGINE = MergeTree ORDER BY b;
INSERT INTO lc_00906__fuzz_46 SELECT '0123456789' FROM numbers(10);
SELECT count(3.4028234663852886e38), b FROM lc_00906__fuzz_46 GROUP BY b;
SELECT count(1), b FROM lc_00906__fuzz_46 GROUP BY b;
DROP TABLE lc_00906__fuzz_46;