@@ -24,7 +24,7 @@ use crate::auth::{build_auth_config, OAuthParams};
2424use crate :: executed_async:: ExecutedAsyncStatement ;
2525use crate :: metadata:: Metadata ;
2626use crate :: statement:: Statement ;
27- use databricks_sql_kernel:: Session as KSession ;
27+ use databricks_sql_kernel:: { GeospatialResultRepresentation , Session as KSession } ;
2828use pyo3:: prelude:: * ;
2929use std:: collections:: HashMap ;
3030use std:: sync:: Arc ;
@@ -140,6 +140,18 @@ fn build_telemetry_config(
140140 Ok ( telemetry)
141141}
142142
143+ fn geospatial_result_representation (
144+ as_string : Option < bool > ,
145+ ) -> Option < GeospatialResultRepresentation > {
146+ as_string. map ( |as_string| {
147+ if as_string {
148+ GeospatialResultRepresentation :: String
149+ } else {
150+ GeospatialResultRepresentation :: Binary
151+ }
152+ } )
153+ }
154+
143155#[ allow( clippy:: too_many_arguments) ]
144156fn build_http_config (
145157 request_timeout_secs : Option < f64 > ,
@@ -325,6 +337,11 @@ impl Session {
325337 /// presets, etc. The kernel does not validate keys; the server
326338 /// rejects unknown ones with a `KernelError(code='SqlError')`
327339 /// when it picks them up.
340+ ///
341+ /// `geospatial_as_string` selects the physical Arrow representation of
342+ /// `GEOMETRY` / `GEOGRAPHY` results. `True` requests EWKT in Arrow UTF-8
343+ /// values; `False` requests Arrow `struct<srid: int32, wkb: binary>`
344+ /// values. `None` leaves the server default in control.
328345 #[ new]
329346 #[ pyo3( signature = (
330347 host,
@@ -364,6 +381,7 @@ impl Session {
364381 catalog=None ,
365382 schema=None ,
366383 session_conf=None ,
384+ geospatial_as_string=None ,
367385 driver_name=None ,
368386 driver_version=None ,
369387 runtime_name=None ,
@@ -429,6 +447,7 @@ impl Session {
429447 catalog : Option < String > ,
430448 schema : Option < String > ,
431449 session_conf : Option < HashMap < String , String > > ,
450+ geospatial_as_string : Option < bool > ,
432451 driver_name : Option < String > ,
433452 driver_version : Option < String > ,
434453 runtime_name : Option < String > ,
@@ -625,6 +644,9 @@ impl Session {
625644 if let Some ( conf) = session_conf {
626645 builder = builder. session_conf( conf) ;
627646 }
647+ if let Some ( representation) = geospatial_result_representation( geospatial_as_string) {
648+ builder = builder. geospatial_result_representation( representation) ;
649+ }
628650 // Merge result-config knobs into one `ResultConfig` so two
629651 // toggles don't clobber each other when both are set.
630652 if complex_types_as_json || intervals_as_string {
@@ -736,6 +758,19 @@ mod send_sync_tests {
736758 assert_send_sync :: < SessionInner > ( ) ;
737759 }
738760
761+ #[ test]
762+ fn geospatial_as_string_maps_to_kernel_representation ( ) {
763+ assert_eq ! ( geospatial_result_representation( None ) , None ) ;
764+ assert_eq ! (
765+ geospatial_result_representation( Some ( true ) ) ,
766+ Some ( GeospatialResultRepresentation :: String )
767+ ) ;
768+ assert_eq ! (
769+ geospatial_result_representation( Some ( false ) ) ,
770+ Some ( GeospatialResultRepresentation :: Binary )
771+ ) ;
772+ }
773+
739774 #[ test]
740775 fn telemetry_kwargs_map_to_kernel_config ( ) {
741776 let telemetry = build_telemetry_config ( TelemetryKwargs {
@@ -819,9 +854,11 @@ mod send_sync_tests {
819854 assert ! ( build_http_config( None , None , None , None , None , None , None )
820855 . unwrap( )
821856 . is_none( ) ) ;
822- assert ! ( build_http_config( Some ( 0.0 ) , None , None , None , None , None , None )
823- . unwrap( )
824- . is_none( ) ) ;
857+ assert ! (
858+ build_http_config( Some ( 0.0 ) , None , None , None , None , None , None )
859+ . unwrap( )
860+ . is_none( )
861+ ) ;
825862
826863 let http = build_http_config ( Some ( 0.5 ) , None , None , None , None , None , None )
827864 . unwrap ( )
@@ -832,8 +869,7 @@ mod send_sync_tests {
832869
833870 let one_ns = std:: time:: Duration :: from_nanos ( 1 ) . as_secs_f64 ( ) ;
834871 assert ! (
835- build_http_config( Some ( one_ns / 1_000.0 ) , None , None , None , None , None , None )
836- . is_err( )
872+ build_http_config( Some ( one_ns / 1_000.0 ) , None , None , None , None , None , None ) . is_err( )
837873 ) ;
838874 let http = build_http_config ( Some ( one_ns) , None , None , None , None , None , None )
839875 . unwrap ( )
0 commit comments