11use std:: any:: Any ;
2- use std:: sync:: { Arc , OnceLock } ;
2+ use std:: sync:: { Arc , LazyLock , OnceLock } ;
33
44use arrow_array:: { Array , BinaryArray } ;
55use arrow_schema:: { DataType , FieldRef } ;
@@ -16,25 +16,29 @@ use geoarrow_array::cast::{from_wkb, to_wkb};
1616use geoarrow_schema:: { CoordType , GeoArrowType , GeometryType , Metadata } ;
1717use geos:: { Geom , Geometry } ;
1818
19+ use crate :: data_types:: any_geometry_type;
1920use 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 ) ]
2335pub struct LineMerge {
24- signature : Signature ,
2536 coord_type : CoordType ,
2637}
2738
2839impl 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