mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
improve field visitors for UUID CLICKHOUSE-3249
This commit is contained in:
parent
a5d7097c08
commit
a69c936b44
@ -1,3 +1,4 @@
|
||||
#include <Core/UUID.h>
|
||||
#include <IO/ReadBuffer.h>
|
||||
#include <IO/WriteBuffer.h>
|
||||
#include <IO/ReadHelpers.h>
|
||||
@ -12,11 +13,6 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
UInt128 stringToUUID(const String & str)
|
||||
{
|
||||
return parseFromString<UUID>(str);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static inline String formatQuoted(T x)
|
||||
{
|
||||
@ -50,14 +46,8 @@ String FieldVisitorDump::operator() (const Float64 & x) const { return formatQuo
|
||||
String FieldVisitorDump::operator() (const DecimalField<Decimal32> & x) const { return formatQuotedWithPrefix(x, "Decimal32_"); }
|
||||
String FieldVisitorDump::operator() (const DecimalField<Decimal64> & x) const { return formatQuotedWithPrefix(x, "Decimal64_"); }
|
||||
String FieldVisitorDump::operator() (const DecimalField<Decimal128> & x) const { return formatQuotedWithPrefix(x, "Decimal128_"); }
|
||||
String FieldVisitorDump::operator() (const UInt128 & x) const { return formatQuotedWithPrefix(UUID(x), "UUID_"); }
|
||||
|
||||
String FieldVisitorDump::operator() (const UInt128 & x) const
|
||||
{
|
||||
WriteBufferFromOwnString wb;
|
||||
wb << "UInt128_" << x.low << "_" << x.high;
|
||||
return wb.str();
|
||||
|
||||
}
|
||||
|
||||
String FieldVisitorDump::operator() (const String & x) const
|
||||
{
|
||||
@ -130,12 +120,7 @@ String FieldVisitorToString::operator() (const String & x) const { return format
|
||||
String FieldVisitorToString::operator() (const DecimalField<Decimal32> & x) const { return formatQuoted(x); }
|
||||
String FieldVisitorToString::operator() (const DecimalField<Decimal64> & x) const { return formatQuoted(x); }
|
||||
String FieldVisitorToString::operator() (const DecimalField<Decimal128> & x) const { return formatQuoted(x); }
|
||||
|
||||
String FieldVisitorToString::operator() (const UInt128 & x) const
|
||||
{
|
||||
/// Dummy implementation. There is no UInt128 literals in SQL.
|
||||
return FieldVisitorDump()(x);
|
||||
}
|
||||
String FieldVisitorToString::operator() (const UInt128 & x) const { return formatQuoted(UUID(x)); }
|
||||
|
||||
String FieldVisitorToString::operator() (const Array & x) const
|
||||
{
|
||||
|
@ -561,6 +561,11 @@ inline T parseFromString(const String & str)
|
||||
return parse<T>(str.data(), str.size());
|
||||
}
|
||||
|
||||
inline UInt128 stringToUUID(const String & str)
|
||||
{
|
||||
return parseFromString<UUID>(str);
|
||||
}
|
||||
|
||||
|
||||
template <typename ReturnType = void>
|
||||
ReturnType readDateTimeTextFallback(time_t & datetime, ReadBuffer & buf, const DateLUTImpl & date_lut);
|
||||
|
@ -704,13 +704,7 @@ inline void writeText(const char * x, size_t size, WriteBuffer & buf) { writeEsc
|
||||
inline void writeText(const LocalDate & x, WriteBuffer & buf) { writeDateText(x, buf); }
|
||||
inline void writeText(const LocalDateTime & x, WriteBuffer & buf) { writeDateTimeText(x, buf); }
|
||||
inline void writeText(const UUID & x, WriteBuffer & buf) { writeUUIDText(x, buf); }
|
||||
inline void writeText(const UInt128 &, WriteBuffer &)
|
||||
{
|
||||
/** Because UInt128 isn't a natural type, without arithmetic operator and only use as an intermediary type -for UUID-
|
||||
* it should never arrive here. But because we used the DataTypeNumber class we should have at least a definition of it.
|
||||
*/
|
||||
throw Exception("UInt128 cannot be write as a text", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
}
|
||||
inline void writeText(const UInt128 & x, WriteBuffer & buf) { writeText(UUID(x), buf); }
|
||||
|
||||
template <typename T> inline T decimalScaleMultiplier(UInt32 scale);
|
||||
template <> inline Int32 decimalScaleMultiplier<Int32>(UInt32 scale) { return common::exp10_i32(scale); }
|
||||
@ -763,6 +757,12 @@ inline void writeQuoted(const LocalDateTime & x, WriteBuffer & buf)
|
||||
writeChar('\'', buf);
|
||||
}
|
||||
|
||||
inline void writeQuoted(const UUID & x, WriteBuffer & buf)
|
||||
{
|
||||
writeChar('\'', buf);
|
||||
writeText(x, buf);
|
||||
writeChar('\'', buf);
|
||||
}
|
||||
|
||||
/// String, date, datetime are in double quotes with C-style escaping. Numbers - without.
|
||||
template <typename T>
|
||||
|
@ -138,19 +138,6 @@ UInt64 stringToDateTime(const String & s)
|
||||
return UInt64(date_time);
|
||||
}
|
||||
|
||||
UInt128 stringToUUID(const String & s)
|
||||
{
|
||||
ReadBufferFromString in(s);
|
||||
UUID uuid;
|
||||
|
||||
readText(uuid, in);
|
||||
if (!in.eof())
|
||||
throw Exception("String is too long for UUID: " + s);
|
||||
|
||||
return UInt128(uuid);
|
||||
}
|
||||
|
||||
|
||||
Field convertFieldToTypeImpl(const Field & src, const IDataType & type)
|
||||
{
|
||||
if (type.isValueRepresentedByNumber())
|
||||
|
Loading…
Reference in New Issue
Block a user