Merge pull request #7747 from hczhcz/patch-1113

Fix empty array handling in arraySplit
This commit is contained in:
alexey-milovidov 2019-12-03 04:00:31 +03:00 committed by GitHub
commit edede563c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 12 deletions

View File

@ -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 <typename T>
T getValue() const { return getField().safeGet<NearestFieldType<T>>(); }
};

View File

@ -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());
}
}
}

View File

@ -6,8 +6,10 @@
[[1],[2],[3],[4],[5]]
[[1,2],[3,4],[5]]
[[1],[2,3],[4,5]]
[[]]
[[]]
[]
[]
[]
[]
[]
[]
[[1]]

View File

@ -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]);