Clamp the limit for arrayPartialShuffle

This commit is contained in:
Joanna Hulboj 2023-01-21 14:08:30 +00:00
parent b0ba8c02be
commit e1d281206f
3 changed files with 6 additions and 1 deletions

View File

@ -156,7 +156,10 @@ ColumnPtr FunctionArrayShuffleImpl<Traits>::executeGeneric(const ColumnArray & a
if constexpr (Traits::has_limit)
{
if (limit)
partial_shuffle(&permutation[current_offset], &permutation[next_offset], limit, rng);
{
const auto effective_limit = std::min(limit, next_offset - current_offset);
partial_shuffle(&permutation[current_offset], &permutation[next_offset], effective_limit, rng);
}
else
shuffle(&permutation[current_offset], &permutation[next_offset], rng);
}

View File

@ -47,6 +47,7 @@
[10,9,4,2,5,6,7,1,3,8]
[10,9,4,2,5,6,7,1,8,3]
[10,9,4,2,5,6,7,1,8,3]
[10,9,4,2,5,6,7,1,8,3]
[10.1,9,4,2,5,6,7,8,3,1]
[9223372036854775808,9,4,2,5,6,7,8,3,1]
[NULL,9,4,2,5,6,7,8,3,1]

View File

@ -47,6 +47,7 @@ SELECT arrayPartialShuffle([1,2,3,4,5,6,7,8,9,10], 4, 0xbad_cafe);
SELECT arrayPartialShuffle([1,2,3,4,5,6,7,8,9,10], 8, 0xbad_cafe);
SELECT arrayPartialShuffle([1,2,3,4,5,6,7,8,9,10], 9, 0xbad_cafe);
SELECT arrayPartialShuffle([1,2,3,4,5,6,7,8,9,10], 10, 0xbad_cafe);
SELECT arrayPartialShuffle([1,2,3,4,5,6,7,8,9,10], 100, 0xbad_cafe);
SELECT arrayPartialShuffle([1,2,3,4,5,6,7,8,9,10.1], 4, 0xbad_cafe);
SELECT arrayPartialShuffle([1,2,3,4,5,6,7,8,9,9223372036854775808], 4, 0xbad_cafe);
SELECT arrayPartialShuffle([1,2,3,4,5,6,7,8,9,NULL], 4, 0xbad_cafe);