Skip to content

Commit fe93827

Browse files
committed
Updated type integration tests
1 parent 111131c commit fe93827

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

tests/integration/test_types_integration.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,27 @@ def test_char(trino_connection):
116116
def test_varbinary(trino_connection):
117117
SqlTest(trino_connection) \
118118
.add_field(sql="X'65683F'", python='ZWg/') \
119-
.add_field(sql="X'0001020304050607080DF9367AA7000000'", python='AAECAwQFBgcIDfk2eqcAAAA=') \
119+
.add_field(sql="X''", python='') \
120120
.add_field(sql="CAST('' AS VARBINARY)", python='') \
121121
.add_field(sql="from_utf8(CAST('😂😂😂😂😂😂' AS VARBINARY))", python='😂😂😂😂😂😂') \
122122
.add_field(sql="CAST(null AS VARBINARY)", python=None) \
123123
.execute()
124124

125125

126+
def test_varbinary_failure(trino_connection):
127+
SqlExpectFailureTest(trino_connection) \
128+
.execute("CAST(42 AS VARBINARY)")
129+
130+
126131
def test_json(trino_connection):
127132
SqlTest(trino_connection) \
128133
.add_field(sql="CAST('{}' AS JSON)", python='"{}"') \
129134
.add_field(sql="CAST('null' AS JSON)", python='"null"') \
130135
.add_field(sql="CAST(null AS JSON)", python=None) \
136+
.add_field(sql="CAST('3.14' AS JSON)", python='"3.14"') \
137+
.add_field(sql="CAST('a string' AS JSON)", python='"a string"') \
138+
.add_field(sql="CAST('a \" complex '' string :' AS JSON)", python='"a \\" complex \' string :"') \
139+
.add_field(sql="CAST('[]' AS JSON)", python='"[]"') \
131140
.execute()
132141

133142

@@ -219,3 +228,20 @@ def _compare_results(self, actual, expected):
219228
continue
220229

221230
assert actual_val == expected_val
231+
232+
233+
class SqlExpectFailureTest:
234+
def __init__(self, trino_connection):
235+
self.cur = trino_connection.cursor(experimental_python_types=True)
236+
237+
def execute(self, field):
238+
sql = 'SELECT ' + field
239+
240+
try:
241+
self.cur.execute(sql)
242+
self.cur.fetchall()
243+
success = True
244+
except Exception:
245+
success = False
246+
247+
assert not success, "Test not expected to succeed"

trino/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ def decorated(*args, **kwargs):
773773
class NoOpRowMapper:
774774
"""
775775
No-op RowMapper which does not perform any transformation
776+
Used when experimental_python_types is False.
776777
"""
777778

778779
def map(self, rows):
@@ -836,7 +837,7 @@ def _double_map_func(self):
836837
else float(val)
837838

838839
def _timestamp_map_func(self, column, col_type):
839-
datetime_default_size = 20
840+
datetime_default_size = 20 # size of 'YYYY-MM-DD HH:MM:SS.' (the datetime string up to the milliseconds)
840841
pattern = "%Y-%m-%d %H:%M:%S"
841842
ms_size, ms_to_trim = self._get_number_of_digits(column)
842843
if ms_size > 0:

0 commit comments

Comments
 (0)