Skip to content

Commit 11e2993

Browse files
authored
chore: Refactor with_aliases to a more builder-like pattern (#178)
1 parent a15844b commit 11e2993

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

rust/sedona-expr/src/scalar_udf.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,13 @@ impl SedonaScalarUDF {
139139
}
140140
}
141141

142-
pub fn new_with_aliases(
143-
name: &str,
144-
kernels: Vec<ScalarKernelRef>,
145-
volatility: Volatility,
146-
documentation: Option<Documentation>,
147-
aliases: Vec<String>,
148-
) -> SedonaScalarUDF {
149-
let signature = Signature::user_defined(volatility);
142+
/// Add aliases to an existing SedonaScalarUDF
143+
pub fn with_aliases(self, aliases: Vec<String>) -> SedonaScalarUDF {
150144
Self {
151-
name: name.to_string(),
152-
signature,
153-
kernels,
154-
documentation,
145+
name: self.name,
146+
signature: self.signature,
147+
kernels: self.kernels,
148+
documentation: self.documentation,
155149
aliases,
156150
}
157151
}

rust/sedona-functions/src/st_asbinary.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ use sedona_schema::{datatypes::SedonaType, matchers::ArgMatcher};
2828
///
2929
/// An implementation of WKB writing using GeoRust's wkt crate.
3030
pub fn st_asbinary_udf() -> SedonaScalarUDF {
31-
SedonaScalarUDF::new_with_aliases(
31+
let udf = SedonaScalarUDF::new(
3232
"st_asbinary",
3333
vec![Arc::new(STAsBinary {})],
3434
Volatility::Immutable,
3535
Some(st_asbinary_doc()),
36-
vec!["st_aswkb".to_string()],
37-
)
36+
);
37+
udf.with_aliases(vec!["st_aswkb".to_string()])
3838
}
3939

4040
fn st_asbinary_doc() -> Documentation {

rust/sedona-functions/src/st_astext.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ use sedona_schema::{datatypes::SedonaType, matchers::ArgMatcher};
3030
///
3131
/// An implementation of WKT writing using GeoRust's wkt crate.
3232
pub fn st_astext_udf() -> SedonaScalarUDF {
33-
SedonaScalarUDF::new_with_aliases(
33+
let udf = SedonaScalarUDF::new(
3434
"st_astext",
3535
vec![Arc::new(STAsText {})],
3636
Volatility::Immutable,
3737
Some(st_astext_doc()),
38-
vec!["st_aswkt".to_string()],
39-
)
38+
);
39+
udf.with_aliases(vec!["st_aswkt".to_string()])
4040
}
4141

4242
fn st_astext_doc() -> Documentation {

rust/sedona-functions/src/st_geomfromwkt.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,31 @@ use crate::executor::WkbExecutor;
3939
/// An implementation of WKT reading using GeoRust's wkt crate.
4040
/// See [`st_geogfromwkt_udf`] for the corresponding geography function.
4141
pub fn st_geomfromwkt_udf() -> SedonaScalarUDF {
42-
SedonaScalarUDF::new_with_aliases(
42+
let udf = SedonaScalarUDF::new(
4343
"st_geomfromwkt",
4444
vec![Arc::new(STGeoFromWKT {
4545
out_type: WKB_GEOMETRY,
4646
})],
4747
Volatility::Immutable,
4848
Some(doc("ST_GeomFromWKT", "Geometry")),
49-
vec!["st_geomfromtext".to_string()],
50-
)
49+
);
50+
udf.with_aliases(vec!["st_geomfromtext".to_string()])
5151
}
5252

5353
/// ST_GeogFromWKT() UDF implementation
5454
///
5555
/// An implementation of WKT reading using GeoRust's wkt crate.
5656
/// See [`st_geomfromwkt_udf`] for the corresponding geometry function.
5757
pub fn st_geogfromwkt_udf() -> SedonaScalarUDF {
58-
SedonaScalarUDF::new_with_aliases(
58+
let udf = SedonaScalarUDF::new(
5959
"st_geogfromwkt",
6060
vec![Arc::new(STGeoFromWKT {
6161
out_type: WKB_GEOGRAPHY,
6262
})],
6363
Volatility::Immutable,
6464
Some(doc("ST_GeogFromWKT", "Geography")),
65-
vec!["st_geogfromtext".to_string()],
66-
)
65+
);
66+
udf.with_aliases(vec!["st_geogfromtext".to_string()])
6767
}
6868

6969
fn doc(name: &str, out_type_name: &str) -> Documentation {

0 commit comments

Comments
 (0)