fix read extra bytes when with separator

This commit is contained in:
zhang2014 2020-06-22 21:30:55 +08:00
parent ee2ca536ff
commit b820cfb3b6
3 changed files with 23 additions and 2 deletions

View File

@ -634,12 +634,22 @@ inline bool tryReadDateText(DayNum & date, ReadBuffer & buf)
inline void readUUIDText(UUID & uuid, ReadBuffer & buf) inline void readUUIDText(UUID & uuid, ReadBuffer & buf)
{ {
char s[36]; char s[36];
size_t size = buf.read(s, 36); size_t size = buf.read(s, 32);
if (size >= 32) if (size == 32)
{ {
if (s[8] == '-') if (s[8] == '-')
{
size += buf.read(&s[32], 4);
if (size != 36)
{
s[size] = 0;
throw Exception(std::string("Cannot parse uuid ") + s, ErrorCodes::CANNOT_PARSE_UUID);
}
parseUUID<true>(reinterpret_cast<const UInt8 *>(s), std::reverse_iterator<UInt8 *>(reinterpret_cast<UInt8 *>(&uuid) + 16)); parseUUID<true>(reinterpret_cast<const UInt8 *>(s), std::reverse_iterator<UInt8 *>(reinterpret_cast<UInt8 *>(&uuid) + 16));
}
else else
parseUUID<false>(reinterpret_cast<const UInt8 *>(s), std::reverse_iterator<UInt8 *>(reinterpret_cast<UInt8 *>(&uuid) + 16)); parseUUID<false>(reinterpret_cast<const UInt8 *>(s), std::reverse_iterator<UInt8 *>(reinterpret_cast<UInt8 *>(&uuid) + 16));
} }

View File

@ -1,2 +1,4 @@
417ddc5d-e556-4d27-95dd-a34d84e46a50 417ddc5d-e556-4d27-95dd-a34d84e46a50
417ddc5d-e556-4d27-95dd-a34d84e46a50 417ddc5d-e556-4d27-95dd-a34d84e46a50
1 417ddc5d-e556-4d27-95dd-a34d84e46a50 Example 1
2 417ddc5d-e556-4d27-95dd-a34d84e46a51 Example 2

View File

@ -1,2 +1,11 @@
SELECT toUUID('417ddc5de5564d2795dda34d84e46a50'); SELECT toUUID('417ddc5de5564d2795dda34d84e46a50');
SELECT toUUID('417ddc5d-e556-4d27-95dd-a34d84e46a50'); SELECT toUUID('417ddc5d-e556-4d27-95dd-a34d84e46a50');
DROP TABLE IF EXISTS t_uuid;
CREATE TABLE t_uuid (x UInt8, y UUID, z String) ENGINE = TinyLog;
INSERT INTO t_uuid VALUES (1, '417ddc5de5564d2795dda34d84e46a50', 'Example 1');
INSERT INTO t_uuid VALUES (2, '417ddc5d-e556-4d27-95dd-a34d84e46a51', 'Example 2');
SELECT * FROM t_uuid ORDER BY x ASC;
DROP TABLE IF EXISTS t_uuid;