mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Merge pull request #7747 from hczhcz/patch-1113
Fix empty array handling in arraySplit
This commit is contained in:
commit
edede563c9
@ -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>>(); }
|
||||
};
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,10 @@
|
||||
[[1],[2],[3],[4],[5]]
|
||||
[[1,2],[3,4],[5]]
|
||||
[[1],[2,3],[4,5]]
|
||||
[[]]
|
||||
[[]]
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
[[1]]
|
||||
|
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user