Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(bq,sf,rs,pg|quadbin): add function QUADBIN_DISTANCE #457

Merged
merged 8 commits into from
Dec 28, 2023

Conversation

vdelacruzb
Copy link
Contributor

@vdelacruzb vdelacruzb commented Dec 27, 2023

Description

Shortcut

Type of change

  • Feature

Acceptance

-- BQ 
SELECT `cartodb-data-engineering-team`.vdelacruz_carto.QUADBIN_DISTANCE(5207251884775047167, 5207251884775047167);
-- 0
SELECT `cartodb-data-engineering-team`.vdelacruz_carto.QUADBIN_DISTANCE(5207251884775047167, 5207128739472736255);
-- 1
SELECT `cartodb-data-engineering-team`.vdelacruz_carto.QUADBIN_DISTANCE(`carto-un`.carto.QUADBIN_FROMZXY(5,1,5), `carto-un`.carto.QUADBIN_FROMZXY(5,2,7))
-- 2
SELECT `cartodb-data-engineering-team`.vdelacruz_carto.QUADBIN_DISTANCE(`carto-un`.carto.QUADBIN_FROMZXY(5,1,5), `carto-un`.carto.QUADBIN_FROMZXY(6,2,7))
-- NULL
SELECT `cartodb-data-engineering-team`.vdelacruz_carto.QUADBIN_DISTANCE(NULL, 5207128739472736255);
-- NULL
SELECT `cartodb-data-engineering-team`.vdelacruz_carto.QUADBIN_DISTANCE(5207128739472736255, NULL);
-- NULL

-- SF
SELECT CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.QUADBIN_DISTANCE(5207251884775047167, 5207251884775047167);
-- 0
SELECT CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.QUADBIN_DISTANCE(5207251884775047167, 5207128739472736255);
-- 1
SELECT CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.QUADBIN_DISTANCE(CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.QUADBIN_FROMZXY(5,1,5), CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.QUADBIN_FROMZXY(5,2,7));
-- 2
SELECT CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.QUADBIN_DISTANCE(CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.QUADBIN_FROMZXY(5,1,5), CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.QUADBIN_FROMZXY(6,2,7));
-- NULL
SELECT CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.QUADBIN_DISTANCE(NULL, 5207128739472736255);
-- NULL
SELECT CARTO_DATA_ENGINEERING_TEAM.vdelacruz_carto.QUADBIN_DISTANCE(5207128739472736255, NULL);

-- RS
SELECT vdelacruz_carto.QUADBIN_DISTANCE(5207251884775047167, 5207251884775047167);
-- 0
SELECT vdelacruz_carto.QUADBIN_DISTANCE(5207251884775047167, 5207128739472736255);
-- 1
SELECT vdelacruz_carto.QUADBIN_DISTANCE(vdelacruz_carto.QUADBIN_FROMZXY(5,1,5), vdelacruz_carto.QUADBIN_FROMZXY(5,2,7));
-- 2
SELECT vdelacruz_carto.QUADBIN_DISTANCE(vdelacruz_carto.QUADBIN_FROMZXY(5,1,5), vdelacruz_carto.QUADBIN_FROMZXY(6,2,7));
-- NULL
SELECT vdelacruz_carto.QUADBIN_DISTANCE(NULL, 5207128739472736255);
-- NULL
SELECT vdelacruz_carto.QUADBIN_DISTANCE(5207128739472736255, NULL);
-- NULL

-- PG
SELECT vdelacruz_carto.QUADBIN_DISTANCE(5207251884775047167, 5207251884775047167);
-- 0
SELECT vdelacruz_carto.QUADBIN_DISTANCE(5207251884775047167, 5207128739472736255);
-- 1
SELECT vdelacruz_carto.QUADBIN_DISTANCE(vdelacruz_carto.QUADBIN_FROMZXY(5,1,5), vdelacruz_carto.QUADBIN_FROMZXY(5,2,7));
-- 2
SELECT vdelacruz_carto.QUADBIN_DISTANCE(vdelacruz_carto.QUADBIN_FROMZXY(5,1,5), vdelacruz_carto.QUADBIN_FROMZXY(6,2,7));
-- NULL
SELECT vdelacruz_carto.QUADBIN_DISTANCE(NULL, 5207128739472736255);
-- NULL
SELECT vdelacruz_carto.QUADBIN_DISTANCE(5207128739472736255, NULL);
-- NULL

Copy link

This pull request has been linked to Shortcut Story #318681: Missing QUADBIN_DISTANCE in AT.

@vdelacruzb vdelacruzb requested a review from jgoizueta December 27, 2023 19:18

**Description**

Returns the **Chebyshev distance** between two quadbin indexes. Returns `null` on invalid inputs.
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps "the Chebyshev distance in quadbin cells between two quadbin indexes" ? but I'm not sure, it might be confusing... the Chebyshev distance in number of quadbin cells between two quadbin indexes" ?? I'm not sure yet.

We could also add a comment about both indices needing to be of the same resultion.

Copy link
Contributor

Choose a reason for hiding this comment

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

On second thought, if the reader understands what Chebyshev distance is (or they have looked it up), they probably have figured out what this that, so we can leave that sentence as it. But I would add:

The origin and destination indices must have the same resolution. Otherwise NULL will be returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

**Description**

Returns the **Chebyshev distance** between two quadbin indexes. Returns `null` on invalid inputs.

Copy link
Contributor

Choose a reason for hiding this comment

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

same as BQ:

The origin and destination indices must have the same resolution. Otherwise NULL will be returned.

NULL
ELSE
GREATEST(
ABS((destination_coords->>'x')::DOUBLE PRECISION - (origin_coords->>'x')::DOUBLE PRECISION),
Copy link
Contributor

Choose a reason for hiding this comment

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

minor thing: I guess we could cast the coordinates to to BIGINT as well, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually the DOUBLE PRECISION was intended here. As I took the approach used in QUADBIN_CENTER but BIGINT makes more sense, will add it.

**Description**

Returns the **Chebyshev distance** between two quadbin indexes. Returns `null` on invalid inputs.

Copy link
Contributor

Choose a reason for hiding this comment

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

same as BQ:

The origin and destination indices must have the same resolution. Otherwise NULL will be returned.

**Description**

Returns the **Chebyshev distance** between two quadbin indexes. Returns `null` on invalid inputs.

Copy link
Contributor

Choose a reason for hiding this comment

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

same as BQ:

The origin and destination indices must have the same resolution. Otherwise NULL will be returned.

Copy link
Contributor

@jgoizueta jgoizueta left a comment

Choose a reason for hiding this comment

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

LGTM

@vdelacruzb vdelacruzb merged commit e5ab01b into main Dec 28, 2023
20 checks passed
@vdelacruzb vdelacruzb deleted the bug/sc-318681/missing-quadbin-distance-in-at branch December 28, 2023 14:06

**Return type**

`GEOGRAPHY`
Copy link
Member

Choose a reason for hiding this comment

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

INT64


**Return type**

`GEOGRAPHY`
Copy link
Member

Choose a reason for hiding this comment

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

BIGINT


**Return type**

`GEOGRAPHY`
Copy link
Member

Choose a reason for hiding this comment

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

BIGINT


**Return type**

`GEOGRAPHY`
Copy link
Member

Choose a reason for hiding this comment

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

BIGINT

@vdelacruzb vdelacruzb mentioned this pull request Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants