From 11960bbaf99332c504f32e5186c72fd1721559e9 Mon Sep 17 00:00:00 2001 From: hcz Date: Wed, 13 Nov 2019 10:41:23 +0800 Subject: [PATCH 1/3] Fix empty array handling --- dbms/src/Functions/array/arraySplit.cpp | 32 +++++++++++++++++-------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/dbms/src/Functions/array/arraySplit.cpp b/dbms/src/Functions/array/arraySplit.cpp index 19bc599f856..c23f3b0af21 100644 --- a/dbms/src/Functions/array/arraySplit.cpp +++ b/dbms/src/Functions/array/arraySplit.cpp @@ -37,20 +37,24 @@ struct ArraySplitImpl size_t pos = 0; - out_offsets_2.reserve(in_offsets.size()); // the actual size would be equal or larger + out_offsets_2.reserve(in_offsets.size()); // assume the actual size to be equal or larger out_offsets_1.reserve(in_offsets.size()); for (size_t i = 0; i < in_offsets.size(); ++i) { - pos += !reverse; - for (; pos < in_offsets[i] - reverse; ++pos) + if (pos < in_offsets[i]) { - if (cut[pos]) - out_offsets_2.push_back(pos + reverse); - } - pos += reverse; + pos += !reverse; + for (; pos < in_offsets[i] - reverse; ++pos) + { + if (cut[pos]) + out_offsets_2.push_back(pos + reverse); + } + pos += reverse; + + out_offsets_2.push_back(pos); + } - out_offsets_2.push_back(pos); out_offsets_1.push_back(out_offsets_2.size()); } } @@ -73,13 +77,21 @@ struct ArraySplitImpl } else { + size_t pos = 0; + out_offsets_2.reserve(in_offsets.size()); out_offsets_1.reserve(in_offsets.size()); for (size_t i = 0; i < in_offsets.size(); ++i) { - out_offsets_2.push_back(in_offsets[i]); - out_offsets_1.push_back(i + 1); + if (pos < in_offsets[i]) + { + pos = in_offsets[i]; + + out_offsets_2.push_back(pos); + } + + out_offsets_1.push_back(out_offsets_2.size()); } } } From 08f8bbf52ef802bdf3908c2f2183ac8c5f563d45 Mon Sep 17 00:00:00 2001 From: hcz Date: Wed, 13 Nov 2019 11:00:08 +0800 Subject: [PATCH 2/3] Update tests --- dbms/tests/queries/0_stateless/01015_array_split.reference | 6 ++++-- dbms/tests/queries/0_stateless/01015_array_split.sql | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dbms/tests/queries/0_stateless/01015_array_split.reference b/dbms/tests/queries/0_stateless/01015_array_split.reference index ea9d36a95b2..652e7ccc43c 100644 --- a/dbms/tests/queries/0_stateless/01015_array_split.reference +++ b/dbms/tests/queries/0_stateless/01015_array_split.reference @@ -6,8 +6,10 @@ [[1],[2],[3],[4],[5]] [[1,2],[3,4],[5]] [[1],[2,3],[4,5]] -[[]] -[[]] +[] +[] +[] +[] [] [] [[1]] diff --git a/dbms/tests/queries/0_stateless/01015_array_split.sql b/dbms/tests/queries/0_stateless/01015_array_split.sql index 64d456ed724..8ae96ba01e6 100644 --- a/dbms/tests/queries/0_stateless/01015_array_split.sql +++ b/dbms/tests/queries/0_stateless/01015_array_split.sql @@ -12,6 +12,8 @@ SELECT arraySplit(x -> 0, []); SELECT arrayReverseSplit(x -> 0, []); SELECT arraySplit(x -> 1, []); SELECT arrayReverseSplit(x -> 1, []); +SELECT arraySplit(x -> x, emptyArrayUInt8()); +SELECT arrayReverseSplit(x -> x, emptyArrayUInt8()); SELECT arraySplit(x -> x % 2 = 1, [1]); SELECT arrayReverseSplit(x -> x % 2 = 1, [1]); From 5e45a4f3cd6f542089df32dd2934cac359d0b5e3 Mon Sep 17 00:00:00 2001 From: hcz Date: Fri, 29 Nov 2019 14:50:36 +0800 Subject: [PATCH 3/3] Add comment on getValue() function --- dbms/src/Columns/ColumnConst.h | 1 + 1 file changed, 1 insertion(+) diff --git a/dbms/src/Columns/ColumnConst.h b/dbms/src/Columns/ColumnConst.h index 5da6cc59527..5fdf9db1ab2 100644 --- a/dbms/src/Columns/ColumnConst.h +++ b/dbms/src/Columns/ColumnConst.h @@ -219,6 +219,7 @@ public: Field getField() const { return getDataColumn()[0]; } + /// The constant value. It is valid even if the size of the column is 0. template T getValue() const { return getField().safeGet>(); } };