From 79a27ece1a9654bc66596dabefe882be6ce41b71 Mon Sep 17 00:00:00 2001 From: hcz Date: Mon, 21 Oct 2019 11:19:11 +0800 Subject: [PATCH] Flip the condition column in arrayFill --- dbms/src/Functions/array/arrayFill.cpp | 40 +++++++++---------- .../0_stateless/01019_array_fill.reference | 8 ++-- .../queries/0_stateless/01019_array_fill.sql | 8 ++-- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/dbms/src/Functions/array/arrayFill.cpp b/dbms/src/Functions/array/arrayFill.cpp index 4c2dc5659b8..1b6d72027e0 100644 --- a/dbms/src/Functions/array/arrayFill.cpp +++ b/dbms/src/Functions/array/arrayFill.cpp @@ -47,6 +47,8 @@ struct ArrayFillImpl { if (end == array_end || fill[end + 1] != fill[begin]) { if (fill[begin]) + out_data.insertRangeFrom(in_data, begin, end + 1 - begin); + else { if constexpr (Reverse) { @@ -63,8 +65,6 @@ struct ArrayFillImpl out_data.insertManyFrom(in_data, begin - 1, end + 1 - begin); } } - else - out_data.insertRangeFrom(in_data, begin, end + 1 - begin); begin = end + 1; } @@ -81,29 +81,27 @@ struct ArrayFillImpl throw Exception("Unexpected type of cut column", ErrorCodes::ILLEGAL_COLUMN); if (column_fill_const->getValue()) - { - size_t array_begin = 0; - size_t array_end = 0; - - out_data.reserve(in_data.size()); - - for (size_t i = 0; i < in_offsets.size(); ++i) - { - array_end = in_offsets[i] - 1; - - if constexpr (Reverse) - out_data.insertManyFrom(in_data, array_end, array_end + 1 - array_begin); - else - out_data.insertManyFrom(in_data, array_begin, array_end + 1 - array_begin); - - array_begin = array_end + 1; - } - } - else return ColumnArray::create( array.getDataPtr(), array.getOffsetsPtr() ); + + size_t array_begin = 0; + size_t array_end = 0; + + out_data.reserve(in_data.size()); + + for (size_t i = 0; i < in_offsets.size(); ++i) + { + array_end = in_offsets[i] - 1; + + if constexpr (Reverse) + out_data.insertManyFrom(in_data, array_end, array_end + 1 - array_begin); + else + out_data.insertManyFrom(in_data, array_begin, array_end + 1 - array_begin); + + array_begin = array_end + 1; + } } return ColumnArray::create( diff --git a/dbms/tests/queries/0_stateless/01019_array_fill.reference b/dbms/tests/queries/0_stateless/01019_array_fill.reference index 97841f800c7..08982beb62e 100644 --- a/dbms/tests/queries/0_stateless/01019_array_fill.reference +++ b/dbms/tests/queries/0_stateless/01019_array_fill.reference @@ -1,9 +1,9 @@ -[1,2,3,11,12,13,4,5,6,14,15,16] -[1,2,3,11,12,13,4,5,6,14,15,16] [1,1,1,1,1,1,1,1,1,1,1,1] [16,16,16,16,16,16,16,16,16,16,16,16] -[1,1,1,11,12,13,13,13,13,14,15,16] -[11,11,11,11,12,13,14,14,14,14,15,16] +[1,2,3,11,12,13,4,5,6,14,15,16] +[1,2,3,11,12,13,4,5,6,14,15,16] +[1,2,3,3,3,3,4,5,6,6,6,6] +[1,2,3,4,4,4,4,5,6,16,16,16] [1,1,3,11,12,12,12,5,6,14,14,14] [1,3,3,11,12,5,5,5,6,14,NULL,NULL] [1,1,3,11,11,11,11,5,6,14,14,14] diff --git a/dbms/tests/queries/0_stateless/01019_array_fill.sql b/dbms/tests/queries/0_stateless/01019_array_fill.sql index 33e064d8cb1..af48e8d0be4 100644 --- a/dbms/tests/queries/0_stateless/01019_array_fill.sql +++ b/dbms/tests/queries/0_stateless/01019_array_fill.sql @@ -5,7 +5,7 @@ SELECT arrayReverseFill(x -> 1, [1, 2, 3, 11, 12, 13, 4, 5, 6, 14, 15, 16]); SELECT arrayFill(x -> x < 10, [1, 2, 3, 11, 12, 13, 4, 5, 6, 14, 15, 16]); SELECT arrayReverseFill(x -> x < 10, [1, 2, 3, 11, 12, 13, 4, 5, 6, 14, 15, 16]); -SELECT arrayFill(x -> isNull(x), [1, null, 3, 11, 12, null, null, 5, 6, 14, null, null]); -SELECT arrayReverseFill(x -> isNull(x), [1, null, 3, 11, 12, null, null, 5, 6, 14, null, null]); -SELECT arrayFill((x, y) -> y, [1, 2, 3, 11, 12, 13, 4, 5, 6, 14, 15, 16], [1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1]); -SELECT arrayReverseFill((x, y) -> y, [1, 2, 3, 11, 12, 13, 4, 5, 6, 14, 15, 16], [1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1]); +SELECT arrayFill(x -> not isNull(x), [1, null, 3, 11, 12, null, null, 5, 6, 14, null, null]); +SELECT arrayReverseFill(x -> not isNull(x), [1, null, 3, 11, 12, null, null, 5, 6, 14, null, null]); +SELECT arrayFill((x, y) -> y, [1, 2, 3, 11, 12, 13, 4, 5, 6, 14, 15, 16], [0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0]); +SELECT arrayReverseFill((x, y) -> y, [1, 2, 3, 11, 12, 13, 4, 5, 6, 14, 15, 16], [0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0]);