Fixed multiIf in case of empty arguments. [#CLICKHOUSE-3119]

This commit is contained in:
Vitaliy Lyudvichenko 2017-07-07 13:56:58 +03:00 committed by alexey-milovidov
parent 2d478cd371
commit 7150e9447a
5 changed files with 11 additions and 33 deletions

View File

@ -400,23 +400,12 @@ private:
static size_t computeResultSize(const IArraySources<TResult> & sources, size_t row_count)
{
size_t max_var = 0;
size_t max_const = 0;
size_t max_size = 0;
for (const auto & source : sources)
{
if (source->isConst())
max_const = std::max(max_const, source->getDataSize());
else
max_var = std::max(max_var, source->getDataSize());
}
max_size = std::max(max_size, source->isConst() ? source->getDataSize() * row_count : source->getDataSize());
if (max_var > 0)
return max_var;
else if (max_const > 0)
return max_const * row_count;
else
throw Exception{"Internal error", ErrorCodes::LOGICAL_ERROR};
return max_size;
}
/// Create the result column.

View File

@ -372,12 +372,7 @@ auto computeResultSize(const StringArraySources & sources, size_t row_count)
throw Exception{"Internal error", ErrorCodes::LOGICAL_ERROR};
}
if (max_var > 0)
return std::make_tuple(max_var, max_var_string_offsets);
else if (max_const > 0)
return std::make_tuple(max_const * row_count, max_const_string_offsets * row_count);
else
throw Exception{"Internal error", ErrorCodes::LOGICAL_ERROR};
return std::make_tuple(std::max(max_var, max_const * row_count), std::max(max_var_string_offsets, max_const_string_offsets * row_count));
}
/// Create the result column.

View File

@ -427,19 +427,7 @@ size_t computeResultSize(const StringSources & sources, size_t row_count)
throw Exception{"Internal error", ErrorCodes::LOGICAL_ERROR};
}
if (max_var > 0)
{
if (max_fixed > 0)
return std::max(max_var, max_fixed + row_count);
else
return max_var;
}
else if (max_fixed > 0)
return max_fixed;
else if (max_const > 0)
return (max_const + 1) * row_count;
else
throw Exception{"Internal error", ErrorCodes::LOGICAL_ERROR};
return std::max(max_var, std::max(max_fixed + row_count, (max_const + 1) * row_count));
}
/// Updates a fixed or variable string sink.

View File

@ -3,6 +3,9 @@ A
A\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
[1,2]
['A','B']
[]
[]
1
3
1

View File

@ -6,6 +6,9 @@ SELECT multiIf(1, 'A', 1, 'BC', 'DEF');
SELECT multiIf(1, toFixedString('A', 16), 1, toFixedString('BC', 16), toFixedString('DEF', 16));
SELECT multiIf(1, [1,2], 1, [3,4], [5,6]);
SELECT multiIf(1, ['A', 'B'], 1, ['C', 'D'], ['E', 'F']);
SELECT multiIf(rand() % 2 = 0, emptyArrayString(), emptyArrayString());
SELECT multiIf(rand() % 2 = 0, emptyArrayUInt8(), emptyArrayUInt8());
SELECT multiIf(rand() % 2 = 0, '', '');
/* Numeric branches */