Fixed error with ARRAY JOIN of arrays of strings [#METR-21863].

This commit is contained in:
Alexey Milovidov 2016-06-28 22:43:32 +03:00
parent aafe85e474
commit 4c73eea3a8
3 changed files with 27 additions and 10 deletions

View File

@ -361,16 +361,14 @@ ColumnPtr ColumnArray::replicateString(const Offsets_t & replicate_offsets) cons
size_t size_to_replicate = replicate_offsets[i] - prev_replicate_offset;
/// Количество строк в массиве.
size_t value_size = src_offsets[i] - prev_src_offset;
size_t sum_chars_size = 0;
/// Количество символов в строках массива, включая нулевые байты.
size_t sum_chars_size = value_size == 0 ? 0 : (src_string_offsets[prev_src_offset + value_size - 1] - prev_src_string_offset);
for (size_t j = 0; j < size_to_replicate; ++j)
{
current_res_offset += value_size;
res_offsets.push_back(current_res_offset);
sum_chars_size = 0;
size_t prev_src_string_offset_local = prev_src_string_offset;
for (size_t k = 0; k < value_size; ++k)
{
@ -380,14 +378,13 @@ ColumnPtr ColumnArray::replicateString(const Offsets_t & replicate_offsets) cons
current_res_string_offset += chars_size;
res_string_offsets.push_back(current_res_string_offset);
/// Копирование символов одной строки.
res_chars.resize(res_chars.size() + chars_size);
memcpySmallAllowReadWriteOverflow15(
&res_chars[res_chars.size() - chars_size], &src_chars[prev_src_string_offset_local], chars_size);
sum_chars_size += chars_size;
prev_src_string_offset_local += chars_size;
}
/// Копирование символов массива строк.
res_chars.resize(res_chars.size() + sum_chars_size);
memcpySmallAllowReadWriteOverflow15(
&res_chars[res_chars.size() - sum_chars_size], &src_chars[prev_src_string_offset], sum_chars_size);
}
prev_replicate_offset = replicate_offsets[i];

View File

@ -0,0 +1,2 @@
['']
['abc']

View File

@ -0,0 +1,18 @@
DROP TABLE IF EXISTS test.bad_arrays;
CREATE TABLE test.bad_arrays (a Array(String), b Array(UInt8)) ENGINE = Memory;
INSERT INTO test.bad_arrays VALUES ([''],[]),([''],[1]);
SELECT a FROM test.bad_arrays ARRAY JOIN b;
DROP TABLE test.bad_arrays;
DROP TABLE IF EXISTS test.bad_arrays;
CREATE TABLE test.bad_arrays (a Array(String), b Array(String)) ENGINE = Memory;
INSERT INTO test.bad_arrays VALUES ([''],[]),([''],[]),([''],[]),([''],[]),([''],[]),([''],[]),([''],[]),([''],[]),([''],[]),(['abc'],['223750']),(['ноутбук acer aspire e5-532-p3p2'],[]),([''],[]),([''],[]),([''],[]),([''],[]),(['лучшие моноблоки 2016'],[]),(['лучшие моноблоки 2016'],[]),([''],[]),([''],[]);
SELECT a FROM test.bad_arrays ARRAY JOIN b;
DROP TABLE test.bad_arrays;