Merge pull request #34557 from bharatnc/ncb/geoToH3-update

check and get columns in geoToH3 func
This commit is contained in:
Maksim Kita 2022-02-13 14:29:45 +01:00 committed by GitHub
commit 380d9afb2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 10 deletions

View File

@ -11,6 +11,7 @@
#include <Common/typeid_cast.h>
#include <base/range.h>
#include <constants.h>
#include <h3api.h>
@ -20,6 +21,8 @@ namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int INCORRECT_DATA;
extern const int ILLEGAL_COLUMN;
extern const int ARGUMENT_OUT_OF_BOUND;
}
namespace
@ -68,9 +71,35 @@ public:
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
{
const auto * col_lon = arguments[0].column.get();
const auto * col_lat = arguments[1].column.get();
const auto * col_res = arguments[2].column.get();
const auto * col_lon = checkAndGetColumn<ColumnFloat64>(arguments[0].column.get());
if (!col_lon)
throw Exception(
ErrorCodes::ILLEGAL_COLUMN,
"Illegal type {} of argument {} of function {}. Must be Float64.",
arguments[0].type->getName(),
1,
getName());
const auto & data_lon = col_lon->getData();
const auto * col_lat = checkAndGetColumn<ColumnFloat64>(arguments[1].column.get());
if (!col_lat)
throw Exception(
ErrorCodes::ILLEGAL_COLUMN,
"Illegal type {} of argument {} of function {}. Must be Float64.",
arguments[1].type->getName(),
2,
getName());
const auto & data_lat = col_lat->getData();
const auto * col_res = checkAndGetColumn<ColumnUInt8>(arguments[2].column.get());
if (!col_res)
throw Exception(
ErrorCodes::ILLEGAL_COLUMN,
"Illegal type {} of argument {} of function {}. Must be UInt8.",
arguments[2].type->getName(),
3,
getName());
const auto & data_res = col_res->getData();
auto dst = ColumnVector<UInt64>::create();
auto & dst_data = dst->getData();
@ -78,9 +107,17 @@ public:
for (size_t row = 0; row < input_rows_count; ++row)
{
const double lon = col_lon->getFloat64(row);
const double lat = col_lat->getFloat64(row);
const UInt8 res = col_res->getUInt(row);
const double lon = data_lon[row];
const double lat = data_lat[row];
const UInt8 res = data_res[row];
if (res > MAX_H3_RES)
throw Exception(
ErrorCodes::ARGUMENT_OUT_OF_BOUND,
"The argument 'resolution' ({}) of function {} is out of bounds because the maximum resolution in H3 library is ",
toString(res),
getName(),
MAX_H3_RES);
LatLng coord;
coord.lng = degsToRads(lon);

View File

@ -4,12 +4,12 @@
644325528491955313
644325528627451570
644325529094369568
644325528491955313
639821928864584823
644325528491955313
644325528491955313
644325528627451570
644325529094369568
55.720762 37.598135 644325528491955313
55.720762 37.598135 639821928864584823
55.720762 37.598135 644325528491955313
55.72076201 37.598135 644325528491955313
55.763241 37.660183 644325528627451570

View File

@ -11,9 +11,10 @@ INSERT INTO table1 VALUES(55.72076201, 37.59813500, 15);
INSERT INTO table1 VALUES(55.72076200, 37.59813500, 14);
select geoToH3(37.63098076, 55.77922738, 15);
select geoToH3(37.63098076, 55.77922738, 24); -- { serverError 69 }
select geoToH3(lon, lat, resolution) from table1 order by lat, lon, resolution;
select geoToH3(lon, lat, 15) AS k from table1 order by lat, lon, k;
select lat, lon, geoToH3(lon, lat, 15) AS k from table1 order by lat, lon, k;
select geoToH3(lon, lat, resolution) AS k from table1 order by lat, lon, k;
select lat, lon, geoToH3(lon, lat, resolution) AS k from table1 order by lat, lon, k;
select geoToH3(lon, lat, resolution) AS k, count(*) from table1 group by k order by k;
DROP TABLE table1