Fix incorrect character counting in PositionImpl::vectorVector

This commit is contained in:
heymind 2024-10-24 14:09:56 +08:00
parent 4c0ce6ad10
commit 53b82efaea
3 changed files with 11 additions and 2 deletions

View File

@ -371,9 +371,13 @@ struct PositionImpl
size_t needle_size = needle_offsets[i] - prev_needle_offset - 1;
size_t haystack_size = haystack_offsets[i] - prev_haystack_offset - 1;
size_t haystack_chars_size = Impl::countChars(
reinterpret_cast<const char *>(&haystack_data[prev_haystack_offset]),
reinterpret_cast<const char *>(&haystack_data[haystack_offsets[i] - 1]));
auto start = start_pos != nullptr ? std::max(start_pos->getUInt(i), UInt64(1)) : UInt64(1);
if (start > haystack_size + 1)
if (start > haystack_chars_size + 1)
{
res[i] = 0;
}
@ -429,13 +433,15 @@ struct PositionImpl
/// NOTE You could use haystack indexing. But this is a rare case.
ColumnString::Offset prev_needle_offset = 0;
size_t haystack_size = Impl::countChars(haystack.data(), haystack.data() + haystack.size());
for (size_t i = 0; i < input_rows_count; ++i)
{
size_t needle_size = needle_offsets[i] - prev_needle_offset - 1;
auto start = start_pos != nullptr ? std::max(start_pos->getUInt(i), UInt64(1)) : UInt64(1);
if (start > haystack.size() + 1)
if (start > haystack_size + 1)
{
res[i] = 0;
}

View File

@ -7306,3 +7306,4 @@
1
1
1
1

View File

@ -486,3 +486,5 @@ select 1 = position('abc', materialize('')) from system.numbers limit 1000;
select 1 = position('abab', materialize('ab'));
select 1 = position('abababababababababababab', materialize('abab'));
select 1 = position('abababababababababababab', materialize('abababababababababa'));
select positionUTF8('', '', 3) = positionUTF8(materialize(''), materialize(''), materialize(3));