mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
CLICKHOUSE-4179 Fix of function arrayEnumerateUniqRanked for arguments with empty arrays
This commit is contained in:
parent
00a1ac64a4
commit
516ce69d70
@ -321,6 +321,7 @@ void FunctionArrayEnumerateRankedExtended<Derived>::executeMethodImpl(
|
||||
|
||||
std::vector<size_t> indices_by_depth(arrays_depths.max_array_depth);
|
||||
std::vector<size_t> current_offset_n_by_depth(arrays_depths.max_array_depth);
|
||||
std::vector<size_t> last_offset_by_depth(arrays_depths.max_array_depth, 0); // For skipping empty arrays
|
||||
|
||||
UInt32 rank = 0;
|
||||
|
||||
@ -330,6 +331,24 @@ void FunctionArrayEnumerateRankedExtended<Derived>::executeMethodImpl(
|
||||
{
|
||||
bool want_clear = false;
|
||||
|
||||
/// Skipping offsets if no data in this array
|
||||
if (prev_off == off)
|
||||
{
|
||||
want_clear = true;
|
||||
++indices_by_depth[0];
|
||||
|
||||
for (int depth = current_offset_depth - 1; depth >= 0; --depth)
|
||||
{
|
||||
const auto offsets_by_depth_size = offsets_by_depth[depth]->size();
|
||||
while (last_offset_by_depth[depth] == (*offsets_by_depth[depth])[current_offset_n_by_depth[depth]])
|
||||
{
|
||||
if(current_offset_n_by_depth[depth] + 1 >= offsets_by_depth_size)
|
||||
break; // only one empty array: SELECT arrayEnumerateUniqRanked([]);
|
||||
++current_offset_n_by_depth[depth];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// For each element at the depth we want to look.
|
||||
for (size_t j = prev_off; j < off; ++j)
|
||||
{
|
||||
@ -358,12 +377,19 @@ void FunctionArrayEnumerateRankedExtended<Derived>::executeMethodImpl(
|
||||
|
||||
for (int depth = current_offset_depth - 1; depth >= 0; --depth)
|
||||
{
|
||||
/// Skipping offsets for empty arrays
|
||||
while (last_offset_by_depth[depth] == (*offsets_by_depth[depth])[current_offset_n_by_depth[depth]])
|
||||
{
|
||||
++current_offset_n_by_depth[depth];
|
||||
}
|
||||
|
||||
++indices_by_depth[depth];
|
||||
|
||||
if (indices_by_depth[depth] == (*offsets_by_depth[depth])[current_offset_n_by_depth[depth]])
|
||||
{
|
||||
if (static_cast<int>(arrays_depths.clear_depth) == depth + 1)
|
||||
want_clear = true;
|
||||
last_offset_by_depth[depth] = (*offsets_by_depth[depth])[current_offset_n_by_depth[depth]];
|
||||
++current_offset_n_by_depth[depth];
|
||||
}
|
||||
else
|
||||
|
@ -178,3 +178,50 @@ arrayEnumerateUniq(a1, a2) =
|
||||
[1,2]
|
||||
[1,1]
|
||||
[[[[[[[[[[1]]]]]]]]]]
|
||||
[[1],[1]]
|
||||
[[],[1],[1]]
|
||||
[[],[],[],[1],[],[1]]
|
||||
[[],[],[],[],[1],[1]]
|
||||
[[1],[],[1]]
|
||||
[[1],[],[],[1]]
|
||||
[[1],[],[],[1],[1]]
|
||||
-- no order
|
||||
[[],[1,2,3,4]] [[],[1,1,1,1]]
|
||||
[[3,4,5]] [[1,1,1]]
|
||||
-- order no arr
|
||||
[[1,2,3,4]] [[1,1,1,1]]
|
||||
[[3,4,5]] [[1,1,1]]
|
||||
-- order two arr
|
||||
[[],[1,2,3,4]] [[],[1,1,1,1]]
|
||||
[[],[3,4,5]] [[],[1,1,1]]
|
||||
-- order non empt
|
||||
[[3,4,5]] [[1,1,1]]
|
||||
[[6],[1,2,3,4]] [[1],[1,1,1,1]]
|
||||
-- order
|
||||
[[],[1,2,3,4]] [[],[1,1,1,1]]
|
||||
[[3,4,5]] [[1,1,1]]
|
||||
--
|
||||
[[1,1,1,1],[1,1,1,1]]
|
||||
[[],[1,1,1,1],[1,1,1,1]]
|
||||
[[],[1,1,1,1],[],[],[1,1,1,1]]
|
||||
[[1,1,1,1],[],[],[1,1,1,1]]
|
||||
[[1],[1]]
|
||||
[[],[1],[1]]
|
||||
[[],[4]] [[],[1]]
|
||||
[[4]] [[1]]
|
||||
--
|
||||
[[],[1,2,3,4]] [[],[1,1,1,1]]
|
||||
[[],[3,4,5]] [[],[1,1,1]]
|
||||
--
|
||||
[[],[1,2,3,4]] [[],[1,1,1,1]]
|
||||
[[3,4,5]] [[1,1,1]]
|
||||
--
|
||||
[[],[],[1,2,3,4]] [[],[],[1,1,1,1]]
|
||||
[[3,4,5]] [[1,1,1]]
|
||||
--
|
||||
[[],[],[1,2,3,4]] [[],[],[1,1,1,1]]
|
||||
[[],[],[3,4,5]] [[],[],[1,1,1]]
|
||||
--
|
||||
[[],[],[1,2,1,4]] [[],[],[1,1,2,1]]
|
||||
[[],[],[3,4,5,4]] [[],[],[1,1,1,2]]
|
||||
--
|
||||
|
@ -180,3 +180,44 @@ SELECT arrayEnumerateDenseRanked(1.1, [10,20,10,30]); -- { serverError 170 }
|
||||
SELECT arrayEnumerateDenseRanked([10,20,10,30], 0.4); -- { serverError 170 }
|
||||
SELECT arrayEnumerateDenseRanked([10,20,10,30], 1.8); -- { serverError 170 }
|
||||
SELECT arrayEnumerateUniqRanked(1, [], 1000000000); -- { serverError 36 }
|
||||
|
||||
|
||||
-- skipping empty arrays
|
||||
SELECT arrayEnumerateUniqRanked(2, [[3], [3]]);
|
||||
SELECT arrayEnumerateUniqRanked(2, [[], [3], [3]]);
|
||||
SELECT arrayEnumerateUniqRanked(2, [[], [], [], [3], [], [3]]);
|
||||
SELECT arrayEnumerateUniqRanked(2, [[], [], [], [], [3], [3]]);
|
||||
SELECT arrayEnumerateUniqRanked(2, [[3], [], [3]]);
|
||||
SELECT arrayEnumerateUniqRanked(2, [[3], [], [], [3]]);
|
||||
SELECT arrayEnumerateUniqRanked(2, [[3], [], [], [3], [3]]);
|
||||
|
||||
|
||||
select '-- no order';
|
||||
SELECT * FROM (SELECT a, arrayEnumerateUniqRanked(a) FROM ( SELECT * FROM ( SELECT [[], [1, 2, 3, 4]] AS a UNION ALL SELECT [[3, 4, 5]] AS a ) ) ) ORDER BY a ASC;
|
||||
select '-- order no arr';
|
||||
SELECT a, arrayEnumerateUniqRanked(a) FROM ( SELECT * FROM ( SELECT [[1, 2, 3, 4]] AS a UNION ALL SELECT [[3, 4, 5]] AS a ) ORDER BY a ASC );
|
||||
select '-- order two arr';
|
||||
SELECT a, arrayEnumerateUniqRanked(a) FROM ( SELECT * FROM ( SELECT [[], [1, 2, 3, 4]] AS a UNION ALL SELECT [[], [3, 4, 5]] AS a ) ORDER BY a ASC );
|
||||
select '-- order non empt';
|
||||
SELECT a, arrayEnumerateUniqRanked(a) FROM ( SELECT * FROM ( SELECT [[6], [1, 2, 3, 4]] AS a UNION ALL SELECT [[3, 4, 5]] AS a ) ORDER BY a ASC );
|
||||
select '-- order';
|
||||
SELECT a, arrayEnumerateUniqRanked(a) FROM ( SELECT * FROM ( SELECT [[], [1, 2, 3, 4]] AS a UNION ALL SELECT [[3, 4, 5]] AS a ) ORDER BY a ASC );
|
||||
select '-- ';
|
||||
SELECT arrayEnumerateUniqRanked(2,[[1, 2, 3, 4], [3, 4, 5, 6]]);
|
||||
SELECT arrayEnumerateUniqRanked(2, [[], [1, 2, 3, 4], [3, 4, 5, 6]]);
|
||||
SELECT arrayEnumerateUniqRanked(2, [[], [1, 2, 3, 4], [], [], [3, 4, 5, 6]]);
|
||||
SELECT arrayEnumerateUniqRanked(2, [[1, 2, 3, 4], [], [], [3, 4, 5, 6]]);
|
||||
SELECT arrayEnumerateUniqRanked(2,[[1], [1]]);
|
||||
SELECT arrayEnumerateUniqRanked(2, [[], [1], [1]]);
|
||||
SELECT a, arrayEnumerateUniqRanked(a) FROM ( SELECT * FROM ( SELECT [[], [4]] AS a UNION ALL SELECT [[4]] AS a ) ORDER BY a ASC );
|
||||
select '-- ';
|
||||
SELECT a, arrayEnumerateUniqRanked(a) FROM ( SELECT * FROM ( SELECT [[], [1, 2, 3, 4]] AS a UNION ALL SELECT [[], [3, 4, 5]] AS a ) ORDER BY a ASC );
|
||||
select '-- ';
|
||||
SELECT a, arrayEnumerateUniqRanked(a) FROM ( SELECT * FROM ( SELECT [[], [1, 2, 3, 4]] AS a UNION ALL SELECT [[3, 4, 5]] AS a ) ORDER BY a ASC );
|
||||
select '-- ';
|
||||
SELECT a, arrayEnumerateUniqRanked(a) FROM ( SELECT * FROM ( SELECT [[], [], [1, 2, 3, 4]] AS a UNION ALL SELECT [[3, 4, 5]] AS a ) ORDER BY a ASC );
|
||||
select '-- ';
|
||||
SELECT a, arrayEnumerateUniqRanked(a) FROM ( SELECT * FROM ( SELECT [[], [], [1, 2, 3, 4]] AS a UNION ALL SELECT [[], [], [3, 4, 5]] AS a ) ORDER BY a ASC );
|
||||
select '-- ';
|
||||
SELECT a, arrayEnumerateUniqRanked(a) FROM ( SELECT * FROM ( SELECT [[], [], [1, 2, 1, 4]] AS a UNION ALL SELECT [[], [], [3, 4, 5, 4]] AS a ) ORDER BY a ASC );
|
||||
select '-- ';
|
||||
|
Loading…
Reference in New Issue
Block a user