From 838e4abfb3e6eccfade7f8f42b861d614c0e68f6 Mon Sep 17 00:00:00 2001 From: volaya Date: Fri, 6 Sep 2024 09:17:57 +0200 Subject: [PATCH 1/5] added "geo" aliases for certain functions --- clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql | 9 +++++++++ .../modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql | 9 +++++++++ clouds/postgres/modules/sql/h3/H3_FROMGEOGPOINT.sql | 11 +++++++++++ .../modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql | 11 +++++++++++ .../modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql | 9 +++++++++ clouds/snowflake/modules/sql/h3/H3_FROMGEOGPOINT.sql | 8 ++++++++ .../modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql | 8 ++++++++ 7 files changed, 65 insertions(+) diff --git a/clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql b/clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql index 12ad026a3..87e94b053 100644 --- a/clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql +++ b/clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql @@ -10,3 +10,12 @@ AS ( SAFE.ST_X(geog), SAFE.ST_Y(geog), resolution ) ); + +CREATE OR REPLACE FUNCTION `@@BQ_DATASET@@.H3_FROMGEOPOINT` +(geo GEOGRAPHY, resolution INT64) +RETURNS STRING +AS ( + `@@BQ_DATASET@@.H3_FROMGEOGPOINT`( + geo, resolution + ) +); \ No newline at end of file diff --git a/clouds/bigquery/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql b/clouds/bigquery/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql index 53cf9ecd1..81b01e5da 100644 --- a/clouds/bigquery/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql +++ b/clouds/bigquery/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql @@ -10,3 +10,12 @@ AS ( ST_X(point), ST_Y(point), resolution ) ); + +CREATE OR REPLACE FUNCTION `@@BQ_DATASET@@.QUADBIN_FROMGEOPOINT` +(point GEOGRAPHY, resolution INT64) +RETURNS INT64 +AS ( + `@@BQ_DATASET@@.QUADBIN_FROMGEOGPOINT`( + point, resolution + ) +); diff --git a/clouds/postgres/modules/sql/h3/H3_FROMGEOGPOINT.sql b/clouds/postgres/modules/sql/h3/H3_FROMGEOGPOINT.sql index 4c66d3c4c..a0370fec2 100644 --- a/clouds/postgres/modules/sql/h3/H3_FROMGEOGPOINT.sql +++ b/clouds/postgres/modules/sql/h3/H3_FROMGEOGPOINT.sql @@ -17,3 +17,14 @@ $BODY$ END $BODY$ LANGUAGE sql IMMUTABLE PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION @@PG_SCHEMA@@.H3_FROMGEOPOINT( + geo GEOMETRY, + resolution INT +) +RETURNS VARCHAR(16) +AS +$BODY$ + SELECT @@PG_SCHEMA@@.H3_FROMGEOGPOINT(geo, resolution) +$BODY$ +LANGUAGE sql IMMUTABLE PARALLEL SAFE; diff --git a/clouds/postgres/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql b/clouds/postgres/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql index ff3a1ea6c..5172bb73d 100644 --- a/clouds/postgres/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql +++ b/clouds/postgres/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql @@ -20,3 +20,14 @@ $BODY$ FROM __geom4326; $BODY$ LANGUAGE sql IMMUTABLE PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION @@PG_SCHEMA@@.QUADBIN_FROMGEOPOINT( + point GEOMETRY, + resolution INT +) +RETURNS BIGINT +AS +$BODY$ + SELECT @@PG_SCHEMA@@.QUADBIN_FROMGEOGPOINT(point, resolution) +$BODY$ +LANGUAGE sql IMMUTABLE PARALLEL SAFE; diff --git a/clouds/redshift/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql b/clouds/redshift/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql index b936d4b8e..56ac60e99 100644 --- a/clouds/redshift/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql +++ b/clouds/redshift/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql @@ -13,3 +13,12 @@ AS $$ ELSE @@RS_SCHEMA@@.QUADBIN_FROMLONGLAT(ST_X(ST_TRANSFORM($1, 4326)), ST_Y(ST_TRANSFORM($1, 4326)), $2) END $$ LANGUAGE sql; + +CREATE OR REPLACE FUNCTION @@RS_SCHEMA@@.QUADBIN_FROMGEOPOINT +(GEOMETRY, INT) +-- (point, resolution) +RETURNS BIGINT +STABLE +AS $$ + SELECT @@RS_SCHEMA@@.QUADBIN_FROMGEOGPOINT($1, $2) +$$ LANGUAGE sql; diff --git a/clouds/snowflake/modules/sql/h3/H3_FROMGEOGPOINT.sql b/clouds/snowflake/modules/sql/h3/H3_FROMGEOGPOINT.sql index 069551dd8..49a2bb512 100644 --- a/clouds/snowflake/modules/sql/h3/H3_FROMGEOGPOINT.sql +++ b/clouds/snowflake/modules/sql/h3/H3_FROMGEOGPOINT.sql @@ -11,3 +11,11 @@ AS $$ H3_POINT_TO_CELL_STRING(GEOG, RESOLUTION), NULL) $$; + +CREATE OR REPLACE SECURE FUNCTION @@SF_SCHEMA@@.H3_FROMGEOPOINT +(geo GEOGRAPHY, resolution INT) +RETURNS STRING +IMMUTABLE +AS $$ + @@SF_SCHEMA@@.H3_FROMGEOGPOINT(geo, resolution) +$$; diff --git a/clouds/snowflake/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql b/clouds/snowflake/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql index b130ee2a6..4d15368d0 100644 --- a/clouds/snowflake/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql +++ b/clouds/snowflake/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql @@ -17,3 +17,11 @@ IMMUTABLE AS $$ @@SF_SCHEMA@@._QUADBIN_FROMLONGLAT(ST_X(point), ST_Y(point), resolution) $$; + +CREATE OR REPLACE SECURE FUNCTION @@SF_SCHEMA@@.QUADBIN_FROMGEOPOINT +(point GEOGRAPHY, resolution INT) +RETURNS BIGINT +IMMUTABLE +AS $$ + @@SF_SCHEMA@@._QUADBIN_FROMGEOGPOINT(point, resolution) +$$; \ No newline at end of file From 57f205857cbd1743c812f18d8de2bb0bbb2ba268 Mon Sep 17 00:00:00 2001 From: vdelacruzb Date: Wed, 23 Oct 2024 14:13:35 +0200 Subject: [PATCH 2/5] update headers --- clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql | 6 +++--- .../bigquery/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql | 6 +++--- clouds/postgres/modules/sql/h3/H3_FROMGEOGPOINT.sql | 6 +++--- .../postgres/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql | 6 +++--- .../redshift/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql | 6 +++--- .../snowflake/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql b/clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql index 87e94b053..6667686eb 100644 --- a/clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql +++ b/clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql @@ -1,6 +1,6 @@ ----------------------------- --- Copyright (C) 2021 CARTO ----------------------------- +-------------------------------- +-- Copyright (C) 2021-2024 CARTO +-------------------------------- CREATE OR REPLACE FUNCTION `@@BQ_DATASET@@.H3_FROMGEOGPOINT` (geog GEOGRAPHY, resolution INT64) diff --git a/clouds/bigquery/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql b/clouds/bigquery/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql index 81b01e5da..94eaa4570 100644 --- a/clouds/bigquery/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql +++ b/clouds/bigquery/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql @@ -1,6 +1,6 @@ ----------------------------- --- Copyright (C) 2022 CARTO ----------------------------- +-------------------------------- +-- Copyright (C) 2022-2024 CARTO +-------------------------------- CREATE OR REPLACE FUNCTION `@@BQ_DATASET@@.QUADBIN_FROMGEOGPOINT` (point GEOGRAPHY, resolution INT64) diff --git a/clouds/postgres/modules/sql/h3/H3_FROMGEOGPOINT.sql b/clouds/postgres/modules/sql/h3/H3_FROMGEOGPOINT.sql index a0370fec2..664818065 100644 --- a/clouds/postgres/modules/sql/h3/H3_FROMGEOGPOINT.sql +++ b/clouds/postgres/modules/sql/h3/H3_FROMGEOGPOINT.sql @@ -1,6 +1,6 @@ ----------------------------- --- Copyright (C) 2023 CARTO ----------------------------- +-------------------------------- +-- Copyright (C) 2023-2024 CARTO +-------------------------------- CREATE OR REPLACE FUNCTION @@PG_SCHEMA@@.H3_FROMGEOGPOINT( geog GEOMETRY, diff --git a/clouds/postgres/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql b/clouds/postgres/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql index 5172bb73d..140020bb5 100644 --- a/clouds/postgres/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql +++ b/clouds/postgres/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql @@ -1,6 +1,6 @@ ----------------------------- --- Copyright (C) 2022 CARTO ----------------------------- +-------------------------------- +-- Copyright (C) 2022-2024 CARTO +-------------------------------- CREATE OR REPLACE FUNCTION @@PG_SCHEMA@@.QUADBIN_FROMGEOGPOINT( point GEOMETRY, diff --git a/clouds/redshift/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql b/clouds/redshift/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql index 56ac60e99..1c208255e 100644 --- a/clouds/redshift/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql +++ b/clouds/redshift/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql @@ -1,6 +1,6 @@ ----------------------------- --- Copyright (C) 2022 CARTO ----------------------------- +-------------------------------- +-- Copyright (C) 2022-2024 CARTO +-------------------------------- CREATE OR REPLACE FUNCTION @@RS_SCHEMA@@.QUADBIN_FROMGEOGPOINT (GEOMETRY, INT) diff --git a/clouds/snowflake/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql b/clouds/snowflake/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql index 4d15368d0..1e8dbc1c8 100644 --- a/clouds/snowflake/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql +++ b/clouds/snowflake/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql @@ -1,6 +1,6 @@ ----------------------------- --- Copyright (C) 2022 CARTO ----------------------------- +-------------------------------- +-- Copyright (C) 2022-2024 CARTO +-------------------------------- CREATE OR REPLACE SECURE FUNCTION @@SF_SCHEMA@@.QUADBIN_FROMGEOGPOINT (point GEOGRAPHY, resolution INT) From a44dcc6df411b69b034398f97bd4bc6255f789d9 Mon Sep 17 00:00:00 2001 From: vdelacruzb Date: Wed, 23 Oct 2024 14:21:00 +0200 Subject: [PATCH 3/5] update docs --- clouds/bigquery/modules/doc/h3/H3_FROMGEOGPOINT.md | 2 +- clouds/bigquery/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md | 2 +- clouds/postgres/modules/doc/h3/H3_FROMGEOGPOINT.md | 2 +- clouds/postgres/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md | 2 +- clouds/redshift/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md | 2 +- clouds/snowflake/modules/doc/h3/H3_FROMGEOGPOINT.md | 2 +- clouds/snowflake/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clouds/bigquery/modules/doc/h3/H3_FROMGEOGPOINT.md b/clouds/bigquery/modules/doc/h3/H3_FROMGEOGPOINT.md index 63bd18b66..58d018d52 100644 --- a/clouds/bigquery/modules/doc/h3/H3_FROMGEOGPOINT.md +++ b/clouds/bigquery/modules/doc/h3/H3_FROMGEOGPOINT.md @@ -6,7 +6,7 @@ H3_FROMGEOGPOINT(point, resolution) **Description** -Returns the H3 cell index that the point belongs to in the required `resolution`. It will return `null` on error (invalid geography type or resolution out of bounds). +Returns the H3 cell index that the point belongs to in the required `resolution`. It will return `null` on error (invalid geography type or resolution out of bounds). This function is an alias for `H3_FROMGEOPOINT`. * `point`: `GEOGRAPHY` point to get the H3 cell from. * `resolution`: `INT64` number between 0 and 15 with the [H3 resolution](https://h3geo.org/docs/core-library/restable). diff --git a/clouds/bigquery/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md b/clouds/bigquery/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md index 59799e32f..0f8496e6a 100644 --- a/clouds/bigquery/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md +++ b/clouds/bigquery/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md @@ -6,7 +6,7 @@ QUADBIN_FROMGEOGPOINT(point, resolution) **Description** -Returns the Quadbin of a given point at a given level of detail. +Returns the Quadbin of a given point at a given level of detail. This function is an alias for `QUADBIN_FROMGEOPOINT`. * `point`: `GEOGRAPHY` point to get the Quadbin from. * `resolution`: `INT64` level of detail or zoom. diff --git a/clouds/postgres/modules/doc/h3/H3_FROMGEOGPOINT.md b/clouds/postgres/modules/doc/h3/H3_FROMGEOGPOINT.md index acd6c6a4f..c5af10567 100644 --- a/clouds/postgres/modules/doc/h3/H3_FROMGEOGPOINT.md +++ b/clouds/postgres/modules/doc/h3/H3_FROMGEOGPOINT.md @@ -6,7 +6,7 @@ H3_FROMGEOGPOINT(point, resolution) **Description** -Returns the H3 cell index that the point belongs to in the required `resolution`. It will return `null` on error (invalid geography type or resolution out of bounds). +Returns the H3 cell index that the point belongs to in the required `resolution`. It will return `null` on error (invalid geography type or resolution out of bounds). This function is an alias for `H3_FROMGEOPOINT`. * `point`: `GEOMETRY` point to get the H3 cell from. * `resolution`: `INT` number between 0 and 15 with the [H3 resolution](https://h3geo.org/docs/core-library/restable). diff --git a/clouds/postgres/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md b/clouds/postgres/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md index 18a095d29..b0cf5f192 100644 --- a/clouds/postgres/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md +++ b/clouds/postgres/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md @@ -6,7 +6,7 @@ QUADBIN_FROMGEOGPOINT(point, resolution) **Description** -Returns the Quadbin of a given point at a given level of detail. +Returns the Quadbin of a given point at a given level of detail. This function is an alias for `QUADBIN_FROMGEOPOINT`. * `point`: `GEOMETRY` point to get the Quadbin from. * `resolution`: `BIGINT` level of detail or zoom. diff --git a/clouds/redshift/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md b/clouds/redshift/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md index 344f309d1..db16ae0cf 100644 --- a/clouds/redshift/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md +++ b/clouds/redshift/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md @@ -6,7 +6,7 @@ QUADBIN_FROMGEOGPOINT(point, resolution) **Description** -Returns the Quadbin of a given point at a given level of detail. +Returns the Quadbin of a given point at a given level of detail. This function is an alias for `QUADBIN_FROMGEOPOINT`. * `point`: `GEOMETRY` point to get the Quadbin from. * `resolution`: `INT` level of detail or zoom. diff --git a/clouds/snowflake/modules/doc/h3/H3_FROMGEOGPOINT.md b/clouds/snowflake/modules/doc/h3/H3_FROMGEOGPOINT.md index 73ac27d77..f6c5f1686 100644 --- a/clouds/snowflake/modules/doc/h3/H3_FROMGEOGPOINT.md +++ b/clouds/snowflake/modules/doc/h3/H3_FROMGEOGPOINT.md @@ -6,7 +6,7 @@ H3_FROMGEOGPOINT(point, resolution) **Description** -Returns the H3 cell index that the point belongs to in the required `resolution`. It will return `null` on error (invalid geography type or resolution out of bounds). +Returns the H3 cell index that the point belongs to in the required `resolution`. It will return `null` on error (invalid geography type or resolution out of bounds). This function is an alias for `H3_FROMGEOPOINT`. * `point`: `GEOGRAPHY` point to get the H3 cell from. * `resolution`: `INT` number between 0 and 15 with the [H3 resolution](https://h3geo.org/docs/core-library/restable). diff --git a/clouds/snowflake/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md b/clouds/snowflake/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md index 55add4864..ea240aecb 100644 --- a/clouds/snowflake/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md +++ b/clouds/snowflake/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md @@ -6,7 +6,7 @@ QUADBIN_FROMGEOGPOINT(point, resolution) **Description** -Returns the Quadbin of a given point at a given level of detail. +Returns the Quadbin of a given point at a given level of detail. This function is an alias for `QUADBIN_FROMGEOPOINT`. * `point`: `GEOGRAPHY` point to get the Quadbin from. * `resolution`: `INT` level of detail or zoom. From e7d375c1fe35f9867446fae792d78b10aca4f552 Mon Sep 17 00:00:00 2001 From: vdelacruzb Date: Wed, 23 Oct 2024 14:28:47 +0200 Subject: [PATCH 4/5] add tests --- .../modules/sql/h3/H3_FROMGEOGPOINT.sql | 2 +- .../modules/test/h3/H3_FROMGEOGPOINT.test.js | 32 +++++++++++++++++ .../quadbin/QUADBIN_FROMGEOGPOINT.test.js | 7 ++++ .../modules/test/h3/test_H3_FROMGEOGPOINT.py | 31 +++++++++++++++++ .../quadbin/test_QUADBIN_FROMGEOGPOINT.py | 8 +++++ .../quadbin/test_QUADBIN_FROMGEOGPOINT.py | 9 +++++ .../sql/quadbin/QUADBIN_FROMGEOGPOINT.sql | 2 +- .../modules/test/h3/H3_FROMGEOGPOINT.spec.js | 34 +++++++++++++++++++ .../quadbin/QUADBIN_FROMGEOGPOINT.test.js | 7 ++++ 9 files changed, 130 insertions(+), 2 deletions(-) diff --git a/clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql b/clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql index 6667686eb..f6725b114 100644 --- a/clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql +++ b/clouds/bigquery/modules/sql/h3/H3_FROMGEOGPOINT.sql @@ -18,4 +18,4 @@ AS ( `@@BQ_DATASET@@.H3_FROMGEOGPOINT`( geo, resolution ) -); \ No newline at end of file +); diff --git a/clouds/bigquery/modules/test/h3/H3_FROMGEOGPOINT.test.js b/clouds/bigquery/modules/test/h3/H3_FROMGEOGPOINT.test.js index fe75d3e43..6d98f87a8 100644 --- a/clouds/bigquery/modules/test/h3/H3_FROMGEOGPOINT.test.js +++ b/clouds/bigquery/modules/test/h3/H3_FROMGEOGPOINT.test.js @@ -50,4 +50,36 @@ test('H3_FROMGEOGPOINT returns NULL with non POINT geographies', async () => { null, null ]); +}); + + +test('H3_FROMGEOPOINT returns the proper INT64', async () => { + const query = ` + WITH inputs AS + ( + SELECT 1 AS id, ST_GEOGPOINT(-122.0553238, 37.3615593) as geom, 5 as resolution UNION ALL + SELECT 2 AS id, ST_GEOGPOINT(-164.991559, 30.943387) as geom, 5 as resolution UNION ALL + SELECT 3 AS id, ST_GEOGPOINT(71.52790329909925, 46.04189431883772) as geom, 15 as resolution UNION ALL + + -- null inputs + SELECT 4 AS id, NULL AS geom, 5 as resolution UNION ALL + SELECT 5 AS id, ST_GEOGPOINT(-122.0553238, 37.3615593) as geom, -1 as resolution UNION ALL + SELECT 6 AS id, ST_GEOGPOINT(-122.0553238, 37.3615593) as geom, 20 as resolution UNION ALL + SELECT 7 AS id, ST_GEOGPOINT(-122.0553238, 37.3615593) as geom, NULL as resolution + ) + SELECT CAST(\`@@BQ_DATASET@@.H3_FROMGEOPOINT\`(geom, resolution) AS STRING) as h3_id + FROM inputs + ORDER BY id ASC + `; + const rows = await runQuery(query); + expect(rows.length).toEqual(7); + expect(rows.map((r) => r.h3_id)).toEqual([ + '85283473fffffff', + '8547732ffffffff', + '8f2000000000000', + null, + null, + null, + null + ]); }); \ No newline at end of file diff --git a/clouds/bigquery/modules/test/quadbin/QUADBIN_FROMGEOGPOINT.test.js b/clouds/bigquery/modules/test/quadbin/QUADBIN_FROMGEOGPOINT.test.js index 51f2a03dd..93b094856 100644 --- a/clouds/bigquery/modules/test/quadbin/QUADBIN_FROMGEOGPOINT.test.js +++ b/clouds/bigquery/modules/test/quadbin/QUADBIN_FROMGEOGPOINT.test.js @@ -5,4 +5,11 @@ test('QUADBIN_FROMGEOGPOINT should work', async () => { const rows = await runQuery(query); expect(rows.length).toEqual(1); expect(rows[0].output).toEqual('5209574053332910079'); +}); + +test('QUADBIN_FROMGEOPOINT should work', async () => { + const query = 'SELECT CAST(`@@BQ_DATASET@@.QUADBIN_FROMGEOPOINT`(ST_GEOGPOINT(40.4168, -3.7038), 4) AS STRING) AS output'; + const rows = await runQuery(query); + expect(rows.length).toEqual(1); + expect(rows[0].output).toEqual('5209574053332910079'); }); \ No newline at end of file diff --git a/clouds/postgres/modules/test/h3/test_H3_FROMGEOGPOINT.py b/clouds/postgres/modules/test/h3/test_H3_FROMGEOGPOINT.py index b75073ead..a829113ef 100644 --- a/clouds/postgres/modules/test/h3/test_H3_FROMGEOGPOINT.py +++ b/clouds/postgres/modules/test/h3/test_H3_FROMGEOGPOINT.py @@ -51,3 +51,34 @@ def test_h3_fromgeogpoint_non_points(): assert result[0][0] is None assert result[1][0] is None assert result[2][0] is None + + +def test_h3_fromgeopoint(): + """Returns the proper index.""" + result = run_query( + """ + WITH inputs AS + ( + SELECT 1 AS id, ST_POINT(-122.0553238, 37.3615593) as geom, 5 as resolution UNION ALL + SELECT 2 AS id, ST_POINT(-164.991559, 30.943387) as geom, 5 as resolution UNION ALL + SELECT 3 AS id, ST_POINT(71.52790329909925, 46.04189431883772) as geom, 15 as resolution UNION ALL + + -- null inputs + SELECT 4 AS id, NULL AS geom, 5 as resolution UNION ALL + SELECT 5 AS id, ST_POINT(-122.0553238, 37.3615593) as geom, -1 as resolution UNION ALL + SELECT 6 AS id, ST_POINT(-122.0553238, 37.3615593) as geom, 20 as resolution UNION ALL + SELECT 7 AS id, ST_POINT(-122.0553238, 37.3615593) as geom, NULL as resolution + ) + SELECT @@PG_SCHEMA@@.H3_FROMGEOPOINT(geom, resolution) as h3_id + FROM inputs + ORDER BY id ASC + """ # noqa + ) + assert len(result) == 7 + assert result[0][0] == '85283473fffffff' + assert result[1][0] == '8547732ffffffff' + assert result[2][0] == '8f2000000000000' + assert result[3][0] is None + assert result[4][0] is None + assert result[5][0] is None + assert result[6][0] is None diff --git a/clouds/postgres/modules/test/quadbin/test_QUADBIN_FROMGEOGPOINT.py b/clouds/postgres/modules/test/quadbin/test_QUADBIN_FROMGEOGPOINT.py index 0589405c2..525d0387e 100644 --- a/clouds/postgres/modules/test/quadbin/test_QUADBIN_FROMGEOGPOINT.py +++ b/clouds/postgres/modules/test/quadbin/test_QUADBIN_FROMGEOGPOINT.py @@ -29,3 +29,11 @@ def test_quadbin_fromgeogpoint_other_srid(): """ ) assert result[0][0] == 5209574053332910079 + + +def test_quadbin_fromgeopoint_no_srid(): + """Computes quadbin for point with no SRID.""" + result = run_query( + 'SELECT @@PG_SCHEMA@@.QUADBIN_FROMGEOPOINT(ST_MAKEPOINT(40.4168, -3.7038), 4)' + ) + assert result[0][0] == 5209574053332910079 diff --git a/clouds/redshift/modules/test/quadbin/test_QUADBIN_FROMGEOGPOINT.py b/clouds/redshift/modules/test/quadbin/test_QUADBIN_FROMGEOGPOINT.py index 0c16b71f2..eccd396a7 100644 --- a/clouds/redshift/modules/test/quadbin/test_QUADBIN_FROMGEOGPOINT.py +++ b/clouds/redshift/modules/test/quadbin/test_QUADBIN_FROMGEOGPOINT.py @@ -8,3 +8,12 @@ def test_quadbin_fromgeogpoint(): assert len(result[0]) == 1 assert result[0][0] == 5209574053332910079 + + +def test_quadbin_fromgeopoint(): + result = run_query( + 'SELECT @@RS_SCHEMA@@.QUADBIN_FROMGEOPOINT(ST_POINT(40.4168, -3.7038),4)' + ) + + assert len(result[0]) == 1 + assert result[0][0] == 5209574053332910079 \ No newline at end of file diff --git a/clouds/snowflake/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql b/clouds/snowflake/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql index 1e8dbc1c8..4b6efa3c3 100644 --- a/clouds/snowflake/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql +++ b/clouds/snowflake/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql @@ -24,4 +24,4 @@ RETURNS BIGINT IMMUTABLE AS $$ @@SF_SCHEMA@@._QUADBIN_FROMGEOGPOINT(point, resolution) -$$; \ No newline at end of file +$$; diff --git a/clouds/snowflake/modules/test/h3/H3_FROMGEOGPOINT.spec.js b/clouds/snowflake/modules/test/h3/H3_FROMGEOGPOINT.spec.js index 1864f6f9a..cd3469372 100644 --- a/clouds/snowflake/modules/test/h3/H3_FROMGEOGPOINT.spec.js +++ b/clouds/snowflake/modules/test/h3/H3_FROMGEOGPOINT.spec.js @@ -53,4 +53,38 @@ test('H3_FROMGEOGPOINT returns NULL with non POINT geographies', async () => { null, null ]); +}); + + +test('H3_FROMGEOPOINT returns the proper INT64', async () => { + const query = ` + WITH inputs AS + ( + SELECT 1 AS id, ST_POINT(-122.0553238, 37.3615593) as geom, 5 as resolution UNION ALL + SELECT 2 AS id, ST_POINT(-164.991559, 30.943387) as geom, 5 as resolution UNION ALL + SELECT 3 AS id, ST_POINT(71.52790329909925, 46.04189431883772) as geom, 15 as resolution UNION ALL + + -- null inputs + SELECT 4 AS id, TRY_TO_GEOGRAPHY(NULL) AS geom, 5 as resolution UNION ALL + SELECT 5 AS id, ST_POINT(-122.0553238, 37.3615593) as geom, -1 as resolution UNION ALL + SELECT 6 AS id, ST_POINT(-122.0553238, 37.3615593) as geom, 20 as resolution UNION ALL + SELECT 7 AS id, ST_POINT(-122.0553238, 37.3615593) as geom, NULL as resolution + ) + SELECT + CAST(H3_FROMGEOPOINT(geom, resolution) AS STRING) as h3_id + FROM inputs + ORDER BY id ASC + `; + + const rows = await runQuery(query); + expect(rows.length).toEqual(7); + expect(rows.map((r) => r.H3_ID)).toEqual([ + '85283473fffffff', + '8547732ffffffff', + '8f2000000000000', + null, + null, + null, + null + ]); }); \ No newline at end of file diff --git a/clouds/snowflake/modules/test/quadbin/QUADBIN_FROMGEOGPOINT.test.js b/clouds/snowflake/modules/test/quadbin/QUADBIN_FROMGEOGPOINT.test.js index dc65b4adb..b90e2efd2 100644 --- a/clouds/snowflake/modules/test/quadbin/QUADBIN_FROMGEOGPOINT.test.js +++ b/clouds/snowflake/modules/test/quadbin/QUADBIN_FROMGEOGPOINT.test.js @@ -5,4 +5,11 @@ test('QUADBIN_FROMGEOGPOINT should work', async () => { const rows = await runQuery(query); expect(rows.length).toEqual(1); expect(rows[0].OUTPUT).toEqual('5209574053332910079'); +}); + +test('QUADBIN_FROMGEOPOINT should work', async () => { + const query = 'SELECT CAST(QUADBIN_FROMGEOPOINT(ST_POINT(40.4168, -3.7038), 4) AS STRING) AS OUTPUT'; + const rows = await runQuery(query); + expect(rows.length).toEqual(1); + expect(rows[0].OUTPUT).toEqual('5209574053332910079'); }); \ No newline at end of file From 18d8ec8ef556c136a523f0782e6e46366b341e4c Mon Sep 17 00:00:00 2001 From: vdelacruzb Date: Wed, 23 Oct 2024 14:32:37 +0200 Subject: [PATCH 5/5] remove space and rename tests --- clouds/bigquery/modules/test/h3/H3_FROMGEOGPOINT.test.js | 1 - .../h3/{H3_FROMGEOGPOINT.spec.js => H3_FROMGEOGPOINT.test.js} | 1 - .../test/h3/{H3_FROMLONGLAT.spec.js => H3_FROMLONGLAT.test.js} | 0 3 files changed, 2 deletions(-) rename clouds/snowflake/modules/test/h3/{H3_FROMGEOGPOINT.spec.js => H3_FROMGEOGPOINT.test.js} (99%) rename clouds/snowflake/modules/test/h3/{H3_FROMLONGLAT.spec.js => H3_FROMLONGLAT.test.js} (100%) diff --git a/clouds/bigquery/modules/test/h3/H3_FROMGEOGPOINT.test.js b/clouds/bigquery/modules/test/h3/H3_FROMGEOGPOINT.test.js index 6d98f87a8..f8ce4d8aa 100644 --- a/clouds/bigquery/modules/test/h3/H3_FROMGEOGPOINT.test.js +++ b/clouds/bigquery/modules/test/h3/H3_FROMGEOGPOINT.test.js @@ -52,7 +52,6 @@ test('H3_FROMGEOGPOINT returns NULL with non POINT geographies', async () => { ]); }); - test('H3_FROMGEOPOINT returns the proper INT64', async () => { const query = ` WITH inputs AS diff --git a/clouds/snowflake/modules/test/h3/H3_FROMGEOGPOINT.spec.js b/clouds/snowflake/modules/test/h3/H3_FROMGEOGPOINT.test.js similarity index 99% rename from clouds/snowflake/modules/test/h3/H3_FROMGEOGPOINT.spec.js rename to clouds/snowflake/modules/test/h3/H3_FROMGEOGPOINT.test.js index cd3469372..a7f87c809 100644 --- a/clouds/snowflake/modules/test/h3/H3_FROMGEOGPOINT.spec.js +++ b/clouds/snowflake/modules/test/h3/H3_FROMGEOGPOINT.test.js @@ -55,7 +55,6 @@ test('H3_FROMGEOGPOINT returns NULL with non POINT geographies', async () => { ]); }); - test('H3_FROMGEOPOINT returns the proper INT64', async () => { const query = ` WITH inputs AS diff --git a/clouds/snowflake/modules/test/h3/H3_FROMLONGLAT.spec.js b/clouds/snowflake/modules/test/h3/H3_FROMLONGLAT.test.js similarity index 100% rename from clouds/snowflake/modules/test/h3/H3_FROMLONGLAT.spec.js rename to clouds/snowflake/modules/test/h3/H3_FROMLONGLAT.test.js