-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
371 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#include "geo.h" | ||
|
||
#include "utils.h" | ||
|
||
namespace { | ||
using namespace ::clickhouse; | ||
|
||
template <Type::Code type_code> | ||
TypeRef CreateGeoType() { | ||
if constexpr (type_code == Type::Code::Point) { | ||
return Type::CreatePoint(); | ||
} else if constexpr (type_code == Type::Code::Ring) { | ||
return Type::CreateRing(); | ||
} else if constexpr (type_code == Type::Code::Polygon) { | ||
return Type::CreatePolygon(); | ||
} else if constexpr (type_code == Type::Code::MultiPolygon) { | ||
return Type::CreateMultiPolygon(); | ||
} | ||
} | ||
|
||
template <typename ColumnType> | ||
std::shared_ptr<ColumnType> CreateColumn() { | ||
if constexpr (std::is_same_v<ColumnType, ColumnTupleT<ColumnFloat64, ColumnFloat64>>) { | ||
return std::make_shared<ColumnTupleT<ColumnFloat64, ColumnFloat64>>( | ||
std::make_tuple(std::make_shared<ColumnFloat64>(), std::make_shared<ColumnFloat64>())); | ||
} else { | ||
return std::make_shared<ColumnType>(); | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
namespace clickhouse { | ||
|
||
template <typename NestedColumnType, Type::Code type_code> | ||
ColumnGeo<NestedColumnType, type_code>::ColumnGeo() | ||
: Column(std::move(CreateGeoType<type_code>())), | ||
data_(std::move(CreateColumn<NestedColumnType>())) { | ||
} | ||
|
||
template <typename NestedColumnType, Type::Code type_code> | ||
ColumnGeo<NestedColumnType, type_code>::ColumnGeo(ColumnRef data) | ||
: Column(std::move(CreateGeoType<type_code>())) | ||
, data_(std::move(WrapColumn<NestedColumnType>(std::move(data)))) { | ||
} | ||
|
||
template <typename NestedColumnType, Type::Code type_code> | ||
void ColumnGeo<NestedColumnType, type_code>::Clear() { | ||
data_->Clear(); | ||
} | ||
|
||
template <typename NestedColumnType, Type::Code type_code> | ||
const typename ColumnGeo<NestedColumnType, type_code>::ValueType ColumnGeo<NestedColumnType, type_code>::At(size_t n) const { | ||
return data_->At(n); | ||
} | ||
|
||
template <typename NestedColumnType, Type::Code type_code> | ||
const typename ColumnGeo<NestedColumnType, type_code>::ValueType ColumnGeo<NestedColumnType, type_code>::operator[](size_t n) const { | ||
return data_->At(n); | ||
} | ||
|
||
template <typename NestedColumnType, Type::Code type_code> | ||
void ColumnGeo<NestedColumnType, type_code>::Append(ColumnRef column) { | ||
if (auto col = column->template As<ColumnGeo>()) { | ||
data_->Append(col->data_->template As<Column>()); | ||
} | ||
} | ||
|
||
template <typename NestedColumnType, Type::Code type_code> | ||
bool ColumnGeo<NestedColumnType, type_code>::LoadBody(InputStream* input, size_t rows) { | ||
return data_->LoadBody(input, rows); | ||
} | ||
|
||
template <typename NestedColumnType, Type::Code type_code> | ||
void ColumnGeo<NestedColumnType, type_code>::SaveBody(OutputStream* output) { | ||
data_->SaveBody(output); | ||
} | ||
|
||
template <typename NestedColumnType, Type::Code type_code> | ||
size_t ColumnGeo<NestedColumnType, type_code>::Size() const { | ||
return data_->Size(); | ||
} | ||
|
||
template <typename NestedColumnType, Type::Code type_code> | ||
ColumnRef ColumnGeo<NestedColumnType, type_code>::Slice(size_t begin, size_t len) const { | ||
return std::make_shared<ColumnGeo>(data_->Slice(begin, len)); | ||
} | ||
|
||
template <typename NestedColumnType, Type::Code type_code> | ||
ColumnRef ColumnGeo<NestedColumnType, type_code>::CloneEmpty() const { | ||
return std::make_shared<ColumnGeo>(); | ||
} | ||
|
||
template <typename NestedColumnType, Type::Code type_code> | ||
void ColumnGeo<NestedColumnType, type_code>::Swap(Column& other) { | ||
auto& col = dynamic_cast<ColumnGeo&>(other); | ||
data_.swap(col.data_); | ||
} | ||
|
||
template class ColumnGeo<ColumnTupleT<ColumnFloat64, ColumnFloat64>, Type::Code::Point>; | ||
|
||
template class ColumnGeo<ColumnArrayT<ColumnPoint>, Type::Code::Ring>; | ||
|
||
template class ColumnGeo<ColumnArrayT<ColumnRing>, Type::Code::Polygon>; | ||
|
||
template class ColumnGeo<ColumnArrayT<ColumnPolygon>, Type::Code::MultiPolygon>; | ||
|
||
} // namespace clickhouse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#pragma once | ||
|
||
#include "array.h" | ||
#include "column.h" | ||
#include "numeric.h" | ||
#include "tuple.h" | ||
|
||
namespace clickhouse { | ||
|
||
template <typename NestedColumnType, Type::Code type_code> | ||
class ColumnGeo : public Column { | ||
public: | ||
using ValueType = typename NestedColumnType::ValueType; | ||
|
||
ColumnGeo(); | ||
|
||
explicit ColumnGeo(ColumnRef data); | ||
|
||
/// Appends one element to the end of column. | ||
template <typename T = ValueType> | ||
void Append(const T& value) { | ||
data_->Append(value); | ||
} | ||
|
||
/// Returns element at given row number. | ||
const ValueType At(size_t n) const; | ||
|
||
/// Returns element at given row number. | ||
const ValueType operator[](size_t n) const; | ||
|
||
public: | ||
/// Appends content of given column to the end of current one. | ||
void Append(ColumnRef column) override; | ||
|
||
/// Loads column data from input stream. | ||
bool LoadBody(InputStream* input, size_t rows) override; | ||
|
||
/// Saves column data to output stream. | ||
void SaveBody(OutputStream* output) override; | ||
|
||
/// Clear column data . | ||
void Clear() override; | ||
|
||
/// Returns count of rows in the column. | ||
size_t Size() const override; | ||
|
||
/// Makes slice of the current column. | ||
ColumnRef Slice(size_t begin, size_t len) const override; | ||
ColumnRef CloneEmpty() const override; | ||
void Swap(Column& other) override; | ||
|
||
private: | ||
std::shared_ptr<NestedColumnType> data_; | ||
}; | ||
|
||
// /** | ||
// * Represents a Point column. | ||
// */ | ||
using ColumnPoint = ColumnGeo<ColumnTupleT<ColumnFloat64, ColumnFloat64>, Type::Code::Point>; | ||
|
||
/** | ||
* Represents a Ring column. | ||
*/ | ||
using ColumnRing = ColumnGeo<ColumnArrayT<ColumnPoint>, Type::Code::Ring>; | ||
|
||
/** | ||
* Represents a Polygon column. | ||
*/ | ||
using ColumnPolygon = ColumnGeo<ColumnArrayT<ColumnRing>, Type::Code::Polygon>; | ||
|
||
/** | ||
* Represents a MultiPolygon column. | ||
*/ | ||
using ColumnMultiPolygon = ColumnGeo<ColumnArrayT<ColumnPolygon>, Type::Code::MultiPolygon>; | ||
|
||
} // namespace clickhouse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.