Skip to content

Commit 3bb797a

Browse files
authored
chore(bq,sf,rs,pg|h3,quadbin): added "geo" aliases for certain functions (#526)
1 parent c0b02a7 commit 3bb797a

22 files changed

+216
-25
lines changed

clouds/bigquery/modules/doc/h3/H3_FROMGEOGPOINT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ H3_FROMGEOGPOINT(point, resolution)
66

77
**Description**
88

9-
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).
9+
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`.
1010

1111
* `point`: `GEOGRAPHY` point to get the H3 cell from.
1212
* `resolution`: `INT64` number between 0 and 15 with the [H3 resolution](https://h3geo.org/docs/core-library/restable).

clouds/bigquery/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ QUADBIN_FROMGEOGPOINT(point, resolution)
66

77
**Description**
88

9-
Returns the Quadbin of a given point at a given level of detail.
9+
Returns the Quadbin of a given point at a given level of detail. This function is an alias for `QUADBIN_FROMGEOPOINT`.
1010

1111
* `point`: `GEOGRAPHY` point to get the Quadbin from.
1212
* `resolution`: `INT64` level of detail or zoom.
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
----------------------------
2-
-- Copyright (C) 2021 CARTO
3-
----------------------------
1+
--------------------------------
2+
-- Copyright (C) 2021-2024 CARTO
3+
--------------------------------
44

55
CREATE OR REPLACE FUNCTION `@@BQ_DATASET@@.H3_FROMGEOGPOINT`
66
(geog GEOGRAPHY, resolution INT64)
@@ -10,3 +10,12 @@ AS (
1010
SAFE.ST_X(geog), SAFE.ST_Y(geog), resolution
1111
)
1212
);
13+
14+
CREATE OR REPLACE FUNCTION `@@BQ_DATASET@@.H3_FROMGEOPOINT`
15+
(geo GEOGRAPHY, resolution INT64)
16+
RETURNS STRING
17+
AS (
18+
`@@BQ_DATASET@@.H3_FROMGEOGPOINT`(
19+
geo, resolution
20+
)
21+
);
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
----------------------------
2-
-- Copyright (C) 2022 CARTO
3-
----------------------------
1+
--------------------------------
2+
-- Copyright (C) 2022-2024 CARTO
3+
--------------------------------
44

55
CREATE OR REPLACE FUNCTION `@@BQ_DATASET@@.QUADBIN_FROMGEOGPOINT`
66
(point GEOGRAPHY, resolution INT64)
@@ -10,3 +10,12 @@ AS (
1010
ST_X(point), ST_Y(point), resolution
1111
)
1212
);
13+
14+
CREATE OR REPLACE FUNCTION `@@BQ_DATASET@@.QUADBIN_FROMGEOPOINT`
15+
(point GEOGRAPHY, resolution INT64)
16+
RETURNS INT64
17+
AS (
18+
`@@BQ_DATASET@@.QUADBIN_FROMGEOGPOINT`(
19+
point, resolution
20+
)
21+
);

clouds/bigquery/modules/test/h3/H3_FROMGEOGPOINT.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,35 @@ test('H3_FROMGEOGPOINT returns NULL with non POINT geographies', async () => {
5050
null,
5151
null
5252
]);
53+
});
54+
55+
test('H3_FROMGEOPOINT returns the proper INT64', async () => {
56+
const query = `
57+
WITH inputs AS
58+
(
59+
SELECT 1 AS id, ST_GEOGPOINT(-122.0553238, 37.3615593) as geom, 5 as resolution UNION ALL
60+
SELECT 2 AS id, ST_GEOGPOINT(-164.991559, 30.943387) as geom, 5 as resolution UNION ALL
61+
SELECT 3 AS id, ST_GEOGPOINT(71.52790329909925, 46.04189431883772) as geom, 15 as resolution UNION ALL
62+
63+
-- null inputs
64+
SELECT 4 AS id, NULL AS geom, 5 as resolution UNION ALL
65+
SELECT 5 AS id, ST_GEOGPOINT(-122.0553238, 37.3615593) as geom, -1 as resolution UNION ALL
66+
SELECT 6 AS id, ST_GEOGPOINT(-122.0553238, 37.3615593) as geom, 20 as resolution UNION ALL
67+
SELECT 7 AS id, ST_GEOGPOINT(-122.0553238, 37.3615593) as geom, NULL as resolution
68+
)
69+
SELECT CAST(\`@@BQ_DATASET@@.H3_FROMGEOPOINT\`(geom, resolution) AS STRING) as h3_id
70+
FROM inputs
71+
ORDER BY id ASC
72+
`;
73+
const rows = await runQuery(query);
74+
expect(rows.length).toEqual(7);
75+
expect(rows.map((r) => r.h3_id)).toEqual([
76+
'85283473fffffff',
77+
'8547732ffffffff',
78+
'8f2000000000000',
79+
null,
80+
null,
81+
null,
82+
null
83+
]);
5384
});

