1212import os
1313import random
1414import re
15+ from contextlib import contextmanager
1516from datetime import date , datetime , time , timedelta , timezone
1617
1718import numpy
198199]
199200
200201
202+ @contextmanager
203+ def structured_type_wrapped_conn (conn_cnx ):
204+ parameters = {}
205+ if STRUCTURED_TYPES_SUPPORTED :
206+ parameters = {
207+ "python_connector_query_result_format" : "arrow" ,
208+ "ENABLE_STRUCTURED_TYPES_IN_CLIENT_RESPONSE" : True ,
209+ "ENABLE_STRUCTURED_TYPES_NATIVE_ARROW_FORMAT" : True ,
210+ "FORCE_ENABLE_STRUCTURED_TYPES_NATIVE_ARROW_FORMAT" : True ,
211+ "IGNORE_CLIENT_VESRION_IN_STRUCTURED_TYPES_RESPONSE" : True ,
212+ }
213+
214+ with conn_cnx (session_parameters = parameters ) as conn :
215+ yield conn
216+
217+
201218def serialize (value ):
202219 if isinstance (value , bytearray ):
203220 return value .hex ()
@@ -214,7 +231,7 @@ def verify_datatypes(
214231 conn_cnx , query , examples , schema , iceberg = False , pandas = False , deserialize = False
215232):
216233 table_name = f"arrow_datatype_test_verifaction_table_{ random_string (5 )} "
217- with conn_cnx ( ) as conn :
234+ with structured_type_wrapped_conn ( conn_cnx ) as conn :
218235 try :
219236 conn .cursor ().execute ("alter session set use_cached_result=false" )
220237 iceberg_table , iceberg_config = (
@@ -271,7 +288,7 @@ def pandas_verify(cur, data, deserialize):
271288@pytest .mark .parametrize ("datatype" , ICEBERG_UNSUPPORTED_TYPES )
272289def test_iceberg_negative (datatype , conn_cnx ):
273290 table_name = f"arrow_datatype_test_verifaction_table_{ random_string (5 )} "
274- with conn_cnx ( ) as conn :
291+ with structured_type_wrapped_conn ( conn_cnx ) as conn :
275292 try :
276293 with pytest .raises (ProgrammingError ):
277294 conn .cursor ().execute (
@@ -349,7 +366,7 @@ def test_structured_type_binds(conn_cnx):
349366 json_data = [json .dumps (d ) for d in data ]
350367 schema = "(num number, arr_b array(boolean), map map(varchar, int), obj object(city varchar, population float), arr_f array(float))"
351368 table_name = f"arrow_structured_type_binds_test_{ random_string (5 )} "
352- with conn_cnx ( ) as conn :
369+ with structured_type_wrapped_conn ( conn_cnx ) as conn :
353370 try :
354371 conn .cursor ().execute ("alter session set enable_bind_stage_v2=Enable" )
355372 conn .cursor ().execute (f"create table if not exists { table_name } { schema } " )
0 commit comments