@@ -119,6 +119,7 @@ def test_none_query_param(trino_connection):
119
119
rows = cur .fetchall ()
120
120
121
121
assert rows [0 ][0 ] is None
122
+ assert_cursor_description (cur , trino_type = "unknown" )
122
123
123
124
124
125
def test_string_query_param (trino_connection ):
@@ -128,6 +129,7 @@ def test_string_query_param(trino_connection):
128
129
rows = cur .fetchall ()
129
130
130
131
assert rows [0 ][0 ] == "six'"
132
+ assert_cursor_description (cur , trino_type = "varchar(4)" , size = 4 )
131
133
132
134
133
135
def test_execute_many (trino_connection ):
@@ -241,10 +243,11 @@ def test_legacy_primitive_types_with_connection_and_cursor(
241
243
def test_decimal_query_param (trino_connection ):
242
244
cur = trino_connection .cursor ()
243
245
244
- cur .execute ("SELECT ?" , params = (Decimal ('0 .142857' ),))
246
+ cur .execute ("SELECT ?" , params = (Decimal ('1112 .142857' ),))
245
247
rows = cur .fetchall ()
246
248
247
- assert rows [0 ][0 ] == Decimal ('0.142857' )
249
+ assert rows [0 ][0 ] == Decimal ('1112.142857' )
250
+ assert_cursor_description (cur , trino_type = "decimal(10, 6)" , precision = 10 , scale = 6 )
248
251
249
252
250
253
def test_null_decimal (trino_connection ):
@@ -254,6 +257,7 @@ def test_null_decimal(trino_connection):
254
257
rows = cur .fetchall ()
255
258
256
259
assert rows [0 ][0 ] is None
260
+ assert_cursor_description (cur , trino_type = "decimal(38, 0)" , precision = 38 , scale = 0 )
257
261
258
262
259
263
def test_biggest_decimal (trino_connection ):
@@ -264,6 +268,7 @@ def test_biggest_decimal(trino_connection):
264
268
rows = cur .fetchall ()
265
269
266
270
assert rows [0 ][0 ] == params
271
+ assert_cursor_description (cur , trino_type = "decimal(38, 0)" , precision = 38 , scale = 0 )
267
272
268
273
269
274
def test_smallest_decimal (trino_connection ):
@@ -274,6 +279,7 @@ def test_smallest_decimal(trino_connection):
274
279
rows = cur .fetchall ()
275
280
276
281
assert rows [0 ][0 ] == params
282
+ assert_cursor_description (cur , trino_type = "decimal(38, 0)" , precision = 38 , scale = 0 )
277
283
278
284
279
285
def test_highest_precision_decimal (trino_connection ):
@@ -284,6 +290,7 @@ def test_highest_precision_decimal(trino_connection):
284
290
rows = cur .fetchall ()
285
291
286
292
assert rows [0 ][0 ] == params
293
+ assert_cursor_description (cur , trino_type = "decimal(38, 38)" , precision = 38 , scale = 38 )
287
294
288
295
289
296
def test_datetime_query_param (trino_connection ):
@@ -295,7 +302,7 @@ def test_datetime_query_param(trino_connection):
295
302
rows = cur .fetchall ()
296
303
297
304
assert rows [0 ][0 ] == params
298
- assert cur . description [ 0 ][ 1 ] == "timestamp(6)"
305
+ assert_cursor_description ( cur , trino_type = "timestamp(6)" , precision = 6 )
299
306
300
307
301
308
def test_datetime_with_utc_time_zone_query_param (trino_connection ):
@@ -307,7 +314,7 @@ def test_datetime_with_utc_time_zone_query_param(trino_connection):
307
314
rows = cur .fetchall ()
308
315
309
316
assert rows [0 ][0 ] == params
310
- assert cur . description [ 0 ][ 1 ] == "timestamp(6) with time zone"
317
+ assert_cursor_description ( cur , trino_type = "timestamp(6) with time zone" , precision = 6 )
311
318
312
319
313
320
def test_datetime_with_numeric_offset_time_zone_query_param (trino_connection ):
@@ -321,7 +328,7 @@ def test_datetime_with_numeric_offset_time_zone_query_param(trino_connection):
321
328
rows = cur .fetchall ()
322
329
323
330
assert rows [0 ][0 ] == params
324
- assert cur . description [ 0 ][ 1 ] == "timestamp(6) with time zone"
331
+ assert_cursor_description ( cur , trino_type = "timestamp(6) with time zone" , precision = 6 )
325
332
326
333
327
334
def test_datetime_with_named_time_zone_query_param (trino_connection ):
@@ -333,7 +340,7 @@ def test_datetime_with_named_time_zone_query_param(trino_connection):
333
340
rows = cur .fetchall ()
334
341
335
342
assert rows [0 ][0 ] == params
336
- assert cur . description [ 0 ][ 1 ] == "timestamp(6) with time zone"
343
+ assert_cursor_description ( cur , trino_type = "timestamp(6) with time zone" , precision = 6 )
337
344
338
345
339
346
def test_datetime_with_trailing_zeros (trino_connection ):
@@ -343,6 +350,7 @@ def test_datetime_with_trailing_zeros(trino_connection):
343
350
rows = cur .fetchall ()
344
351
345
352
assert rows [0 ][0 ] == datetime .strptime ("2001-08-22 03:04:05.321000" , "%Y-%m-%d %H:%M:%S.%f" )
353
+ assert_cursor_description (cur , trino_type = "timestamp(6)" , precision = 6 )
346
354
347
355
348
356
def test_null_datetime_with_time_zone (trino_connection ):
@@ -352,6 +360,7 @@ def test_null_datetime_with_time_zone(trino_connection):
352
360
rows = cur .fetchall ()
353
361
354
362
assert rows [0 ][0 ] is None
363
+ assert_cursor_description (cur , trino_type = "timestamp(3) with time zone" , precision = 3 )
355
364
356
365
357
366
def test_datetime_with_time_zone_numeric_offset (trino_connection ):
@@ -361,6 +370,7 @@ def test_datetime_with_time_zone_numeric_offset(trino_connection):
361
370
rows = cur .fetchall ()
362
371
363
372
assert rows [0 ][0 ] == datetime .strptime ("2001-08-22 03:04:05.321 -08:00" , "%Y-%m-%d %H:%M:%S.%f %z" )
373
+ assert_cursor_description (cur , trino_type = "timestamp(3) with time zone" , precision = 3 )
364
374
365
375
366
376
def test_datetimes_with_time_zone_in_dst_gap_query_param (trino_connection ):
@@ -404,6 +414,7 @@ def test_date_query_param(trino_connection):
404
414
rows = cur .fetchall ()
405
415
406
416
assert rows [0 ][0 ] == params
417
+ assert_cursor_description (cur , trino_type = "date" )
407
418
408
419
409
420
def test_null_date (trino_connection ):
@@ -413,6 +424,7 @@ def test_null_date(trino_connection):
413
424
rows = cur .fetchall ()
414
425
415
426
assert rows [0 ][0 ] is None
427
+ assert_cursor_description (cur , trino_type = "date" )
416
428
417
429
418
430
def test_unsupported_python_dates (trino_connection ):
@@ -462,6 +474,16 @@ def test_supported_special_dates_query_param(trino_connection):
462
474
assert rows [0 ][0 ] == params
463
475
464
476
477
+ def test_char (trino_connection ):
478
+ cur = trino_connection .cursor ()
479
+
480
+ cur .execute ("SELECT CHAR 'trino'" )
481
+ rows = cur .fetchall ()
482
+
483
+ assert rows [0 ][0 ] == 'trino'
484
+ assert_cursor_description (cur , trino_type = "char(5)" , size = 5 )
485
+
486
+
465
487
def test_time_query_param (trino_connection ):
466
488
cur = trino_connection .cursor ()
467
489
@@ -471,7 +493,7 @@ def test_time_query_param(trino_connection):
471
493
rows = cur .fetchall ()
472
494
473
495
assert rows [0 ][0 ] == params
474
- assert cur . description [ 0 ][ 1 ] == "time(6)"
496
+ assert_cursor_description ( cur , trino_type = "time(6)" , precision = 6 )
475
497
476
498
477
499
def test_time_with_named_time_zone_query_param (trino_connection ):
@@ -501,7 +523,7 @@ def test_time(trino_connection):
501
523
rows = cur .fetchall ()
502
524
503
525
assert rows [0 ][0 ] == time (1 , 2 , 3 , 456000 )
504
- assert cur . description [ 0 ][ 1 ] == "time(3)"
526
+ assert_cursor_description ( cur , trino_type = "time(3)" , precision = 3 )
505
527
506
528
507
529
def test_null_time (trino_connection ):
@@ -511,6 +533,7 @@ def test_null_time(trino_connection):
511
533
rows = cur .fetchall ()
512
534
513
535
assert rows [0 ][0 ] is None
536
+ assert_cursor_description (cur , trino_type = "time(3)" , precision = 3 )
514
537
515
538
516
539
def test_time_with_time_zone_negative_offset (trino_connection ):
@@ -522,7 +545,7 @@ def test_time_with_time_zone_negative_offset(trino_connection):
522
545
tz = timezone (- timedelta (hours = 8 , minutes = 0 ))
523
546
524
547
assert rows [0 ][0 ] == time (1 , 2 , 3 , 456000 , tzinfo = tz )
525
- assert cur . description [ 0 ][ 1 ] == "time(3) with time zone"
548
+ assert_cursor_description ( cur , trino_type = "time(3) with time zone" , precision = 3 )
526
549
527
550
528
551
def test_time_with_time_zone_positive_offset (trino_connection ):
@@ -534,7 +557,7 @@ def test_time_with_time_zone_positive_offset(trino_connection):
534
557
tz = timezone (timedelta (hours = 8 , minutes = 0 ))
535
558
536
559
assert rows [0 ][0 ] == time (1 , 2 , 3 , 456000 , tzinfo = tz )
537
- assert cur . description [ 0 ][ 1 ] == "time(3) with time zone"
560
+ assert_cursor_description ( cur , trino_type = "time(3) with time zone" , precision = 3 )
538
561
539
562
540
563
def test_null_date_with_time_zone (trino_connection ):
@@ -544,6 +567,7 @@ def test_null_date_with_time_zone(trino_connection):
544
567
rows = cur .fetchall ()
545
568
546
569
assert rows [0 ][0 ] is None
570
+ assert_cursor_description (cur , trino_type = "time(3) with time zone" , precision = 3 )
547
571
548
572
549
573
@pytest .mark .parametrize (
@@ -717,7 +741,7 @@ def test_float_query_param(trino_connection):
717
741
cur .execute ("SELECT ?" , params = (1.1 ,))
718
742
rows = cur .fetchall ()
719
743
720
- assert cur . description [ 0 ][ 1 ] == "double"
744
+ assert_cursor_description ( cur , trino_type = "double" )
721
745
assert rows [0 ][0 ] == 1.1
722
746
723
747
@@ -726,7 +750,7 @@ def test_float_nan_query_param(trino_connection):
726
750
cur .execute ("SELECT ?" , params = (float ("nan" ),))
727
751
rows = cur .fetchall ()
728
752
729
- assert cur . description [ 0 ][ 1 ] == "double"
753
+ assert_cursor_description ( cur , trino_type = "double" )
730
754
assert isinstance (rows [0 ][0 ], float )
731
755
assert math .isnan (rows [0 ][0 ])
732
756
@@ -736,6 +760,7 @@ def test_float_inf_query_param(trino_connection):
736
760
cur .execute ("SELECT ?" , params = (float ("inf" ),))
737
761
rows = cur .fetchall ()
738
762
763
+ assert_cursor_description (cur , trino_type = "double" )
739
764
assert rows [0 ][0 ] == float ("inf" )
740
765
741
766
cur .execute ("SELECT ?" , params = (float ("-inf" ),))
@@ -750,13 +775,13 @@ def test_int_query_param(trino_connection):
750
775
rows = cur .fetchall ()
751
776
752
777
assert rows [0 ][0 ] == 3
753
- assert cur . description [ 0 ][ 1 ] == "integer"
778
+ assert_cursor_description ( cur , trino_type = "integer" )
754
779
755
780
cur .execute ("SELECT ?" , params = (9223372036854775807 ,))
756
781
rows = cur .fetchall ()
757
782
758
783
assert rows [0 ][0 ] == 9223372036854775807
759
- assert cur . description [ 0 ][ 1 ] == "bigint"
784
+ assert_cursor_description ( cur , trino_type = "bigint" )
760
785
761
786
762
787
@pytest .mark .parametrize ('params' , [
@@ -1239,3 +1264,12 @@ def test_describe_table_query(run_trino):
1239
1264
aliased = False ,
1240
1265
)
1241
1266
]
1267
+
1268
+
1269
+ def assert_cursor_description (cur , trino_type , size = None , precision = None , scale = None ):
1270
+ assert cur .description [0 ][1 ] == trino_type
1271
+ assert cur .description [0 ][2 ] is None
1272
+ assert cur .description [0 ][3 ] is size
1273
+ assert cur .description [0 ][4 ] is precision
1274
+ assert cur .description [0 ][5 ] is scale
1275
+ assert cur .description [0 ][6 ] is None
0 commit comments