Fix crash with Variant + AggregateFunction type

This commit is contained in:
avogar 2024-07-25 13:05:25 +00:00
parent 397a523971
commit cd06945a03
3 changed files with 71 additions and 1 deletions

View File

@ -330,7 +330,11 @@ ColumnPtr ColumnAggregateFunction::filter(const Filter & filter, ssize_t result_
void ColumnAggregateFunction::expand(const Filter & mask, bool inverted)
{
expandDataByMask<char *>(data, mask, inverted);
ensureOwnership();
Arena & arena = createOrGetArena();
char * default_ptr = arena.alignedAlloc(func->sizeOfData(), func->alignOfData());
func->create(default_ptr);
expandDataByMask<char *>(data, mask, inverted, default_ptr);
}
ColumnPtr ColumnAggregateFunction::permute(const Permutation & perm, size_t limit) const

View File

@ -0,0 +1,6 @@
500
fail 500
499
fail 500
500 499
fail 500 500

View File

@ -0,0 +1,60 @@
SET allow_experimental_variant_type = 1;
DROP TABLE IF EXISTS source;
CREATE TABLE source
(
Name String,
Value Int64
) ENGINE = MergeTree ORDER BY ();
INSERT INTO source SELECT ['fail', 'success'][number % 2] as Name, number AS Value FROM numbers(1000);
DROP TABLE IF EXISTS test_agg_variant;
CREATE TABLE test_agg_variant
(
Name String,
Value Variant(AggregateFunction(uniqExact, Int64), AggregateFunction(avg, Int64))
)
ENGINE = MergeTree
ORDER BY (Name);
INSERT INTO test_agg_variant
SELECT
Name,
t AS Value
FROM
(
SELECT
Name,
arrayJoin([
uniqExactState(Value)::Variant(AggregateFunction(uniqExact, Int64), AggregateFunction(avg, Int64)),
avgState(Value)::Variant(AggregateFunction(uniqExact, Int64), AggregateFunction(avg, Int64))
]) AS t
FROM source
GROUP BY Name
);
SELECT
Name,
uniqExactMerge(Value.`AggregateFunction(uniqExact, Int64)`) AS Value
FROM test_agg_variant
GROUP BY Name;
SELECT
Name,
avgMerge(Value.`AggregateFunction(avg, Int64)`) AS Value
FROM test_agg_variant
GROUP BY Name;
SELECT
Name,
uniqExactMerge(Value.`AggregateFunction(uniqExact, Int64)`) AS ValueUniq,
avgMerge(Value.`AggregateFunction(avg, Int64)`) AS ValueAvg
FROM test_agg_variant
GROUP BY Name;
DROP TABLE test_agg_variant;
DROP TABLE source;