2017-07-04 10:42:53 +00:00
|
|
|
#include <DataTypes/DataTypeUUID.h>
|
2017-07-16 03:05:40 +00:00
|
|
|
#include <DataTypes/DataTypeFactory.h>
|
2018-09-20 20:21:29 +00:00
|
|
|
#include <Columns/ColumnsNumber.h>
|
2019-02-19 20:01:31 +00:00
|
|
|
#include <Formats/ProtobufReader.h>
|
2019-01-23 19:41:18 +00:00
|
|
|
#include <Formats/ProtobufWriter.h>
|
2018-09-20 20:21:29 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
#include <IO/ReadHelpers.h>
|
2019-08-21 02:28:04 +00:00
|
|
|
#include <Common/assert_cast.h>
|
2017-07-16 03:05:40 +00:00
|
|
|
|
2017-06-15 09:12:32 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-06-05 21:39:01 +00:00
|
|
|
void DataTypeUUID::serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const
|
2017-07-16 03:05:40 +00:00
|
|
|
{
|
2019-08-21 02:28:04 +00:00
|
|
|
writeText(UUID(assert_cast<const ColumnUInt128 &>(column).getData()[row_num]), ostr);
|
2017-07-16 03:05:40 +00:00
|
|
|
}
|
2017-06-15 09:12:32 +00:00
|
|
|
|
2018-09-18 13:28:46 +00:00
|
|
|
void DataTypeUUID::deserializeTextEscaped(IColumn & column, ReadBuffer & istr, const FormatSettings &) const
|
2017-07-16 03:05:40 +00:00
|
|
|
{
|
|
|
|
UUID x;
|
|
|
|
readText(x, istr);
|
2019-08-21 02:28:04 +00:00
|
|
|
assert_cast<ColumnUInt128 &>(column).getData().push_back(x);
|
2017-07-16 03:05:40 +00:00
|
|
|
}
|
2017-06-15 09:12:32 +00:00
|
|
|
|
2018-06-08 01:51:55 +00:00
|
|
|
void DataTypeUUID::serializeTextEscaped(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const
|
2017-07-16 03:05:40 +00:00
|
|
|
{
|
2018-06-08 01:51:55 +00:00
|
|
|
serializeText(column, row_num, ostr, settings);
|
2017-07-16 03:05:40 +00:00
|
|
|
}
|
2017-06-15 09:12:32 +00:00
|
|
|
|
2018-06-08 01:51:55 +00:00
|
|
|
void DataTypeUUID::serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const
|
2017-07-16 03:05:40 +00:00
|
|
|
{
|
|
|
|
writeChar('\'', ostr);
|
2018-06-08 01:51:55 +00:00
|
|
|
serializeText(column, row_num, ostr, settings);
|
2017-07-16 03:05:40 +00:00
|
|
|
writeChar('\'', ostr);
|
|
|
|
}
|
2017-06-15 09:12:32 +00:00
|
|
|
|
2018-06-05 21:39:01 +00:00
|
|
|
void DataTypeUUID::deserializeTextQuoted(IColumn & column, ReadBuffer & istr, const FormatSettings &) const
|
2017-07-16 03:05:40 +00:00
|
|
|
{
|
|
|
|
UUID x;
|
|
|
|
assertChar('\'', istr);
|
|
|
|
readText(x, istr);
|
|
|
|
assertChar('\'', istr);
|
2019-08-21 02:28:04 +00:00
|
|
|
assert_cast<ColumnUInt128 &>(column).getData().push_back(x); /// It's important to do this at the end - for exception safety.
|
2017-07-16 03:05:40 +00:00
|
|
|
}
|
2017-06-15 09:12:32 +00:00
|
|
|
|
2018-06-08 01:51:55 +00:00
|
|
|
void DataTypeUUID::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const
|
2017-07-16 03:05:40 +00:00
|
|
|
{
|
|
|
|
writeChar('"', ostr);
|
2018-06-08 01:51:55 +00:00
|
|
|
serializeText(column, row_num, ostr, settings);
|
2017-07-16 03:05:40 +00:00
|
|
|
writeChar('"', ostr);
|
|
|
|
}
|
|
|
|
|
2018-06-05 21:39:01 +00:00
|
|
|
void DataTypeUUID::deserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings &) const
|
2017-07-16 03:05:40 +00:00
|
|
|
{
|
|
|
|
UUID x;
|
|
|
|
assertChar('"', istr);
|
|
|
|
readText(x, istr);
|
|
|
|
assertChar('"', istr);
|
2019-08-21 02:28:04 +00:00
|
|
|
assert_cast<ColumnUInt128 &>(column).getData().push_back(x);
|
2017-07-16 03:05:40 +00:00
|
|
|
}
|
|
|
|
|
2018-06-08 01:51:55 +00:00
|
|
|
void DataTypeUUID::serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const
|
2017-07-16 03:05:40 +00:00
|
|
|
{
|
|
|
|
writeChar('"', ostr);
|
2018-06-08 01:51:55 +00:00
|
|
|
serializeText(column, row_num, ostr, settings);
|
2017-07-16 03:05:40 +00:00
|
|
|
writeChar('"', ostr);
|
|
|
|
}
|
2017-06-15 09:12:32 +00:00
|
|
|
|
2018-06-05 21:39:01 +00:00
|
|
|
void DataTypeUUID::deserializeTextCSV(IColumn & column, ReadBuffer & istr, const FormatSettings &) const
|
2017-07-16 03:05:40 +00:00
|
|
|
{
|
|
|
|
UUID value;
|
|
|
|
readCSV(value, istr);
|
2019-08-21 02:28:04 +00:00
|
|
|
assert_cast<ColumnUInt128 &>(column).getData().push_back(value);
|
2017-07-16 03:05:40 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 14:06:05 +00:00
|
|
|
void DataTypeUUID::serializeProtobuf(const IColumn & column, size_t row_num, ProtobufWriter & protobuf, size_t & value_index) const
|
2019-01-23 19:41:18 +00:00
|
|
|
{
|
2019-02-26 14:06:05 +00:00
|
|
|
if (value_index)
|
|
|
|
return;
|
2019-08-21 02:28:04 +00:00
|
|
|
value_index = static_cast<bool>(protobuf.writeUUID(UUID(assert_cast<const ColumnUInt128 &>(column).getData()[row_num])));
|
2019-01-23 19:41:18 +00:00
|
|
|
}
|
|
|
|
|
2019-02-19 20:01:31 +00:00
|
|
|
void DataTypeUUID::deserializeProtobuf(IColumn & column, ProtobufReader & protobuf, bool allow_add_row, bool & row_added) const
|
|
|
|
{
|
|
|
|
row_added = false;
|
|
|
|
UUID uuid;
|
|
|
|
if (!protobuf.readUUID(uuid))
|
|
|
|
return;
|
|
|
|
|
2019-08-21 02:28:04 +00:00
|
|
|
auto & container = assert_cast<ColumnUInt128 &>(column).getData();
|
2019-02-19 20:01:31 +00:00
|
|
|
if (allow_add_row)
|
|
|
|
{
|
|
|
|
container.emplace_back(uuid);
|
|
|
|
row_added = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
container.back() = uuid;
|
|
|
|
}
|
2017-07-16 03:05:40 +00:00
|
|
|
|
2017-12-23 01:05:29 +00:00
|
|
|
bool DataTypeUUID::equals(const IDataType & rhs) const
|
|
|
|
{
|
|
|
|
return typeid(rhs) == typeid(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-16 03:05:40 +00:00
|
|
|
void registerDataTypeUUID(DataTypeFactory & factory)
|
|
|
|
{
|
2020-03-10 18:16:14 +00:00
|
|
|
factory.registerSimpleDataType("UUID", [] { return DataTypePtr(std::make_shared<DataTypeUUID>()); });
|
2017-07-16 03:05:40 +00:00
|
|
|
}
|
2017-06-15 09:12:32 +00:00
|
|
|
|
|
|
|
}
|