Skip to content

Commit cc65a03

Browse files
lpoulainhashhar
authored andcommitted
Support UUID type
Support UUID type
1 parent 55b1efe commit cc65a03

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

tests/integration/test_types_integration.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import math
22
import re
3+
import uuid
34
from datetime import date, datetime, time, timedelta, timezone, tzinfo
45
from decimal import Decimal
56

@@ -774,7 +775,8 @@ def test_ipaddress(trino_connection):
774775
def test_uuid(trino_connection):
775776
SqlTest(trino_connection) \
776777
.add_field(sql="CAST(null AS UUID)", python=None) \
777-
.add_field(sql="UUID '12151fd2-7586-11e9-8f9e-2a86e4085a59'", python='12151fd2-7586-11e9-8f9e-2a86e4085a59') \
778+
.add_field(sql="UUID '12151fd2-7586-11e9-8f9e-2a86e4085a59'",
779+
python=uuid.UUID('12151fd2-7586-11e9-8f9e-2a86e4085a59')) \
778780
.execute()
779781

780782

trino/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import re
4444
import threading
4545
import urllib.parse
46+
import uuid
4647
import warnings
4748
from dataclasses import dataclass
4849
from datetime import date, datetime, time, timedelta, timezone, tzinfo
@@ -1187,6 +1188,13 @@ def map(self, values: Any) -> Optional[Dict[Any, Optional[Any]]]:
11871188
}
11881189

11891190

1191+
class UuidValueMapper(ValueMapper[uuid.UUID]):
1192+
def map(self, value: Any) -> Optional[uuid.UUID]:
1193+
if value is None:
1194+
return None
1195+
return uuid.UUID(value)
1196+
1197+
11901198
class NoOpRowMapper:
11911199
"""
11921200
No-op RowMapper which does not perform any transformation
@@ -1247,6 +1255,8 @@ def _create_value_mapper(self, column) -> ValueMapper:
12471255
return DateValueMapper()
12481256
elif col_type == 'varbinary':
12491257
return BinaryValueMapper()
1258+
elif col_type == 'uuid':
1259+
return UuidValueMapper()
12501260
else:
12511261
return NoOpValueMapper()
12521262

0 commit comments

Comments
 (0)