Skip to content

Commit 240def5

Browse files
Add arrow test
1 parent 75bbc8a commit 240def5

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/integ/test_arrow_result.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,49 @@ def iterate_over_test_chunk(
13451345
assert str(arrow_res[0]) == expected[i]
13461346

13471347

1348+
@pytest.mark.parametrize(
1349+
"timestamp_type", ["timestamp_ntz", "timestamp_ltz", "timestamp_tz"]
1350+
)
1351+
def test_convert_timestamp_overflow(conn_cnx, timestamp_type):
1352+
"""Test whether large timestamps are correctly falling back to microsecond precision."""
1353+
1354+
def query(timestamp):
1355+
if timestamp_type == "timestamp_tz":
1356+
return f"SELECT CONVERT_TIMEZONE ('UTC', '{timestamp}') AS result"
1357+
return f"SELECT '{timestamp}'::{timestamp_type} AS result"
1358+
1359+
with conn_cnx() as cnx:
1360+
cur = cnx.cursor()
1361+
1362+
# Check that "large" dates are correctly falling back to microsecond precision
1363+
cur.execute(query("2999-12-31 00:00:00.001234"))
1364+
result = cur.fetchall()
1365+
assert str(result[0][0]).startswith("2999-12-31 00:00:00.001234")
1366+
result_arrow = cur.fetch_arrow_all()
1367+
assert str(result_arrow.to_pydict()["RESULT"]).startswith(
1368+
"[datetime.datetime(2999, 12, 31, 0, 0, 0, 1234"
1369+
)
1370+
1371+
# Check that nanosecond precision is used for dates within the nanosecond range
1372+
cur.execute(query("2000-12-31 00:00:00.001234567"))
1373+
result_arrow = cur.fetch_arrow_all()
1374+
assert str(result_arrow.to_pydict()["RESULT"]).startswith(
1375+
"[Timestamp('2000-12-31 00:00:00.001234567"
1376+
)
1377+
1378+
# Check that nanosecond precision used outside of nanosecond range throws an error
1379+
cur.execute(query("2999-12-31 00:00:00.0012345678"))
1380+
with pytest.raises(
1381+
OverflowError,
1382+
match=(
1383+
"If you use a timestamp with the nanosecond part over 6-digits in the Snowflake database, "
1384+
"the timestamp must be between '1677-09-21 00:12:43.145224192' and "
1385+
"'2262-04-11 23:47:16.854775807' to not overflow."
1386+
),
1387+
):
1388+
result_arrow = cur.fetch_arrow_all()
1389+
1390+
13481391
@pytest.mark.parametrize("debug_arrow_chunk", [True, False])
13491392
def test_arrow_bad_data(conn_cnx, caplog, debug_arrow_chunk):
13501393
with caplog.at_level(logging.DEBUG):

0 commit comments

Comments
 (0)