improvements to tests for h3kRing and h3ToChildren funcs (#33311)

This commit is contained in:
Bharat Nallan 2022-01-20 06:08:13 -08:00 committed by GitHub
parent 779538bd89
commit adbdc3153a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 8 deletions

View File

@ -278,7 +278,7 @@ h3kRing(h3index, k)
**Arguments** **Arguments**
- `h3index` — Hexagon index number. Type: [UInt64](../../../sql-reference/data-types/int-uint.md). - `h3index` — Hexagon index number. Type: [UInt64](../../../sql-reference/data-types/int-uint.md).
- `k` — Raduis. Type: [integer](../../../sql-reference/data-types/int-uint.md) - `k` — Radius. Type: [integer](../../../sql-reference/data-types/int-uint.md)
**Returned values** **Returned values**

View File

@ -74,8 +74,6 @@ public:
dst_offsets.resize(input_rows_count); dst_offsets.resize(input_rows_count);
auto current_offset = 0; auto current_offset = 0;
std::vector<H3Index> hindex_vec;
for (size_t row = 0; row < input_rows_count; ++row) for (size_t row = 0; row < input_rows_count; ++row)
{ {
const UInt64 parent_hindex = col_hindex->getUInt(row); const UInt64 parent_hindex = col_hindex->getUInt(row);
@ -94,6 +92,7 @@ public:
"The result of function {} (array of {} elements) will be too large with resolution argument = {}", "The result of function {} (array of {} elements) will be too large with resolution argument = {}",
getName(), toString(vec_size), toString(child_resolution)); getName(), toString(vec_size), toString(child_resolution));
std::vector<H3Index> hindex_vec;
hindex_vec.resize(vec_size); hindex_vec.resize(vec_size);
cellToChildren(parent_hindex, child_resolution, hindex_vec.data()); cellToChildren(parent_hindex, child_resolution, hindex_vec.data());

View File

@ -71,8 +71,6 @@ public:
dst_offsets.resize(input_rows_count); dst_offsets.resize(input_rows_count);
auto current_offset = 0; auto current_offset = 0;
std::vector<H3Index> hindex_vec;
for (size_t row = 0; row < input_rows_count; ++row) for (size_t row = 0; row < input_rows_count; ++row)
{ {
const H3Index origin_hindex = col_hindex->getUInt(row); const H3Index origin_hindex = col_hindex->getUInt(row);
@ -88,6 +86,7 @@ public:
throw Exception(ErrorCodes::PARAMETER_OUT_OF_BOUND, "Argument 'k' for {} function must be non negative", getName()); throw Exception(ErrorCodes::PARAMETER_OUT_OF_BOUND, "Argument 'k' for {} function must be non negative", getName());
const auto vec_size = maxGridDiskSize(k); const auto vec_size = maxGridDiskSize(k);
std::vector<H3Index> hindex_vec;
hindex_vec.resize(vec_size); hindex_vec.resize(vec_size);
gridDisk(origin_hindex, k, hindex_vec.data()); gridDisk(origin_hindex, k, hindex_vec.data());

File diff suppressed because one or more lines are too long

View File

@ -3,3 +3,33 @@
SELECT arraySort(h3kRing(581276613233082367, 1)); SELECT arraySort(h3kRing(581276613233082367, 1));
SELECT h3kRing(581276613233082367, 0); SELECT h3kRing(581276613233082367, 0);
SELECT h3kRing(581276613233082367, -1); -- { serverError 12 } SELECT h3kRing(581276613233082367, -1); -- { serverError 12 }
DROP TABLE IF EXISTS h3_indexes;
CREATE TABLE h3_indexes (h3_index UInt64, res UInt8) ENGINE = Memory;
-- Random geo coordinates were generated using the H3 tool: https://github.com/ClickHouse-Extras/h3/blob/master/src/apps/testapps/mkRandGeo.c at various resolutions from 0 to 15.
-- Corresponding H3 index values were in turn generated with those geo coordinates using `geoToH3(lon, lat, res)` ClickHouse function for the following test.
INSERT INTO h3_indexes VALUES (579205133326352383,1);
INSERT INTO h3_indexes VALUES (581263419093549055,2);
INSERT INTO h3_indexes VALUES (589753847883235327,3);
INSERT INTO h3_indexes VALUES (594082350283882495,4);
INSERT INTO h3_indexes VALUES (598372386957426687,5);
INSERT INTO h3_indexes VALUES (599542359671177215,6);
INSERT INTO h3_indexes VALUES (604296355086598143,7);
INSERT INTO h3_indexes VALUES (608785214872748031,8);
INSERT INTO h3_indexes VALUES (615732192485572607,9);
INSERT INTO h3_indexes VALUES (617056794467368959,10);
INSERT INTO h3_indexes VALUES (624586477873168383,11);
INSERT INTO h3_indexes VALUES (627882919484481535,12);
INSERT INTO h3_indexes VALUES (634600058503392255,13);
INSERT INTO h3_indexes VALUES (635544851677385791,14);
INSERT INTO h3_indexes VALUES (639763125756281263,15);
INSERT INTO h3_indexes VALUES (644178757620501158,16);
SELECT arraySort(h3kRing(h3_index, res)) FROM h3_indexes ORDER BY h3_index;
DROP TABLE h3_indexes;

View File

@ -1,7 +1,16 @@
-- Tags: no-fasttest -- Tags: no-fasttest
SELECT arraySort(h3ToChildren(599405990164561919, 3)); SELECT h3ToChildren(599405990164561919, 16); -- { serverError 69 }
SELECT arraySort(h3ToChildren(599405990164561919, 6)); DROP TABLE IF EXISTS h3_indexes;
SELECT arraySort(h3ToChildren(599405990164561919, 8)); CREATE TABLE h3_indexes (h3_index UInt64, res UInt8) ENGINE = Memory;
INSERT INTO h3_indexes VALUES (599405990164561919, 3);
INSERT INTO h3_indexes VALUES (599405990164561919, 6);
INSERT INTO h3_indexes VALUES (599405990164561919, 8);
SELECT arraySort(h3ToChildren(h3_index,res)) FROM h3_indexes ORDER BY res;
DROP TABLE h3_indexes;