Skip to content

Commit 845481c

Browse files
authored
SNOW-940615: fix pyarrow import if pyarrow iterator is not compiled (#1769)
1 parent 5bdef59 commit 845481c

File tree

6 files changed

+69
-12
lines changed

6 files changed

+69
-12
lines changed

.github/workflows/build_test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,38 @@ jobs:
210210
PYTEST_ADDOPTS: --color=yes --tb=short
211211
shell: bash
212212

213+
test-noarrowextension:
214+
name: No Arrow Extension Test ${{ matrix.os.download_name }}-${{ matrix.python-version }}-${{ matrix.cloud-provider }}
215+
needs: lint
216+
runs-on: ${{ matrix.os.image_name }}
217+
strategy:
218+
fail-fast: false
219+
matrix:
220+
os:
221+
- image_name: ubuntu-latest
222+
download_name: linux
223+
python-version: [3.8]
224+
cloud-provider: [aws]
225+
steps:
226+
- uses: actions/checkout@v3
227+
- name: Set up Python
228+
uses: actions/setup-python@v4
229+
with:
230+
python-version: ${{ matrix.python-version }}
231+
- name: Display Python version
232+
run: python -c "import sys; print(sys.version)"
233+
- name: Upgrade setuptools, pip and wheel
234+
run: python -m pip install -U setuptools pip wheel
235+
- name: Install tox
236+
run: python -m pip install tox
237+
- name: Run tests
238+
run: python -m tox -e noarrowextension
239+
env:
240+
PYTHON_VERSION: ${{ matrix.python-version }}
241+
cloud_provider: ${{ matrix.cloud-provider }}
242+
PYTEST_ADDOPTS: --color=yes --tb=short
243+
shell: bash
244+
213245
test-fips:
214246
name: Test FIPS linux-3.8-${{ matrix.cloud-provider }}
215247
needs: build

DESCRIPTION.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ https://docs.snowflake.com/
77
Source code is also available at: https://github.com/snowflakedb/snowflake-connector-python
88

99
# Release Notes
10-
- v3.2.2(TBD)
11-
- Fixed issue with connection diagnostics failing to complete certificate checks.
12-
1310
- v3.3.1(Unreleased)
1411

1512
- Added for non-Windows platforms command suggestions (chown/chmod) for insufficient file permissions of config files.
13+
- Fixed issue with connection diagnostics failing to complete certificate checks.
14+
- Fixed issue that arrow iterator causes `ImportError` when the c extensions are not compiled.
1615

1716
- v3.3.0(October 10,2023)
1817

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
extensions = None
4343
cmd_class = {}
4444

45+
SNOWFLAKE_DISABLE_COMPILE_ARROW_EXTENSIONS = os.environ.get(
46+
"SNOWFLAKE_DISABLE_COMPILE_ARROW_EXTENSIONS", "false"
47+
).lower() in ("y", "yes", "t", "true", "1", "on")
48+
4549
try:
4650
import numpy
4751
import pyarrow
@@ -56,7 +60,7 @@
5660
)
5761
_ABLE_TO_COMPILE_EXTENSIONS = False
5862

59-
if _ABLE_TO_COMPILE_EXTENSIONS:
63+
if _ABLE_TO_COMPILE_EXTENSIONS and not SNOWFLAKE_DISABLE_COMPILE_ARROW_EXTENSIONS:
6064
pyarrow_version = tuple(int(x) for x in pyarrow.__version__.split("."))
6165
extensions = cythonize(
6266
[

src/snowflake/connector/result_batch.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414
from typing import TYPE_CHECKING, Any, Callable, Iterator, NamedTuple, Sequence
1515

1616
from .arrow_context import ArrowConverterContext
17-
from .arrow_iterator import PyArrowIterator
1817
from .compat import OK, UNAUTHORIZED, urlparse
1918
from .constants import FIELD_TYPES, IterUnit
2019
from .errorcode import ER_FAILED_TO_CONVERT_ROW_TO_PYTHON_TYPE, ER_NO_PYARROW
2120
from .errors import Error, InterfaceError, NotSupportedError, ProgrammingError
22-
from .nanoarrow_arrow_iterator import PyArrowRowIterator as NanoarrowRowIterator
23-
from .nanoarrow_arrow_iterator import PyArrowTableIterator as NanoarrowTableIterator
2421
from .network import (
2522
RetryRequest,
2623
get_http_retryable_error,
@@ -65,7 +62,9 @@ def _create_vendored_arrow_iterator(
6562
numpy: bool,
6663
number_to_decimal: bool,
6764
row_unit: IterUnit,
68-
) -> PyArrowIterator:
65+
):
66+
from .arrow_iterator import PyArrowIterator
67+
6968
logger.debug("Using vendored arrow as the arrow data converter")
7069
iter = PyArrowIterator(
7170
None,
@@ -87,10 +86,12 @@ def _create_nanoarrow_iterator(
8786
numpy: bool,
8887
number_to_decimal: bool,
8988
row_unit: IterUnit,
90-
) -> NanoarrowRowIterator | NanoarrowTableIterator:
89+
):
90+
from .nanoarrow_arrow_iterator import PyArrowRowIterator, PyArrowTableIterator
91+
9192
logger.debug("Using nanoarrow as the arrow data converter")
9293
return (
93-
NanoarrowRowIterator(
94+
PyArrowRowIterator(
9495
None,
9596
data,
9697
context,
@@ -99,7 +100,7 @@ def _create_nanoarrow_iterator(
99100
number_to_decimal,
100101
)
101102
if row_unit == IterUnit.ROW_UNIT
102-
else NanoarrowTableIterator(
103+
else PyArrowTableIterator(
103104
None,
104105
data,
105106
context,

test/unit/test_connection_diagnostic.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@
55

66
from __future__ import annotations
77

8+
import pytest
9+
10+
pytestmark = pytest.mark.skipolddriver # old test driver tests won't run this module
11+
12+
813
import snowflake.connector
9-
from snowflake.connector.connection_diagnostic import ConnectionDiagnostic, _decode_dict
14+
15+
try:
16+
from snowflake.connector.connection_diagnostic import (
17+
ConnectionDiagnostic,
18+
_decode_dict,
19+
)
20+
except ImportError:
21+
pass
1022

1123

1224
def test_https_host_report(caplog):

tox.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ passenv = {[testenv]passenv}
9696
commands =
9797
{env:SNOWFLAKE_PYTEST_CMD} -m "not skipolddriver" -vvv {posargs:} test
9898

99+
[testenv:noarrowextension]
100+
basepython = python3.8
101+
skip_install = True
102+
description = run import with no arrow extension under {basepython}
103+
setenv = SNOWFLAKE_DISABLE_COMPILE_ARROW_EXTENSIONS=1
104+
commands =
105+
pip install .
106+
python -c 'import snowflake.connector.result_batch'
107+
99108
[testenv:coverage]
100109
description = [run locally after tests]: combine coverage data and create report
101110
; generates a diff coverage against origin/master (can be changed by setting DIFF_AGAINST env var)

0 commit comments

Comments
 (0)