Merge pull request #40034 from CurtizJ/fix-parsing-arrays-of-tuples

Fix parsing of tuples in case of errors
This commit is contained in:
Anton Popov 2022-08-11 12:10:27 +02:00 committed by GitHub
commit c746dcd644
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 20 deletions

View File

@ -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

View File

@ -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);
});
}
}

View File

@ -0,0 +1,3 @@
1 [[]]
2 [[(500,246)]]
3 [[(500,10)]]

View 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;