|
| 1 | +#include "geo.h" |
| 2 | + |
| 3 | +#include "utils.h" |
| 4 | + |
| 5 | +namespace { |
| 6 | +using namespace ::clickhouse; |
| 7 | + |
| 8 | +template <Type::Code type_code> |
| 9 | +TypeRef CreateGeoType() { |
| 10 | + if constexpr (type_code == Type::Code::Point) { |
| 11 | + return Type::CreatePoint(); |
| 12 | + } else if constexpr (type_code == Type::Code::Ring) { |
| 13 | + return Type::CreateRing(); |
| 14 | + } else if constexpr (type_code == Type::Code::Polygon) { |
| 15 | + return Type::CreatePolygon(); |
| 16 | + } else if constexpr (type_code == Type::Code::MultiPolygon) { |
| 17 | + return Type::CreateMultiPolygon(); |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +template <typename ColumnType> |
| 22 | +std::shared_ptr<ColumnType> CreateColumn() { |
| 23 | + if constexpr (std::is_same_v<ColumnType, ColumnTupleT<ColumnFloat64, ColumnFloat64>>) { |
| 24 | + return std::make_shared<ColumnTupleT<ColumnFloat64, ColumnFloat64>>( |
| 25 | + std::make_tuple(std::make_shared<ColumnFloat64>(), std::make_shared<ColumnFloat64>())); |
| 26 | + } else { |
| 27 | + return std::make_shared<ColumnType>(); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +} // namespace |
| 32 | + |
| 33 | +namespace clickhouse { |
| 34 | + |
| 35 | +template <typename NestedColumnType, Type::Code type_code> |
| 36 | +ColumnGeo<NestedColumnType, type_code>::ColumnGeo() |
| 37 | + : Column(std::move(CreateGeoType<type_code>())), |
| 38 | + data_(std::move(CreateColumn<NestedColumnType>())) { |
| 39 | +} |
| 40 | + |
| 41 | +template <typename NestedColumnType, Type::Code type_code> |
| 42 | +ColumnGeo<NestedColumnType, type_code>::ColumnGeo(ColumnRef data) |
| 43 | + : Column(std::move(CreateGeoType<type_code>())) |
| 44 | + , data_(std::move(WrapColumn<NestedColumnType>(std::move(data)))) { |
| 45 | +} |
| 46 | + |
| 47 | +template <typename NestedColumnType, Type::Code type_code> |
| 48 | +void ColumnGeo<NestedColumnType, type_code>::Clear() { |
| 49 | + data_->Clear(); |
| 50 | +} |
| 51 | + |
| 52 | +template <typename NestedColumnType, Type::Code type_code> |
| 53 | +const typename ColumnGeo<NestedColumnType, type_code>::ValueType ColumnGeo<NestedColumnType, type_code>::At(size_t n) const { |
| 54 | + return data_->At(n); |
| 55 | +} |
| 56 | + |
| 57 | +template <typename NestedColumnType, Type::Code type_code> |
| 58 | +const typename ColumnGeo<NestedColumnType, type_code>::ValueType ColumnGeo<NestedColumnType, type_code>::operator[](size_t n) const { |
| 59 | + return data_->At(n); |
| 60 | +} |
| 61 | + |
| 62 | +template <typename NestedColumnType, Type::Code type_code> |
| 63 | +void ColumnGeo<NestedColumnType, type_code>::Append(ColumnRef column) { |
| 64 | + if (auto col = column->template As<ColumnGeo>()) { |
| 65 | + data_->Append(col->data_->template As<Column>()); |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +template <typename NestedColumnType, Type::Code type_code> |
| 70 | +bool ColumnGeo<NestedColumnType, type_code>::LoadBody(InputStream* input, size_t rows) { |
| 71 | + return data_->LoadBody(input, rows); |
| 72 | +} |
| 73 | + |
| 74 | +template <typename NestedColumnType, Type::Code type_code> |
| 75 | +void ColumnGeo<NestedColumnType, type_code>::SaveBody(OutputStream* output) { |
| 76 | + data_->SaveBody(output); |
| 77 | +} |
| 78 | + |
| 79 | +template <typename NestedColumnType, Type::Code type_code> |
| 80 | +size_t ColumnGeo<NestedColumnType, type_code>::Size() const { |
| 81 | + return data_->Size(); |
| 82 | +} |
| 83 | + |
| 84 | +template <typename NestedColumnType, Type::Code type_code> |
| 85 | +ColumnRef ColumnGeo<NestedColumnType, type_code>::Slice(size_t begin, size_t len) const { |
| 86 | + return std::make_shared<ColumnGeo>(data_->Slice(begin, len)); |
| 87 | +} |
| 88 | + |
| 89 | +template <typename NestedColumnType, Type::Code type_code> |
| 90 | +ColumnRef ColumnGeo<NestedColumnType, type_code>::CloneEmpty() const { |
| 91 | + return std::make_shared<ColumnGeo>(); |
| 92 | +} |
| 93 | + |
| 94 | +template <typename NestedColumnType, Type::Code type_code> |
| 95 | +void ColumnGeo<NestedColumnType, type_code>::Swap(Column& other) { |
| 96 | + auto& col = dynamic_cast<ColumnGeo&>(other); |
| 97 | + data_.swap(col.data_); |
| 98 | +} |
| 99 | + |
| 100 | +template class ColumnGeo<ColumnTupleT<ColumnFloat64, ColumnFloat64>, Type::Code::Point>; |
| 101 | + |
| 102 | +template class ColumnGeo<ColumnArrayT<ColumnPoint>, Type::Code::Ring>; |
| 103 | + |
| 104 | +template class ColumnGeo<ColumnArrayT<ColumnRing>, Type::Code::Polygon>; |
| 105 | + |
| 106 | +template class ColumnGeo<ColumnArrayT<ColumnPolygon>, Type::Code::MultiPolygon>; |
| 107 | + |
| 108 | +} // namespace clickhouse |
0 commit comments