@@ -19,7 +19,7 @@ use vortex_array::arrow::ArrowArray;
19
19
use vortex_array:: arrow:: compute:: { ToArrowArgs , ToArrowKernelRef } ;
20
20
use vortex_array:: compute:: { InvocationArgs , Kernel , Output , cast} ;
21
21
use vortex_array:: { Array , ToCanonical , register_kernel} ;
22
- use vortex_dtype:: arrow:: { ArrowMetadata , ArrowMetadataRef , ArrowToDType , ArrowToDTypeRef } ;
22
+ use vortex_dtype:: arrow:: { TypeConversion , TypeConversionRef } ;
23
23
use vortex_dtype:: { DType , ExtDType , PType , register_extension_type} ;
24
24
use vortex_error:: { VortexExpect , VortexResult , vortex_bail, vortex_err} ;
25
25
@@ -68,7 +68,7 @@ fn to_arrow_point(
68
68
point_array : & ExtensionArray ,
69
69
metadata : & GeoMetadata ,
70
70
) -> VortexResult < arrow_array:: ArrayRef > {
71
- let coords = coordinate_buffer ( point_array. storage ( ) , & metadata) ?;
71
+ let coords = coordinate_buffer ( point_array. storage ( ) , metadata) ?;
72
72
let nulls = point_array. validity_mask ( ) ?. to_null_buffer ( ) ;
73
73
let crs = match metadata. crs {
74
74
None => Crs :: default ( ) ,
@@ -88,7 +88,7 @@ fn to_arrow_linestring(
88
88
metadata : & GeoMetadata ,
89
89
) -> VortexResult < arrow_array:: ArrayRef > {
90
90
let list = line_string. to_list ( ) ?;
91
- let coords = coordinate_buffer ( list. elements ( ) . as_ref ( ) , & metadata) ?;
91
+ let coords = coordinate_buffer ( list. elements ( ) . as_ref ( ) , metadata) ?;
92
92
let offsets = cast ( & list. offsets ( ) . to_primitive ( ) ?, & PType :: I32 . into ( ) ) ?
93
93
. to_primitive ( ) ?
94
94
. into_buffer :: < i32 > ( )
@@ -114,26 +114,24 @@ fn to_arrow_linestring(
114
114
pub struct GeoArrowConversion ;
115
115
116
116
// Conversion between Vortex geospatial extension types and GeoArrow extension types.
117
- impl ArrowToDType for GeoArrowConversion {
118
- fn can_convert ( & self , field : & Field ) -> bool {
119
- // The field needs to support all of our types
120
- if let Some ( ext_type) = field. extension_type_name ( ) {
121
- if ext_type == PointType :: NAME
122
- || ext_type == LineStringType :: NAME
123
- || ext_type == PolygonType :: NAME
124
- || ext_type == WkbType :: NAME
125
- {
126
- return true ;
127
- }
128
- }
129
- false
130
- }
131
-
132
- fn to_vortex ( & self , field : & Field ) -> VortexResult < DType > {
117
+ impl TypeConversion for GeoArrowConversion {
118
+ fn to_vortex ( & self , field : & Field ) -> VortexResult < Option < DType > > {
119
+ // Validate that the field is one of the supported geospatial
120
+ // extension types.
133
121
let Some ( ext_type) = field. extension_type_name ( ) else {
134
- vortex_bail ! ( "field does not have an extension type" )
122
+ return Ok ( None ) ;
135
123
} ;
136
124
125
+ println ! ( "ext_type = {}" , ext_type) ;
126
+
127
+ if ext_type != PointType :: NAME
128
+ && ext_type != LineStringType :: NAME
129
+ && ext_type != PolygonType :: NAME
130
+ && ext_type != WkbType :: NAME
131
+ {
132
+ return Ok ( None ) ;
133
+ }
134
+
137
135
macro_rules! dim_from_fields {
138
136
( $fields: expr) => { {
139
137
match $fields. len( ) {
@@ -232,13 +230,15 @@ impl ArrowToDType for GeoArrowConversion {
232
230
_ => vortex_bail ! ( "extension type {} not supported" , ext_type) ,
233
231
} ;
234
232
235
- Ok ( DType :: Extension ( Arc :: new ( ext_dtype) ) )
233
+ Ok ( Some ( DType :: Extension ( Arc :: new ( ext_dtype) ) ) )
236
234
}
237
- }
238
235
239
- impl ArrowMetadata for GeoArrowConversion {
240
236
#[ allow( clippy:: disallowed_types) ]
241
- fn arrow_metadata ( & self , vortex_extension_type : & ExtDType ) -> Option < HashMap < String , String > > {
237
+ fn to_arrow (
238
+ & self ,
239
+ vortex_extension_type : & ExtDType ,
240
+ field : & mut Field ,
241
+ ) -> VortexResult < Option < ( ) > > {
242
242
if let Ok ( geometry) = GeometryType :: try_from ( vortex_extension_type) {
243
243
let mut extension_metadata = HashMap :: new ( ) ;
244
244
let ext_type_name = match geometry {
@@ -249,7 +249,7 @@ impl ArrowMetadata for GeoArrowConversion {
249
249
} ;
250
250
extension_metadata. insert ( EXTENSION_TYPE_NAME_KEY . to_string ( ) , ext_type_name) ;
251
251
252
- match geometry {
252
+ let extension_metadata = match geometry {
253
253
GeometryType :: Point ( meta)
254
254
| GeometryType :: LineString ( meta)
255
255
| GeometryType :: Polygon ( meta)
@@ -264,19 +264,23 @@ impl ArrowMetadata for GeoArrowConversion {
264
264
. vortex_expect ( "failed to serialize geoarrow metadata" ) ;
265
265
extension_metadata
266
266
. insert ( EXTENSION_TYPE_METADATA_KEY . to_string ( ) , metadata_json) ;
267
+ extension_metadata
268
+ } else {
269
+ extension_metadata
267
270
}
268
271
}
269
272
} ;
270
273
271
- Some ( extension_metadata)
274
+ field. set_metadata ( extension_metadata) ;
275
+
276
+ Ok ( Some ( ( ) ) )
272
277
} else {
273
- None
278
+ Ok ( None )
274
279
}
275
280
}
276
281
}
277
282
278
- register_extension_type ! ( ArrowToDTypeRef ( ArcRef :: new_ref( & GeoArrowConversion ) ) ) ;
279
- register_extension_type ! ( ArrowMetadataRef ( ArcRef :: new_ref( & GeoArrowConversion ) ) ) ;
283
+ register_extension_type ! ( TypeConversionRef :: new( ArcRef :: new_ref( & GeoArrowConversion ) ) ) ;
280
284
281
285
/// Unpack the geoarrow CoordBuffer. Errors if the dimensions specified in the metadata do not
282
286
/// match the actual encoding.
@@ -400,7 +404,7 @@ mod tests {
400
404
dimension : crate :: Dimension :: XY ,
401
405
crs : None ,
402
406
} )
403
- . into_ext_dtype ( false . into ( ) ) ;
407
+ . into_ext_dtype ( true . into ( ) ) ;
404
408
assert_eq ! ( dtype, DType :: Extension ( Arc :: new( owned_type) ) ) ;
405
409
406
410
// round trip back to Arrow type.
@@ -424,7 +428,4 @@ mod tests {
424
428
let exported = imported. into_arrow_preferred ( ) . unwrap ( ) ;
425
429
assert_eq ! ( exported. data_type( ) , struct_array. data_type( ) ) ;
426
430
}
427
-
428
- #[ test]
429
- fn test_roundtrip ( ) { }
430
431
}
0 commit comments