|
13 | 13 | import pickle
|
14 | 14 | import time
|
15 | 15 | from datetime import date, datetime, timezone
|
16 |
| -from typing import TYPE_CHECKING, NamedTuple |
17 | 16 | from unittest import mock
|
18 | 17 |
|
19 | 18 | import pytest
|
20 | 19 | import pytz
|
21 | 20 |
|
22 | 21 | import snowflake.connector
|
| 22 | +import snowflake.connector.aio |
23 | 23 | from snowflake.connector import (
|
24 | 24 | InterfaceError,
|
25 | 25 | NotSupportedError,
|
|
30 | 30 | errors,
|
31 | 31 | )
|
32 | 32 | from snowflake.connector.aio import DictCursor, SnowflakeCursor
|
| 33 | +from snowflake.connector.aio._result_batch import ( |
| 34 | + ArrowResultBatch, |
| 35 | + JSONResultBatch, |
| 36 | + ResultBatch, |
| 37 | +) |
33 | 38 | from snowflake.connector.compat import IS_WINDOWS
|
34 |
| - |
35 |
| -try: |
36 |
| - from snowflake.connector.cursor import ResultMetadata |
37 |
| -except ImportError: |
38 |
| - |
39 |
| - class ResultMetadata(NamedTuple): |
40 |
| - name: str |
41 |
| - type_code: int |
42 |
| - display_size: int |
43 |
| - internal_size: int |
44 |
| - precision: int |
45 |
| - scale: int |
46 |
| - is_nullable: bool |
47 |
| - |
48 |
| - |
49 |
| -import snowflake.connector.aio |
| 39 | +from snowflake.connector.constants import ( |
| 40 | + FIELD_ID_TO_NAME, |
| 41 | + PARAMETER_MULTI_STATEMENT_COUNT, |
| 42 | + PARAMETER_PYTHON_CONNECTOR_QUERY_RESULT_FORMAT, |
| 43 | + QueryStatus, |
| 44 | +) |
| 45 | +from snowflake.connector.cursor import ResultMetadata |
50 | 46 | from snowflake.connector.description import CLIENT_VERSION
|
51 | 47 | from snowflake.connector.errorcode import (
|
52 | 48 | ER_FAILED_TO_REWRITE_MULTI_ROW_INSERT,
|
| 49 | + ER_NO_ARROW_RESULT, |
| 50 | + ER_NO_PYARROW, |
| 51 | + ER_NO_PYARROW_SNOWSQL, |
53 | 52 | ER_NOT_POSITIVE_SIZE,
|
54 | 53 | )
|
55 | 54 | from snowflake.connector.errors import Error
|
56 | 55 | from snowflake.connector.sqlstate import SQLSTATE_FEATURE_NOT_SUPPORTED
|
57 | 56 | from snowflake.connector.telemetry import TelemetryField
|
58 |
| - |
59 |
| -try: |
60 |
| - from snowflake.connector.util_text import random_string |
61 |
| -except ImportError: |
62 |
| - from ..randomize import random_string |
63 |
| - |
64 |
| -try: |
65 |
| - from snowflake.connector.aio._result_batch import ArrowResultBatch, JSONResultBatch |
66 |
| - from snowflake.connector.constants import ( |
67 |
| - FIELD_ID_TO_NAME, |
68 |
| - PARAMETER_MULTI_STATEMENT_COUNT, |
69 |
| - PARAMETER_PYTHON_CONNECTOR_QUERY_RESULT_FORMAT, |
70 |
| - ) |
71 |
| - from snowflake.connector.errorcode import ( |
72 |
| - ER_NO_ARROW_RESULT, |
73 |
| - ER_NO_PYARROW, |
74 |
| - ER_NO_PYARROW_SNOWSQL, |
75 |
| - ) |
76 |
| -except ImportError: |
77 |
| - PARAMETER_PYTHON_CONNECTOR_QUERY_RESULT_FORMAT = None |
78 |
| - ER_NO_ARROW_RESULT = None |
79 |
| - ER_NO_PYARROW = None |
80 |
| - ER_NO_PYARROW_SNOWSQL = None |
81 |
| - ArrowResultBatch = JSONResultBatch = None |
82 |
| - FIELD_ID_TO_NAME = {} |
83 |
| - |
84 |
| -if TYPE_CHECKING: # pragma: no cover |
85 |
| - from snowflake.connector.result_batch import ResultBatch |
86 |
| - |
87 |
| -try: # pragma: no cover |
88 |
| - from snowflake.connector.constants import QueryStatus |
89 |
| -except ImportError: |
90 |
| - QueryStatus = None |
| 57 | +from snowflake.connector.util_text import random_string |
91 | 58 |
|
92 | 59 |
|
93 | 60 | @pytest.fixture
|
@@ -1824,3 +1791,24 @@ async def test_decoding_utf8_for_json_result(conn_cnx):
|
1824 | 1791 | )
|
1825 | 1792 | with pytest.raises(Error):
|
1826 | 1793 | await result_batch._load("À".encode("latin1"), "latin1")
|
| 1794 | + |
| 1795 | + |
| 1796 | +async def test_fetch_download_timeout_setting(conn_cnx): |
| 1797 | + with mock.patch.multiple( |
| 1798 | + "snowflake.connector.aio._result_batch", |
| 1799 | + DOWNLOAD_TIMEOUT=0.001, |
| 1800 | + MAX_DOWNLOAD_RETRY=2, |
| 1801 | + ): |
| 1802 | + sql = "SELECT seq4(), uniform(1, 10, RANDOM(12)) FROM TABLE(GENERATOR(ROWCOUNT => 100000)) v" |
| 1803 | + async with conn_cnx() as con, con.cursor() as cur: |
| 1804 | + with pytest.raises(asyncio.TimeoutError): |
| 1805 | + await (await cur.execute(sql)).fetchall() |
| 1806 | + |
| 1807 | + with mock.patch.multiple( |
| 1808 | + "snowflake.connector.aio._result_batch", |
| 1809 | + DOWNLOAD_TIMEOUT=10, |
| 1810 | + MAX_DOWNLOAD_RETRY=1, |
| 1811 | + ): |
| 1812 | + sql = "SELECT seq4(), uniform(1, 10, RANDOM(12)) FROM TABLE(GENERATOR(ROWCOUNT => 100000)) v" |
| 1813 | + async with conn_cnx() as con, con.cursor() as cur: |
| 1814 | + assert len(await (await cur.execute(sql)).fetchall()) == 100000 |
0 commit comments