mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
tupleElement(): Return default value for out-of-bounds-index
Makes the actual and the documented behavior consistent.
This commit is contained in:
parent
eea3c39959
commit
bf54fb4caa
@ -203,13 +203,15 @@ private:
|
||||
{
|
||||
const size_t index = index_column->getUInt(0);
|
||||
|
||||
if (index == 0)
|
||||
throw Exception(ErrorCodes::ILLEGAL_INDEX, "Indices in tuples are 1-based.");
|
||||
|
||||
if (index > tuple.getElements().size())
|
||||
throw Exception(ErrorCodes::ILLEGAL_INDEX, "Index for tuple element is out of range.");
|
||||
|
||||
if (index > 0 && index <= tuple.getElements().size())
|
||||
return {index - 1};
|
||||
else
|
||||
{
|
||||
if (argument_size == 2)
|
||||
throw Exception(ErrorCodes::NOT_FOUND_COLUMN_IN_BLOCK, "Tuple doesn't have element with index '{}'", index);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
}
|
||||
else if (const auto * name_col = checkAndGetColumnConst<ColumnString>(index_column.get()))
|
||||
{
|
||||
|
@ -7,6 +7,8 @@ FROM t_tuple_element_default
|
||||
z
|
||||
SELECT tupleElement(t2, \'z\', \'z\')
|
||||
FROM t_tuple_element_default
|
||||
z
|
||||
z
|
||||
--------------------
|
||||
[(3,4)]
|
||||
SELECT tupleElement([(1, 2)], \'a\', [(3, 4)])
|
||||
|
@ -10,8 +10,8 @@ EXPLAIN SYNTAX SELECT tupleElement(t1, 'z', 0) FROM t_tuple_element_default;
|
||||
SELECT tupleElement(t2, 'z', 'z') FROM t_tuple_element_default;
|
||||
EXPLAIN SYNTAX SELECT tupleElement(t2, 'z', 'z') FROM t_tuple_element_default;
|
||||
|
||||
SELECT tupleElement(t1, 3, 'z') FROM t_tuple_element_default; -- { serverError ILLEGAL_INDEX }
|
||||
SELECT tupleElement(t1, 0, 'z') FROM t_tuple_element_default; -- { serverError ILLEGAL_INDEX }
|
||||
SELECT tupleElement(t1, 3, 'z') FROM t_tuple_element_default;
|
||||
SELECT tupleElement(t1, 0, 'z') FROM t_tuple_element_default;
|
||||
|
||||
DROP TABLE t_tuple_element_default;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user