Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ adbc_ffi = { git = "https://github.com/apache/arrow-adbc.git", package = "adbc_f

# TODO: remove them once changes we made to geo-index and wkb crates are merged to upstream and released
geo-index = { git = "https://github.com/wherobots/geo-index.git", branch = "main" }
wkb = { git = "https://github.com/georust/wkb.git", rev = "130eb0c2b343bc9299aeafba6d34c2a6e53f3b6a" }
wkb = { git = "https://github.com/georust/wkb.git", rev = "3158e6295e4a39dc7fd75f3cfebee113c8b844d0" }
45 changes: 9 additions & 36 deletions rust/sedona-functions/src/st_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use sedona_schema::{
datatypes::{SedonaType, WKB_GEOMETRY},
matchers::ArgMatcher,
};
use std::sync::Arc;
use std::{io::Write, sync::Arc};

use crate::executor::WkbExecutor;

Expand Down Expand Up @@ -64,14 +64,6 @@ fn st_dump_doc() -> Documentation {
#[derive(Debug)]
struct STDump;

// This enum is solely for passing the subset of wkb geometry to STDumpStructBuilder.
// Maybe we can pass the underlying raw WKB bytes directly, but this just works for now.
enum SingleWkb<'a> {
Point(&'a wkb::reader::Point<'a>),
LineString(&'a wkb::reader::LineString<'a>),
Polygon(&'a wkb::reader::Polygon<'a>),
}

// A builder for a list of the structs
struct STDumpBuilder {
path_array_builder: UInt32Builder,
Expand Down Expand Up @@ -102,7 +94,7 @@ impl STDumpBuilder {
}

// This appends both path and geom at once.
fn append_single_struct(&mut self, cur_index: Option<u32>, wkb: SingleWkb<'_>) -> Result<()> {
fn append_single_struct(&mut self, cur_index: Option<u32>, wkb: &[u8]) -> Result<()> {
self.path_array_builder.append_slice(&self.parent_path);
if let Some(cur_index) = cur_index {
self.path_array_builder.append_value(cur_index);
Expand All @@ -113,23 +105,7 @@ impl STDumpBuilder {
.push_length(self.parent_path.len());
}

let write_result = match wkb {
SingleWkb::Point(point) => {
wkb::writer::write_point(&mut self.geom_builder, &point, &Default::default())
}
SingleWkb::LineString(line_string) => wkb::writer::write_line_string(
&mut self.geom_builder,
&line_string,
&Default::default(),
),
SingleWkb::Polygon(polygon) => {
wkb::writer::write_polygon(&mut self.geom_builder, &polygon, &Default::default())
}
};
if let Err(e) = write_result {
return sedona_internal_err!("Failed to write WKB: {e}");
}

self.geom_builder.write_all(wkb)?;
self.geom_builder.append_value([]);

Ok(())
Expand All @@ -138,35 +114,32 @@ impl STDumpBuilder {
fn append_structs(&mut self, wkb: &wkb::reader::Wkb<'_>) -> Result<i32> {
match wkb.as_type() {
GeometryType::Point(point) => {
self.append_single_struct(None, SingleWkb::Point(point))?;
self.append_single_struct(None, point.buf())?;
Ok(1)
}
GeometryType::LineString(line_string) => {
self.append_single_struct(None, SingleWkb::LineString(line_string))?;
self.append_single_struct(None, line_string.buf())?;
Ok(1)
}
GeometryType::Polygon(polygon) => {
self.append_single_struct(None, SingleWkb::Polygon(polygon))?;
self.append_single_struct(None, polygon.buf())?;
Ok(1)
}
GeometryType::MultiPoint(multi_point) => {
for (index, point) in multi_point.points().enumerate() {
self.append_single_struct(Some((index + 1) as _), SingleWkb::Point(&point))?;
self.append_single_struct(Some((index + 1) as _), point.buf())?;
}
Ok(multi_point.num_points() as _)
}
GeometryType::MultiLineString(multi_line_string) => {
for (index, line_string) in multi_line_string.line_strings().enumerate() {
self.append_single_struct(
Some((index + 1) as _),
SingleWkb::LineString(line_string),
)?;
self.append_single_struct(Some((index + 1) as _), line_string.buf())?;
}
Ok(multi_line_string.num_line_strings() as _)
}
GeometryType::MultiPolygon(multi_polygon) => {
for (index, polygon) in multi_polygon.polygons().enumerate() {
self.append_single_struct(Some((index + 1) as _), SingleWkb::Polygon(polygon))?;
self.append_single_struct(Some((index + 1) as _), polygon.buf())?;
}
Ok(multi_polygon.num_polygons() as _)
}
Expand Down
Loading