Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(sf|random): ST_GENERATEPOINTS was not accepting column names #480

Merged

Conversation

vdelacruzb
Copy link
Contributor

Description

Shortcut

Updated the implementation to make if full Javascript. It's 3x faster and ensures to get the exact number of points.
On the other side I'm returning the JSON.stringified version as it was working before. Noticed that it wouldn't be needed but kept it as it was just in case.

Type of change

  • Fix

Acceptance

CREATE or replace TABLE CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.test_random_points AS
SELECT TO_GEOGRAPHY('POLYGON((0 0, 10 0, 10 10, 0 0))') as geog, 1230 as npoints
UNION ALL
SELECT TO_GEOGRAPHY('POLYGON((0 0, -10 0, -10 -10, 0 0))') as geog, 2340 as npoints;

with _a AS (
SELECT CARTO_DEV_DATA.CARTO.ST_GENERATEPOINTS(TO_GEOGRAPHY('POLYGON((0 0, 10 0, 10 10, 0 0))'), 1000) arr
)
SELECT ST_NPOINTS(TO_GEOGRAPHY(element.VALUE)) FROM a, LATERAL FLATTEN(input=>arr) as element
;
-- OK 628 ms

WITH _a AS (
SELECT CARTO_DEV_DATA.CARTO.ST_GENERATEPOINTS(geog, npoints) arr
FROM CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.test_random_points
)
SELECT ST_NPOINTS(TO_GEOGRAPHY(element.VALUE)) FROM _a, LATERAL FLATTEN(input=>arr) as element
;
-- Unsupported subquery type cannot be evaluated

with _a AS (
SELECT CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.ST_GENERATEPOINTS(TO_GEOGRAPHY('POLYGON((0 0, 10 0, 10 10, 0 0))'), 1000) arr
)
SELECT ST_NPOINTS(TO_GEOGRAPHY(element.VALUE)) FROM _a, LATERAL FLATTEN(input=>arr) as element
;
-- OK 137 ms

WITH _a AS (
SELECT CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.ST_GENERATEPOINTS(geog, npoints) arr
FROM CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.test_random_points
)
SELECT ST_NPOINTS(TO_GEOGRAPHY(element.VALUE)) FROM _a, LATERAL FLATTEN(input=>arr) as element
;
-- OK 361 ms

@vdelacruzb vdelacruzb requested a review from Jesus89 February 12, 2024 16:40
Copy link

Copy link
Member

@Jesus89 Jesus89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, after fixing CI

@vdelacruzb vdelacruzb requested a review from Jesus89 February 12, 2024 18:47
@vdelacruzb
Copy link
Contributor Author

LGTM, after fixing CI

It seems that processing tests were malfunctioning, just fixed them. Also updated the test to use a table in ST_GENERATEPOINTS.

@vdelacruzb vdelacruzb merged commit 5fde517 into main Feb 13, 2024
10 checks passed
@vdelacruzb vdelacruzb deleted the bug/sc-386028/bug-report-st-generatepoints-function-not branch February 13, 2024 11:12
@Jesus89 Jesus89 mentioned this pull request Feb 15, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants