@@ -628,6 +628,67 @@ async def test_8123(self):
628628 fetched_data = self .__get_data_from_df (fetched_df )
629629 self .assertEqual (fetched_data , data )
630630
631+ async def test_8124 (self ):
632+ "8124 - verify dtype for all Arrow types"
633+ query = """
634+ select
635+ cast(1 as number(10)) as col_int64,
636+ cast(1.23 as binary_double) as col_double,
637+ cast(7.14 as binary_float) as col_float,
638+ cast('abcd' as varchar2(10)) as col_string,
639+ cast('efgh' as nvarchar2(6)) as col_nstring,
640+ cast('ijkl' as char(4)) as col_char,
641+ cast('mnop' as nchar(4)) as col_nchar,
642+ cast(systimestamp as timestamp(0)) as col_ts_sec,
643+ cast(systimestamp as timestamp(3)) as col_ts_ms,
644+ cast(systimestamp as timestamp(6)) as col_ts_us,
645+ cast(systimestamp as timestamp(9)) as col_ts_ns,
646+ to_clob('abc') as col_large_string,
647+ to_nclob('def') as col_large_nstring,
648+ utl_raw.cast_to_raw('abc2') as col_binary,
649+ to_blob(utl_raw.cast_to_raw('abc3')) as col_large_binary
650+ from dual
651+ """
652+ decimal_query = (
653+ "select cast(123.45 as decimal(10, 2)) as col_decimal128"
654+ )
655+
656+ # determine dtype kind enumeration
657+ ora_df = await self .conn .fetch_df_all ("select user from dual" )
658+ col = ora_df .get_column (0 )
659+ dtype_kind = type (col .dtype [0 ])
660+
661+ expected_dtypes = {
662+ "COL_INT64" : (dtype_kind .INT , 64 , "l" , "=" ),
663+ "COL_DOUBLE" : (dtype_kind .FLOAT , 64 , "g" , "=" ),
664+ "COL_FLOAT" : (dtype_kind .FLOAT , 64 , "g" , "=" ),
665+ "COL_STRING" : (dtype_kind .STRING , 8 , "u" , "=" ),
666+ "COL_NSTRING" : (dtype_kind .STRING , 8 , "u" , "=" ),
667+ "COL_CHAR" : (dtype_kind .STRING , 8 , "u" , "=" ),
668+ "COL_NCHAR" : (dtype_kind .STRING , 8 , "u" , "=" ),
669+ "COL_TS_SEC" : (dtype_kind .DATETIME , 64 , "tss:" , "=" ),
670+ "COL_TS_MS" : (dtype_kind .DATETIME , 64 , "tsm:" , "=" ),
671+ "COL_TS_US" : (dtype_kind .DATETIME , 64 , "tsu:" , "=" ),
672+ "COL_TS_NS" : (dtype_kind .DATETIME , 64 , "tsn:" , "=" ),
673+ "COL_LARGE_STRING" : (dtype_kind .STRING , 8 , "U" , "=" ),
674+ "COL_LARGE_NSTRING" : (dtype_kind .STRING , 8 , "U" , "=" ),
675+ "COL_BINARY" : (dtype_kind .STRING , 8 , "z" , "=" ),
676+ "COL_LARGE_BINARY" : (dtype_kind .STRING , 8 , "Z" , "=" ),
677+ "COL_DECIMAL128" : (dtype_kind .DECIMAL , 128 , "d:10.2" , "=" ),
678+ }
679+
680+ # check query without fetch_decimals enabled
681+ ora_df = await self .conn .fetch_df_all (query )
682+ for i , name in enumerate (ora_df .column_names ()):
683+ col = ora_df .get_column (i )
684+ self .assertEqual (col .dtype , expected_dtypes [name ])
685+
686+ # check query with fetch_decimals enabled
687+ with test_env .DefaultsContextManager ("fetch_decimals" , True ):
688+ ora_df = await self .conn .fetch_df_all (decimal_query )
689+ col = ora_df .get_column (0 )
690+ self .assertEqual (col .dtype , expected_dtypes ["COL_DECIMAL128" ])
691+
631692
632693if __name__ == "__main__" :
633694 test_env .run_test_cases ()
0 commit comments