mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Merge pull request #40034 from CurtizJ/fix-parsing-arrays-of-tuples
Fix parsing of tuples in case of errors
This commit is contained in:
commit
c746dcd644
@ -56,7 +56,9 @@ ColumnArray::ColumnArray(MutableColumnPtr && nested_column, MutableColumnPtr &&
|
||||
|
||||
/// This will also prevent possible overflow in offset.
|
||||
if (data->size() != last_offset)
|
||||
throw Exception("offsets_column has data inconsistent with nested_column", ErrorCodes::LOGICAL_ERROR);
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
||||
"offsets_column has data inconsistent with nested_column. Data size: {}, last offset: {}",
|
||||
data->size(), last_offset);
|
||||
}
|
||||
|
||||
/** NOTE
|
||||
|
@ -135,20 +135,21 @@ void SerializationTuple::deserializeText(IColumn & column, ReadBuffer & istr, co
|
||||
}
|
||||
elems[i]->deserializeTextQuoted(extractElementColumn(column, i), istr, settings);
|
||||
}
|
||||
});
|
||||
|
||||
// Special format for one element tuple (1,)
|
||||
if (1 == elems.size())
|
||||
{
|
||||
// Special format for one element tuple (1,)
|
||||
if (1 == elems.size())
|
||||
{
|
||||
skipWhitespaceIfAny(istr);
|
||||
// Allow both (1) and (1,)
|
||||
checkChar(',', istr);
|
||||
}
|
||||
|
||||
skipWhitespaceIfAny(istr);
|
||||
// Allow both (1) and (1,)
|
||||
checkChar(',', istr);
|
||||
}
|
||||
skipWhitespaceIfAny(istr);
|
||||
assertChar(')', istr);
|
||||
assertChar(')', istr);
|
||||
|
||||
if (whole && !istr.eof())
|
||||
throwUnexpectedDataAfterParsedValue(column, istr, settings, "Tuple");
|
||||
if (whole && !istr.eof())
|
||||
throwUnexpectedDataAfterParsedValue(column, istr, settings, "Tuple");
|
||||
});
|
||||
}
|
||||
|
||||
void SerializationTuple::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const
|
||||
@ -213,19 +214,18 @@ void SerializationTuple::deserializeTextJSON(IColumn & column, ReadBuffer & istr
|
||||
auto & element_column = extractElementColumn(column, element_pos);
|
||||
elems[element_pos]->deserializeTextJSON(element_column, istr, settings);
|
||||
}
|
||||
});
|
||||
|
||||
skipWhitespaceIfAny(istr);
|
||||
assertChar('}', istr);
|
||||
skipWhitespaceIfAny(istr);
|
||||
assertChar('}', istr);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
const size_t size = elems.size();
|
||||
assertChar('[', istr);
|
||||
|
||||
addElementSafe(elems.size(), column, [&]
|
||||
{
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
for (size_t i = 0; i < elems.size(); ++i)
|
||||
{
|
||||
skipWhitespaceIfAny(istr);
|
||||
if (i != 0)
|
||||
@ -235,10 +235,10 @@ void SerializationTuple::deserializeTextJSON(IColumn & column, ReadBuffer & istr
|
||||
}
|
||||
elems[i]->deserializeTextJSON(extractElementColumn(column, i), istr, settings);
|
||||
}
|
||||
});
|
||||
|
||||
skipWhitespaceIfAny(istr);
|
||||
assertChar(']', istr);
|
||||
skipWhitespaceIfAny(istr);
|
||||
assertChar(']', istr);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,3 @@
|
||||
1 [[]]
|
||||
2 [[(500,246)]]
|
||||
3 [[(500,10)]]
|
14
tests/queries/0_stateless/02381_parse_array_of_tuples.sql
Normal file
14
tests/queries/0_stateless/02381_parse_array_of_tuples.sql
Normal file
@ -0,0 +1,14 @@
|
||||
DROP TABLE IF EXISTS t_parse_tuples;
|
||||
|
||||
CREATE TABLE t_parse_tuples
|
||||
(
|
||||
id UInt32,
|
||||
arr Array(Array(Tuple(c1 Int32, c2 UInt8)))
|
||||
)
|
||||
ENGINE = Memory;
|
||||
|
||||
INSERT INTO t_parse_tuples VALUES (1, [[]]), (2, [[(500, -10)]]), (3, [[(500, '10')]]);
|
||||
|
||||
SELECT * FROM t_parse_tuples ORDER BY id;
|
||||
|
||||
DROP TABLE IF EXISTS t_parse_tuples;
|
Loading…
Reference in New Issue
Block a user