-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
geo/geomfn: implement ST_LineInterpolatePoint(s) #49742
Conversation
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. I have added a few people who may be able to assist in reviewing:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
Small Overview:
|
8af28d1
to
4d35e3c
Compare
Thank you for updating your pull request. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glad to see you back! looking good, mostly minor nits.
nit: title does not fit in PR message. can you make it:
geo/geomfn: implement ST_LineInterpolatePoint(s)
}, | ||
Info: infoBuilder{ | ||
info: builtinInfo, | ||
libraryUsage: usesGEOS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function does not use an index; please remove canUseIdex: true,
pkg/sql/sem/builtins/geo_builtins.go
Outdated
|
||
Note If the result has zero or one points, it will be returned as a POINT. If it has two or more points, it will be returned as a MULTIPOINT.`, | ||
libraryUsage: usesGEOS, | ||
canUseIndex: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function does not use an index; please remove canUseIdex: true,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done for all places.
pkg/geo/geos/geos.cc
Outdated
@@ -119,6 +120,7 @@ struct CR_GEOS { | |||
CR_GEOS_Area_r GEOSArea_r; | |||
CR_GEOS_Length_r GEOSLength_r; | |||
CR_GEOS_Centroid_r GEOSGetCentroid_r; | |||
CR_GEOS_Interpolate_r GEOSInterpolateNormalized_r; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain why we're using InterpolateNormalized
? if this is required, please rename Interpolate_r
to InterpolateNormalized_r
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed Geos
function which we're using for interpolation. Previously it was GEOSInterpolateNormalized
now it is GEOSInterpolate
and Updated their names according to GEOSInterpolate
.
Initially, I was using GEOSInterpolateNormalized
as it was directly satisfying the use-case as it works with fraction directly.
But later realised that It is wrapper function over GEOSInterpolate
inside which we are computing LineString's
length each time it called.
Which could be inefficient for MULTIPOINT
case as It can be done just computing length only once.
And there may be the case in future where we may require to locate a point at a certain distance. For which GEOSInterpolate
will be the best option rather somehow using GEOSInterpolateNormalized
@@ -1428,3 +1428,72 @@ ORDER BY id | |||
1 4004 0 | |||
2 4326 4326 | |||
3 4004 3857 | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subtest geom_linear
, maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
pkg/sql/sem/builtins/geo_builtins.go
Outdated
defProps(), | ||
lineInterpolatePointForRepeatOverload( | ||
false, | ||
`Returns point along the given LineString which is at given fraction of LineString's total length.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: returns a point
INSERT INTO geom_linear VALUES | ||
('Empty LineString', 'LINESTRING EMPTY'), | ||
('LineString anticlockwise covering all the quadrants', 'LINESTRING(1 -1, 2 2, -2 2, -1 -1)'), | ||
('LineString clockwise covering all the quadrants with SRID 4004', 'SRID=4004;LINESTRING(1 -1, -1 -1, -2 2, 2 2)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add tests to make sure this behaves as appropriate for POLYGON/POINT/MULTILINESTRING?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since POLYGON/POINT/MULTILINESTRING
each of them will produce an error, therefore added separately query for them at the bottom.
Currently, I am unable to figure out how could we add test cases for them by inserting elements in the table.
Similar to this added test case for POLYGON/POINT/MULTILINESTRING
,
in unary_operator_test.go
too.
} | ||
for _, test := range testCasesForLineInterpolate { | ||
for _, repeat := range []bool{false, true} { | ||
t.Run(fmt.Sprintf("%s for fraction %v where repeat is %t", test.wkb, test.fraction, repeat), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: fraction %f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed!
Along with this error message are also changes. As were also using %v
for float in error message too.
4d35e3c
to
7c0c7f8
Compare
bors r+ |
Merge conflict (retrying...) |
Merge conflict |
fixing the conflict for you, moving the file to |
Thank you for the review 😊 |
Fixes cockroachdb#48971 Fixes cockroachdb#48972 This PR adds following builtin functions * ST_LineInterpolatePoint{{geometry, float8}} * ST_LineInterpolatePoints{{geometry, float8, bool}} which works for LineString only, allows us to determine one or more interpolated points in the LineString which at an integral multiple of given fraction of LineString's total length. Release note (sql change): This PR implement adds the following built-in functions. * ST_LineInterpolatePoint{{geometry, float8}} * ST_LineInterpolatePoints{{geometry, float8, bool}}
bors r+ |
Build succeeded |
Fixes #48971
Fixes #48972
This PR adds following builtin functions
which works for LineString only, allows us to determine one or more
interpolated points in the LineString which at an integral multiple
of given fraction of LineString's total length.
Release note (sql change): This PR implement adds the following built-in functions.