Skip to content

Commit f9143a9

Browse files
committed
refactor: Strongly typed inputs
1 parent f973ced commit f9143a9

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

rust/geodatafusion/src/data_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use geoarrow_schema::{
77
MultiLineStringType, MultiPointType, MultiPolygonType, PointType, PolygonType,
88
};
99

10-
fn any_geometry_type() -> Vec<DataType> {
10+
pub(crate) fn any_geometry_type() -> Vec<DataType> {
1111
let expected_capacity = (2 * 4 * 7) + 2 + 4 + 3 + 3;
1212
let mut valid_types = Vec::with_capacity(expected_capacity);
1313

rust/geodatafusion/src/udf/geos/processing/line_merge.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::any::Any;
2-
use std::sync::{Arc, OnceLock};
2+
use std::sync::{Arc, LazyLock, OnceLock};
33

44
use arrow_array::{Array, BinaryArray};
55
use arrow_schema::{DataType, FieldRef};
@@ -16,25 +16,29 @@ use geoarrow_array::cast::{from_wkb, to_wkb};
1616
use geoarrow_schema::{CoordType, GeoArrowType, GeometryType, Metadata};
1717
use geos::{Geom, Geometry};
1818

19+
use crate::data_types::any_geometry_type;
1920
use crate::error::GeoDataFusionResult;
2021

22+
/// A single geometry argument, optionally followed by the `directed` boolean.
23+
static SIGNATURE: LazyLock<Signature> = LazyLock::new(|| {
24+
let geometry_types = any_geometry_type();
25+
let mut variants = Vec::with_capacity(geometry_types.len() * 2);
26+
for geometry_type in geometry_types {
27+
variants.push(TypeSignature::Exact(vec![geometry_type.clone()]));
28+
variants.push(TypeSignature::Exact(vec![geometry_type, DataType::Boolean]));
29+
}
30+
Signature::one_of(variants, Volatility::Immutable)
31+
});
32+
2133
/// Sews together the component lines of a (multi)linestring.
2234
#[derive(Debug, Eq, PartialEq, Hash)]
2335
pub struct LineMerge {
24-
signature: Signature,
2536
coord_type: CoordType,
2637
}
2738

2839
impl LineMerge {
2940
pub fn new(coord_type: CoordType) -> Self {
30-
Self {
31-
// A single geometry argument, optionally followed by the `directed` boolean.
32-
signature: Signature::one_of(
33-
vec![TypeSignature::Any(1), TypeSignature::Any(2)],
34-
Volatility::Immutable,
35-
),
36-
coord_type,
37-
}
41+
Self { coord_type }
3842
}
3943
}
4044

@@ -56,7 +60,7 @@ impl ScalarUDFImpl for LineMerge {
5660
}
5761

5862
fn signature(&self) -> &Signature {
59-
&self.signature
63+
&SIGNATURE
6064
}
6165

6266
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {

0 commit comments

Comments
 (0)