-
Notifications
You must be signed in to change notification settings - Fork 29
feat(sql): Implement ST_StartPoint() and ST_EndPoint() #245
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(sql): Implement ST_StartPoint() and ST_EndPoint() #245
Conversation
Thank you!
I think using |
|
Thanks for the hint! Now I figured out how to do it with geo-traits and the functions in wkb_factory.rs. |
|
It seems I still have troubles on running Python tests on my Windows, so I don't run these Python tests yet. I'll try on macOS tomorrow. Anyway, I believe this pull request is ready for review now. |
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.
Just a few things to consider...thank you!
I'll try to work on the Windows development situation soon 😬
| match dim.size() { | ||
| 2 => { | ||
| let coords_tuple = coords.x_y(); | ||
| write_wkb_coord(buf, coords_tuple) | ||
| } | ||
| 3 => { | ||
| let coords_tuple = (coords.x(), coords.y(), coords.nth_or_panic(2)); | ||
| write_wkb_coord(buf, coords_tuple) | ||
| } | ||
| 4 => { | ||
| let coords_tuple = ( | ||
| coords.x(), | ||
| coords.y(), | ||
| coords.nth_or_panic(2), | ||
| coords.nth_or_panic(3), | ||
| ); | ||
| write_wkb_coord(buf, coords_tuple) | ||
| } | ||
| _ => Err(SedonaGeometryError::Invalid( | ||
| "Unsupported number of dimensions".to_string(), | ||
| )), | ||
| } |
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 would fit nicely as wkb_factory::write_wkb_coord_trait() (I'm sure we'll need it again!)
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.
Thanks, moved the implementation to wkb_factory now.
Co-authored-by: Dewey Dunnington <[email protected]>
|
Thanks for reviewing! Sorry, this was unexpected, but I just found the document has this small note
and this is the actual behavior (while the example on the document returns Probably I need some time to update the implementation. |
|
I think this should be ready for review again now! Benchmark result: |
| fn st_start_point_doc() -> Documentation { | ||
| Documentation::builder( | ||
| DOC_SECTION_OTHER, | ||
| "Returns the start point of a LINESTRING geometry. Returns NULL if the geometry is not a LINESTRING.", |
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.
According to https://github.com/apache/sedona-db/pull/245/files#diff-6675d3a4b31524e6b409c5e557bdecd20adb0615fba805d77ba4b52a61c4dae5R142-R143 this is correct for the end point, not for the start one.
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.
It would be good to take care of the documentation and test suggestions here but I this is a great implementation and we can also handle that in a follow-on ticket if needed. Thank you!
| [ | ||
| ("LINESTRING (1 2, 3 4, 5 6)", "POINT (5 6)"), |
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.
NULL and empties would be good to test here, too.
| let input = create_array( | ||
| &[ | ||
| Some("LINESTRING (1 2, 3 4, 5 6)"), |
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.
For full test coverage of your implementation I think we would need to test empty geometries here as well.
Co-authored-by: Dewey Dunnington <[email protected]>
|
Thanks for the great review! Adding tests about empty geometry actually helped me to find a bug in my implementation of |
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.
Thank you!
As many people are adding geos-related functions, I pick this to avoid collision.
At first, I thought this can be implemented viageo_traits::CoordTrait. But, I read the implementation ofST_Pointand felt it's preferable to handle the raw bytes of WKB for performance. While I'm not good at performance, I'm trying to implement it.The remaining tasks are: