Skip to content

Commit

Permalink
Merge pull request #10711 from ClickHouse/h3-range-check
Browse files Browse the repository at this point in the history
Range check in function h3EdgeAngle
  • Loading branch information
alexey-milovidov committed May 6, 2020
2 parents 4df7dd8 + 97211e5 commit d0b61f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Functions/h3EdgeAngle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
# include <Functions/FunctionFactory.h>
# include <Functions/IFunction.h>
# include <Common/typeid_cast.h>
# include <IO/WriteHelpers.h>
# include <ext/range.h>

# if __has_include(<h3/h3api.h>)
# include <h3/h3api.h>
# include <h3/constants.h>
# else
# include <h3api.h>
# include <constants.h>
# endif


Expand All @@ -19,7 +22,9 @@ namespace DB
namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int ARGUMENT_OUT_OF_BOUND;
}

class FunctionH3EdgeAngle : public IFunction
{
public:
Expand Down Expand Up @@ -54,6 +59,9 @@ class FunctionH3EdgeAngle : public IFunction
for (const auto row : ext::range(0, input_rows_count))
{
const int resolution = col_hindex->getUInt(row);
if (resolution > MAX_H3_RES)
throw Exception("The argument 'resolution' (" + toString(resolution) + ") of function " + getName()
+ " is out of bounds because the maximum resolution in H3 library is " + toString(MAX_H3_RES), ErrorCodes::ARGUMENT_OUT_OF_BOUND);

// Numerical constant is 180 degrees / pi / Earth radius, Earth radius is from h3 sources
Float64 res = 8.99320592271288084e-6 * edgeLengthM(resolution);
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT h3EdgeAngle(100); -- { serverError 69 }

0 comments on commit d0b61f9

Please sign in to comment.