Skip to content

Commit

Permalink
Support UUID type
Browse files Browse the repository at this point in the history
Support UUID type
  • Loading branch information
lpoulain committed Apr 6, 2023
1 parent e10bc53 commit ac33c54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tests/integration/test_types_integration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math
import re
import uuid
from datetime import date, datetime, time, timedelta, timezone, tzinfo
from decimal import Decimal

Expand Down Expand Up @@ -774,7 +775,8 @@ def test_ipaddress(trino_connection):
def test_uuid(trino_connection):
SqlTest(trino_connection) \
.add_field(sql="CAST(null AS UUID)", python=None) \
.add_field(sql="UUID '12151fd2-7586-11e9-8f9e-2a86e4085a59'", python='12151fd2-7586-11e9-8f9e-2a86e4085a59') \
.add_field(sql="UUID '12151fd2-7586-11e9-8f9e-2a86e4085a59'",
python=uuid.UUID('12151fd2-7586-11e9-8f9e-2a86e4085a59')) \
.execute()


Expand Down
10 changes: 10 additions & 0 deletions trino/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import re
import threading
import urllib.parse
import uuid
import warnings
from dataclasses import dataclass
from datetime import date, datetime, time, timedelta, timezone, tzinfo
Expand Down Expand Up @@ -1185,6 +1186,13 @@ def map(self, values: Any) -> Optional[Dict[Any, Optional[Any]]]:
}


class UuidValueMapper(ValueMapper[uuid.UUID]):
def map(self, value: Any) -> Optional[uuid.UUID]:
if value is None:
return None
return uuid.UUID(value)


class NoOpRowMapper:
"""
No-op RowMapper which does not perform any transformation
Expand Down Expand Up @@ -1245,6 +1253,8 @@ def _create_value_mapper(self, column) -> ValueMapper:
return DateValueMapper()
elif col_type == 'varbinary':
return BinaryValueMapper()
elif col_type == 'uuid':
return UuidValueMapper()
else:
return NoOpValueMapper()

Expand Down

0 comments on commit ac33c54

Please sign in to comment.