Update h3ToGeoBoundary.cpp

This commit is contained in:
alexey-milovidov 2021-09-16 00:24:12 +03:00 committed by GitHub
parent b467df98d3
commit 10a314dd46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,9 +16,9 @@
#include <h3api.h> #include <h3api.h>
namespace DB namespace DB
{ {
namespace ErrorCodes namespace ErrorCodes
{ {
extern const int ILLEGAL_TYPE_OF_ARGUMENT; extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int INCORRECT_DATA; extern const int INCORRECT_DATA;
@ -29,16 +29,17 @@ class FunctionH3ToGeoBoundary : public IFunction
public: public:
static constexpr auto name = "h3ToGeoBoundary"; static constexpr auto name = "h3ToGeoBoundary";
String getName() const override { return name; } String getName() const override { return name; }
static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionH3ToGeoBoundary>(); } static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionH3ToGeoBoundary>(); }
size_t getNumberOfArguments() const override { return 1; } size_t getNumberOfArguments() const override { return 1; }
bool useDefaultImplementationForConstants() const override { return true; } bool useDefaultImplementationForConstants() const override { return true; }
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; } bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{ {
const auto & arg = arguments[0]; const auto & arg = arguments[0];
if(!isUInt64(arg)) { if (!isUInt64(arg))
{
throw Exception( throw Exception(
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"Illegal type {} of argument {} of function {}. Must be UInt64", "Illegal type {} of argument {} of function {}. Must be UInt64",
@ -47,12 +48,10 @@ public:
return std::make_shared<DataTypeArray>( return std::make_shared<DataTypeArray>(
std::make_shared<DataTypeTuple>( std::make_shared<DataTypeTuple>(
DataTypes{std::make_shared<DataTypeFloat64>(), std::make_shared<DataTypeFloat64>()} DataTypes{std::make_shared<DataTypeFloat64>(), std::make_shared<DataTypeFloat64>()}));
)
);
} }
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
{ {
const auto * col_hindex = arguments[0].column.get(); const auto * col_hindex = arguments[0].column.get();
@ -62,7 +61,7 @@ public:
offsets->reserve(input_rows_count); offsets->reserve(input_rows_count);
IColumn::Offset current_offset = 0; IColumn::Offset current_offset = 0;
for (size_t row = 0; row < input_rows_count; ++row) for (size_t row = 0; row < input_rows_count; ++row)
{ {
H3Index h3index = col_hindex->getUInt(row); H3Index h3index = col_hindex->getUInt(row);
CellBoundary boundary{}; CellBoundary boundary{};
@ -70,8 +69,8 @@ public:
auto err = cellToBoundary(h3index, &boundary); auto err = cellToBoundary(h3index, &boundary);
if (err) if (err)
throw Exception(ErrorCodes::INCORRECT_DATA, "Incorrect H3 index: {}, error: {}", h3index, err); throw Exception(ErrorCodes::INCORRECT_DATA, "Incorrect H3 index: {}, error: {}", h3index, err);
for (int vert = 0; vert < boundary.numVerts; ++vert) for (int vert = 0; vert < boundary.numVerts; ++vert)
{ {
latitude->insert(radsToDegs(boundary.verts[vert].lat)); latitude->insert(radsToDegs(boundary.verts[vert].lat));
longitude->insert(radsToDegs(boundary.verts[vert].lng)); longitude->insert(radsToDegs(boundary.verts[vert].lng));
@ -83,8 +82,7 @@ public:
return ColumnArray::create( return ColumnArray::create(
ColumnTuple::create(Columns{std::move(latitude), std::move(longitude)}), ColumnTuple::create(Columns{std::move(latitude), std::move(longitude)}),
std::move(offsets) std::move(offsets));
);
} }
}; };
@ -93,7 +91,6 @@ void registerFunctionH3ToGeoBoundary(FunctionFactory & factory)
factory.registerFunction<FunctionH3ToGeoBoundary>(); factory.registerFunction<FunctionH3ToGeoBoundary>();
} }
} }
#endif #endif