Add geo data types point and polygon

This commit is contained in:
Alexey Ilyukhov 2020-05-05 17:40:04 +03:00
parent 4d8660f270
commit 0850d63d52
4 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,74 @@
#include <Columns/ColumnsNumber.h>
#include <Columns/ColumnTuple.h>
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/DataTypeCustom.h>
#include <DataTypes/DataTypeCustomSimpleTextSerialization.h>
#include <DataTypes/DataTypeFactory.h>
#include <DataTypes/DataTypeTuple.h>
#include <DataTypes/DataTypesNumber.h>
namespace DB
{
namespace
{
class DataTypeCustomPointSerialization : public DataTypeCustomSimpleTextSerialization
{
private:
DataTypePtr tuple;
public:
DataTypeCustomPointSerialization() : tuple(std::make_unique<DataTypeTuple>(
DataTypes({std::make_unique<DataTypeFloat64>(), std::make_unique<DataTypeFloat64>()})))
{}
void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override
{
tuple->serializeAsText(column, row_num, ostr, settings);
}
void deserializeText(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override
{
tuple->deserializeAsWholeText(column, istr, settings);
}
};
class DataTypeCustomPolygonSerialization : public DataTypeCustomSimpleTextSerialization
{
private:
DataTypePtr array;
public:
DataTypeCustomPolygonSerialization() : array(std::make_unique<DataTypeArray>(std::make_unique<DataTypeArray>(std::make_unique<DataTypeTuple>(
DataTypes({std::make_unique<DataTypeFloat64>(), std::make_unique<DataTypeFloat64>()})))))
{}
void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override
{
array->serializeAsText(column, row_num, ostr, settings);
}
void deserializeText(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override
{
array->deserializeAsWholeText(column, istr, settings);
}
};
}
void registerDataTypeDomainGeo(DataTypeFactory & factory) {
factory.registerSimpleDataTypeCustom("Point", []
{
return std::make_pair(DataTypeFactory::instance().get("Tuple(Float64, Float64)"),
std::make_unique<DataTypeCustomDesc>(std::make_unique<DataTypeCustomFixedName>("Point"), std::make_unique<DataTypeCustomPointSerialization>()));
});
factory.registerSimpleDataTypeCustom("Polygon", []
{
return std::make_pair(DataTypeFactory::instance().get("Array(Array(Tuple(Float64, Float64)))"),
std::make_unique<DataTypeCustomDesc>(std::make_unique<DataTypeCustomFixedName>("Polygon"), std::make_unique<DataTypeCustomPolygonSerialization>()));
});
}
}

View File

@ -180,6 +180,7 @@ DataTypeFactory::DataTypeFactory()
registerDataTypeLowCardinality(*this); registerDataTypeLowCardinality(*this);
registerDataTypeDomainIPv4AndIPv6(*this); registerDataTypeDomainIPv4AndIPv6(*this);
registerDataTypeDomainSimpleAggregateFunction(*this); registerDataTypeDomainSimpleAggregateFunction(*this);
registerDataTypeDomainGeo(*this);
} }
DataTypeFactory & DataTypeFactory::instance() DataTypeFactory & DataTypeFactory::instance()

View File

@ -83,5 +83,6 @@ void registerDataTypeLowCardinality(DataTypeFactory & factory);
void registerDataTypeDomainIPv4AndIPv6(DataTypeFactory & factory); void registerDataTypeDomainIPv4AndIPv6(DataTypeFactory & factory);
void registerDataTypeDomainSimpleAggregateFunction(DataTypeFactory & factory); void registerDataTypeDomainSimpleAggregateFunction(DataTypeFactory & factory);
void registerDataTypeDateTime64(DataTypeFactory & factory); void registerDataTypeDateTime64(DataTypeFactory & factory);
void registerDataTypeDomainGeo(DataTypeFactory & factory);
} }

View File

@ -10,6 +10,7 @@ SRCS(
DataTypeAggregateFunction.cpp DataTypeAggregateFunction.cpp
DataTypeArray.cpp DataTypeArray.cpp
DataTypeCustomIPv4AndIPv6.cpp DataTypeCustomIPv4AndIPv6.cpp
DataTypeCustomPoint.cpp
DataTypeCustomSimpleAggregateFunction.cpp DataTypeCustomSimpleAggregateFunction.cpp
DataTypeCustomSimpleTextSerialization.cpp DataTypeCustomSimpleTextSerialization.cpp
DataTypeDate.cpp DataTypeDate.cpp