From 889d5139ef7d6e63c2fe4278d0ebe48008e08f89 Mon Sep 17 00:00:00 2001 From: daoready Date: Tue, 18 Sep 2018 14:55:14 +0300 Subject: [PATCH 1/2] fix arrayCumSumNonNegative that it does not accumulative negative values --- dbms/src/Functions/arrayCumSumNonNegative.cpp | 10 ++++++---- .../00704_arrayCumSumLimited_arrayDifference.reference | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dbms/src/Functions/arrayCumSumNonNegative.cpp b/dbms/src/Functions/arrayCumSumNonNegative.cpp index d5b7f3b8e3d..f020de56828 100644 --- a/dbms/src/Functions/arrayCumSumNonNegative.cpp +++ b/dbms/src/Functions/arrayCumSumNonNegative.cpp @@ -55,13 +55,15 @@ struct ArrayCumSumNonNegativeImpl // skip empty arrays if (pos < offsets[i]) { - accum_sum = data[pos]; - res_values[pos] = accum_sum > 0 ? accum_sum : 0; + accum_sum = data[pos] > 0 ? data[pos] : 0; + res_values[pos] = accum_sum; for (++pos; pos < offsets[i]; ++pos) { accum_sum = accum_sum + data[pos]; - - res_values[pos] = accum_sum > 0 ? accum_sum : 0; + if(accum_sum < 0){ + accum_sum = 0; + } + res_values[pos] = accum_sum; } } } diff --git a/dbms/tests/queries/0_stateless/00704_arrayCumSumLimited_arrayDifference.reference b/dbms/tests/queries/0_stateless/00704_arrayCumSumLimited_arrayDifference.reference index 6355a1c30ab..11a07746516 100644 --- a/dbms/tests/queries/0_stateless/00704_arrayCumSumLimited_arrayDifference.reference +++ b/dbms/tests/queries/0_stateless/00704_arrayCumSumLimited_arrayDifference.reference @@ -1,8 +1,8 @@ [1,3,6,10] -[1,0,1,0] +[1,0,5,3] [0,1,1,1] [0,6,93,-95] -[1,0,0,0] +[1,0,0,1] [1,1.4,1.2999999999999998] [1,4,5] [0,-4,3,1] From 00dbf6417649e97e41a6e51e7480e594db1754b7 Mon Sep 17 00:00:00 2001 From: alexey-milovidov Date: Tue, 18 Sep 2018 19:14:01 +0300 Subject: [PATCH 2/2] Update arrayCumSumNonNegative.cpp --- dbms/src/Functions/arrayCumSumNonNegative.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbms/src/Functions/arrayCumSumNonNegative.cpp b/dbms/src/Functions/arrayCumSumNonNegative.cpp index f020de56828..3e89257375d 100644 --- a/dbms/src/Functions/arrayCumSumNonNegative.cpp +++ b/dbms/src/Functions/arrayCumSumNonNegative.cpp @@ -60,9 +60,9 @@ struct ArrayCumSumNonNegativeImpl for (++pos; pos < offsets[i]; ++pos) { accum_sum = accum_sum + data[pos]; - if(accum_sum < 0){ + if (accum_sum < 0) accum_sum = 0; - } + res_values[pos] = accum_sum; } }