mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Fixed error found by M.Filimonov (equality of array sizes are not checked in n-ary version of aggregate functions with -Array combinator) [#CLICKHOUSE-2].
This commit is contained in:
parent
6c28c72fdc
commit
521b3aee84
@ -10,6 +10,11 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int SIZES_OF_ARRAYS_DOESNT_MATCH;
|
||||
}
|
||||
|
||||
|
||||
/** Not an aggregate function, but an adapter of aggregate functions,
|
||||
* which any aggregate function `agg(x)` makes an aggregate function of the form `aggArray(x)`.
|
||||
@ -97,6 +102,16 @@ public:
|
||||
size_t begin = row_num == 0 ? 0 : offsets[row_num - 1];
|
||||
size_t end = offsets[row_num];
|
||||
|
||||
/// Sanity check. NOTE We can implement specialization for a case with single argument, if the check will hurt performance.
|
||||
for (size_t i = 1; i < num_agruments; ++i)
|
||||
{
|
||||
const ColumnArray & ith_column = static_cast<const ColumnArray &>(*columns[i]);
|
||||
const IColumn::Offsets & ith_offsets = ith_column.getOffsets();
|
||||
|
||||
if (ith_offsets[row_num] != end || (row_num != 0 && ith_offsets[row_num - 1] != begin))
|
||||
throw Exception("Arrays passed to " + getName() + " aggregate function have different sizes", ErrorCodes::SIZES_OF_ARRAYS_DOESNT_MATCH);
|
||||
}
|
||||
|
||||
for (size_t i = begin; i < end; ++i)
|
||||
nested_func->add(place, nested, i, arena);
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
2
|
||||
3
|
||||
2
|
||||
3
|
||||
2
|
||||
3
|
6
dbms/tests/queries/0_stateless/00533_uniq_array.sql
Normal file
6
dbms/tests/queries/0_stateless/00533_uniq_array.sql
Normal file
@ -0,0 +1,6 @@
|
||||
SELECT uniqArray([0, 1, 1], [0, 1, 1], [0, 1, 1]);
|
||||
SELECT uniqArray([0, 1, 1], [0, 1, 1], [0, 1, 0]);
|
||||
SELECT uniqExactArray([0, 1, 1], [0, 1, 1], [0, 1, 1]);
|
||||
SELECT uniqExactArray([0, 1, 1], [0, 1, 1], [0, 1, 0]);
|
||||
SELECT uniqUpToArray(10)([0, 1, 1], [0, 1, 1], [0, 1, 1]);
|
||||
SELECT uniqUpToArray(10)([0, 1, 1], [0, 1, 1], [0, 1, 0]);
|
Loading…
Reference in New Issue
Block a user