Skip to content

Commit c01303c

Browse files
Sync 30072020 (#347)
Sync 30072020
1 parent b2a3a29 commit c01303c

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

cursor.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@
7070
LOG_MAX_QUERY_LENGTH = 80
7171

7272

73+
def exit_handler(*_):
74+
"""Handler for signal. When called, it will raise SystemExit with exit code FORCE_EXIT."""
75+
print("\nForce exit")
76+
logger.info("Force exit")
77+
sys.exit(1)
78+
79+
7380
class SnowflakeCursor(object):
7481
"""Implementation of Cursor object that is returned from Connection.cursor() method.
7582
@@ -334,9 +341,9 @@ def _execute_helper(
334341

335342
original_sigint = signal.getsignal(signal.SIGINT)
336343

337-
def abort_exit(*_):
344+
def interrupt_handler(*_):
338345
try:
339-
signal.signal(signal.SIGINT, signal.SIG_IGN)
346+
signal.signal(signal.SIGINT, exit_handler)
340347
except (ValueError, TypeError):
341348
# ignore failures
342349
pass
@@ -356,7 +363,8 @@ def abort_exit(*_):
356363
raise KeyboardInterrupt
357364

358365
try:
359-
signal.signal(signal.SIGINT, abort_exit)
366+
if not original_sigint == exit_handler:
367+
signal.signal(signal.SIGINT, interrupt_handler)
360368
except ValueError:
361369
logger.debug(
362370
'Failed to set SIGINT handler. '
@@ -665,9 +673,8 @@ def check_can_use_pandas(self):
665673
global pyarrow
666674

667675
if pyarrow is None:
668-
msg = (
669-
"pyarrow package is missing. Install using pip if the platform is supported."
670-
)
676+
msg = ("Optional dependency: 'pyarrow' is not installed, please see the following link for install "
677+
"instructions: https://docs.snowflake.com/en/user-guide/python-connector-pandas.html#installation")
671678
errno = ER_NO_PYARROW
672679

673680
Error.errorhandler_wrapper(

test/pandas/test_arrow_pandas.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
import pytest
88
import time
9+
10+
from pandas import DataFrame
11+
912
from snowflake.connector.options import pandas as pd, installed_pandas
1013
import random
1114
from datetime import datetime
@@ -674,3 +677,34 @@ def test_arrow_fetch_result_scan(conn_cnx):
674677
assert tuple(res) == ('1', '2', '3')
675678
result_scan_res = cur.execute("select * from table(result_scan('{}'));".format(cur.sfqid)).fetch_pandas_all()
676679
assert tuple(result_scan_res) == ('1', '2', '3')
680+
681+
682+
@pytest.mark.parametrize('query_format', ('JSON', 'ARROW'))
683+
@pytest.mark.parametrize('resultscan_format', ('JSON', 'ARROW'))
684+
def test_query_resultscan_combos(conn_cnx, query_format, resultscan_format):
685+
with conn_cnx() as cnx:
686+
sfqid = None
687+
results = None
688+
scanned_results = None
689+
with cnx.cursor() as query_cur:
690+
query_cur.execute("alter session set python_connector_query_result_format='{}'".format(query_format))
691+
query_cur.execute("select seq8(), randstr(1000,random()) from table(generator(rowcount=>100))")
692+
sfqid = query_cur.sfqid
693+
assert query_cur._query_result_format.upper() == query_format
694+
if query_format == 'JSON':
695+
results = query_cur.fetchall()
696+
else:
697+
results = query_cur.fetch_pandas_all()
698+
with cnx.cursor() as resultscan_cur:
699+
resultscan_cur.execute("alter session set python_connector_query_result_format='{}'".format(resultscan_format))
700+
resultscan_cur.execute("select * from table(result_scan('{}'))".format(sfqid))
701+
if resultscan_format == 'JSON':
702+
scanned_results = resultscan_cur.fetchall()
703+
else:
704+
scanned_results = resultscan_cur.fetch_pandas_all()
705+
assert resultscan_cur._query_result_format.upper() == resultscan_format
706+
if isinstance(results, DataFrame):
707+
results = [tuple(e) for e in results.values.tolist()]
708+
if isinstance(scanned_results, DataFrame):
709+
scanned_results = [tuple(e) for e in scanned_results.values.tolist()]
710+
assert results == scanned_results

0 commit comments

Comments
 (0)