clouds/bigquery/modules/test/quadbin/QUADBIN_FROMGEOGPOINT.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@ test('QUADBIN_FROMGEOGPOINT should work', async () => {
55
const rows = await runQuery(query);
66
expect(rows.length).toEqual(1);
77
expect(rows[0].output).toEqual('5209574053332910079');
8+
});
9+
10+
test('QUADBIN_FROMGEOPOINT should work', async () => {
11+
const query = 'SELECT CAST(`@@BQ_DATASET@@.QUADBIN_FROMGEOPOINT`(ST_GEOGPOINT(40.4168, -3.7038), 4) AS STRING) AS output';
12+
const rows = await runQuery(query);
13+
expect(rows.length).toEqual(1);
14+
expect(rows[0].output).toEqual('5209574053332910079');
815
});

clouds/postgres/modules/doc/h3/H3_FROMGEOGPOINT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ H3_FROMGEOGPOINT(point, resolution)
66

77
**Description**
88

9-
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).
9+
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`.
1010

1111
* `point`: `GEOMETRY` point to get the H3 cell from.
1212
* `resolution`: `INT` number between 0 and 15 with the [H3 resolution](https://h3geo.org/docs/core-library/restable).

clouds/postgres/modules/doc/quadbin/QUADBIN_FROMGEOGPOINT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ QUADBIN_FROMGEOGPOINT(point, resolution)
66

77
**Description**
88

9-
Returns the Quadbin of a given point at a given level of detail.
9+
Returns the Quadbin of a given point at a given level of detail. This function is an alias for `QUADBIN_FROMGEOPOINT`.
1010

1111
* `point`: `GEOMETRY` point to get the Quadbin from.
1212
* `resolution`: `BIGINT` level of detail or zoom.

clouds/postgres/modules/sql/h3/H3_FROMGEOGPOINT.sql

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
----------------------------
2-
-- Copyright (C) 2023 CARTO
3-
----------------------------
1+
--------------------------------
2+
-- Copyright (C) 2023-2024 CARTO
3+
--------------------------------
44

55
CREATE OR REPLACE FUNCTION @@PG_SCHEMA@@.H3_FROMGEOGPOINT(
66
geog GEOMETRY,
@@ -17,3 +17,14 @@ $BODY$
1717
END
1818
$BODY$
1919
LANGUAGE sql IMMUTABLE PARALLEL SAFE;
20+
21+
CREATE OR REPLACE FUNCTION @@PG_SCHEMA@@.H3_FROMGEOPOINT(
22+
geo GEOMETRY,
23+
resolution INT
24+
)
25+
RETURNS VARCHAR(16)
26+
AS
27+
$BODY$
28+
SELECT @@PG_SCHEMA@@.H3_FROMGEOGPOINT(geo, resolution)
29+
$BODY$
30+
LANGUAGE sql IMMUTABLE PARALLEL SAFE;

clouds/postgres/modules/sql/quadbin/QUADBIN_FROMGEOGPOINT.sql

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
----------------------------
2-
-- Copyright (C) 2022 CARTO
3-
----------------------------
1+
--------------------------------
2+
-- Copyright (C) 2022-2024 CARTO
3+
--------------------------------
44

55
CREATE OR REPLACE FUNCTION @@PG_SCHEMA@@.QUADBIN_FROMGEOGPOINT(
66
point GEOMETRY,
@@ -20,3 +20,14 @@ $BODY$
2020
FROM __geom4326;
2121
$BODY$
2222
LANGUAGE sql IMMUTABLE PARALLEL SAFE;
23+
24+
CREATE OR REPLACE FUNCTION @@PG_SCHEMA@@.QUADBIN_FROMGEOPOINT(
25+
point GEOMETRY,
26+
resolution INT
27+
)
28+
RETURNS BIGINT
29+
AS
30+
$BODY$
31+
SELECT @@PG_SCHEMA@@.QUADBIN_FROMGEOGPOINT(point, resolution)
32+
$BODY$
33+
LANGUAGE sql IMMUTABLE PARALLEL SAFE;

0 commit comments

Comments
 (0)