-
Notifications
You must be signed in to change notification settings - Fork 198
feat(vortex-spatial): add make-line scalar function #9201
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
Open
HarukiMoriarty
wants to merge
1
commit into
nemo/interleave-primitive-execution
from
nemo/geo-native-bbox-precheck
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| //! Microbenchmarks for native `ST_MakeLine`. | ||
| //! | ||
| //! The cases cover the normal paired-column operation, a broadcast point constant, and strict | ||
| //! null propagation. They execute the result to its canonical representation so the benchmark | ||
| //! includes construction of the two-vertex line storage. | ||
| //! | ||
| //! `ROWS` keeps each case near the roughly 1 ms iteration budget recommended for CodSpeed. | ||
| //! | ||
| //! Run with `cargo bench -p vortex-spatial --bench make_line`. | ||
|
|
||
| #![expect(clippy::unwrap_used)] | ||
|
|
||
| use std::sync::LazyLock; | ||
|
|
||
| use divan::Bencher; | ||
| use divan::counter::ItemsCount; | ||
| use mimalloc::MiMalloc; | ||
| use vortex_array::ArrayRef; | ||
| use vortex_array::Canonical; | ||
| use vortex_array::ExecutionCtx; | ||
| use vortex_array::IntoArray; | ||
| use vortex_array::VortexSessionExecute; | ||
| use vortex_array::arrays::ConstantArray; | ||
| use vortex_session::VortexSession; | ||
| use vortex_spatial::scalar_fn::make_line::SpatialMakeLine; | ||
| use vortex_spatial::test_harness::nullable_point_column; | ||
| use vortex_spatial::test_harness::point_column; | ||
| use vortex_spatial::test_harness::spatial_session; | ||
|
|
||
| // Scalar function execution allocates its output inside the timed region, so use the vendored | ||
| // allocator instead of measuring glibc differences between CodSpeed runner images. | ||
| #[global_allocator] | ||
| static GLOBAL: MiMalloc = MiMalloc; | ||
|
|
||
| static SESSION: LazyLock<VortexSession> = LazyLock::new(spatial_session); | ||
|
|
||
| const ROWS: usize = 512; | ||
|
|
||
| fn main() { | ||
| divan::main(); | ||
| } | ||
|
|
||
| /// Deterministic pseudo-random value in `[0, 1)`. | ||
| fn unit(i: usize) -> f64 { | ||
| ((i.wrapping_mul(2_654_435_761) >> 8) % 10_000) as f64 / 10_000.0 | ||
| } | ||
|
|
||
| fn points(offset: usize) -> ArrayRef { | ||
| let xs = (0..ROWS) | ||
| .map(|i| 300.0 * unit(i + offset) - 150.0) | ||
| .collect(); | ||
| let ys = (0..ROWS) | ||
| .map(|i| 300.0 * unit(i + offset + 1) - 150.0) | ||
| .collect(); | ||
| point_column(xs, ys).unwrap() | ||
| } | ||
|
|
||
| fn nullable_points(offset: usize, null_every: usize) -> ArrayRef { | ||
| nullable_point_column( | ||
| (0..ROWS) | ||
| .map(|i| { | ||
| (!i.is_multiple_of(null_every)).then(|| { | ||
| ( | ||
| 300.0 * unit(i + offset) - 150.0, | ||
| 300.0 * unit(i + offset + 1) - 150.0, | ||
| ) | ||
| }) | ||
| }) | ||
| .collect(), | ||
| ) | ||
| .unwrap() | ||
| } | ||
|
|
||
| fn point_constant(ctx: &mut ExecutionCtx) -> ArrayRef { | ||
| let scalar = point_column(vec![0.0], vec![0.0]) | ||
| .unwrap() | ||
| .execute_scalar(0, ctx) | ||
| .unwrap(); | ||
| ConstantArray::new(scalar, ROWS).into_array() | ||
| } | ||
|
|
||
| fn make_lines(starts: &ArrayRef, ends: &ArrayRef, ctx: &mut ExecutionCtx) -> ArrayRef { | ||
| SpatialMakeLine::try_new_array(starts.clone(), ends.clone()) | ||
| .unwrap() | ||
| .into_array() | ||
| .execute::<Canonical>(ctx) | ||
| .unwrap() | ||
| .into_array() | ||
| } | ||
|
|
||
| #[divan::bench] | ||
| fn column_x_column(bencher: Bencher) { | ||
| let starts = points(0); | ||
| let ends = points(97); | ||
| let mut ctx = SESSION.create_execution_ctx(); | ||
| bencher | ||
| .counter(ItemsCount::new(ROWS)) | ||
| .bench_local(|| make_lines(&starts, &ends, &mut ctx)); | ||
| } | ||
|
|
||
| #[divan::bench] | ||
| fn column_x_constant(bencher: Bencher) { | ||
| let starts = points(0); | ||
| let mut ctx = SESSION.create_execution_ctx(); | ||
| let end = point_constant(&mut ctx); | ||
| bencher | ||
| .counter(ItemsCount::new(ROWS)) | ||
| .bench_local(|| make_lines(&starts, &end, &mut ctx)); | ||
| } | ||
|
|
||
| #[divan::bench] | ||
| fn nullable_columns(bencher: Bencher) { | ||
| let starts = nullable_points(0, 8); | ||
| let ends = nullable_points(97, 11); | ||
| let mut ctx = SESSION.create_execution_ctx(); | ||
| bencher | ||
| .counter(ItemsCount::new(ROWS)) | ||
| .bench_local(|| make_lines(&starts, &ends, &mut ctx)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
in what cases do you ever run into an "absent ordinate", and is returning 0.0 really ok here? instead of null, for example?
its a bit hard for me to understand why we want this behavior in the create linestring functionality
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.
“absent ordinate” only occurs with mixed-dimensional inputs. We promote the output dimension to the union of both inputs and fill missing Z/M values with zero, matching DuckDB’s ST_MakeLine behavior.
Null would represent a null coordinate inside an otherwise valid geometry and is not supported by the native LineString coordinate storage.
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.
e.g. XYZ + XYM → LINESTRING ZM (..., 2 2 0 3) https://github.com/duckdb/duckdb-spatial/blob/c27bc2b0091f75e97c189d345f37a3771dfef89c/test/sql/geometry/st_makeline.test