Skip to content

Commit 982ead3

Browse files
committed
SNOW-27328: region parameter doesn't work
1 parent 0e9509d commit 982ead3

File tree

5 files changed

+54
-12
lines changed

5 files changed

+54
-12
lines changed

connection.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
DatabaseError)
2424
from .sqlstate import (SQLSTATE_CONNECTION_NOT_EXISTS,
2525
SQLSTATE_FEATURE_NOT_SUPPORTED)
26-
from .util_text import split_statements
26+
from .util_text import split_statements, construct_hostname
2727

2828
try:
2929
import snowflake.internal.constants
@@ -478,13 +478,9 @@ def __config(self, **kwargs):
478478

479479
if u'account' in kwargs and kwargs[u'account'] not in TEST_ACCOUNTS:
480480
if u'host' not in kwargs:
481-
if kwargs.get(u'region'):
482-
host = u'{0}.{1}.snowflakecomputing.com'.format(
483-
self._account[0:self._account.find(u'.')],
484-
kwargs.get(u'region'))
485-
else:
486-
host = u'{0}.snowflakecomputing.com'.format(self._account)
487-
setattr(self, u'_host', host)
481+
setattr(self, u'_host',
482+
construct_hostname(
483+
kwargs.get(u'region'), self._account))
488484
if u'port' not in kwargs:
489485
setattr(self, u'_port', u'443')
490486
if u'protocol' not in kwargs:

converter_snowsql.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _DATE_to_python(self, value, ctx):
108108
try:
109109
t = ZERO_EPOCH + timedelta(seconds=int(value) * (24 * 60 * 60))
110110
if fmt:
111-
return fmt.format(t)
111+
return fmt.format(SnowflakeDateTime(t, nanosecond=0))
112112
return TO_UNICODE(date(t.year, t.month, t.day))
113113
except OverflowError:
114114
self.logger.debug(
@@ -117,9 +117,7 @@ def _DATE_to_python(self, value, ctx):
117117
value)
118118
t = time.gmtime(value)
119119
if fmt:
120-
return fmt.format(
121-
SnowflakeDateTime(t, nanosecond=0)
122-
)
120+
return fmt.format(SnowflakeDateTime(t, nanosecond=0))
123121
return u'{year:d}-{month:02d}-{day:02d}'.format(
124122
year=t.tm_year, month=t.tm_mon, day=t.tm_mday)
125123

test/test_unit_construct_hostname.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2012-2017 Snowflake Computing Inc. All right reserved.
5+
#
6+
7+
from snowflake.connector.util_text import construct_hostname
8+
9+
10+
def test_construct_hostname_basic():
11+
assert construct_hostname('eu-central-1', 'account1') == \
12+
'account1.eu-central-1.snowflakecomputing.com'
13+
14+
assert construct_hostname('', 'account1') == \
15+
'account1.snowflakecomputing.com'
16+
17+
assert construct_hostname(None, 'account1') == \
18+
'account1.snowflakecomputing.com'
19+
20+
assert construct_hostname('as-east-3', 'account1') == \
21+
'account1.as-east-3.snowflakecomputing.com'
22+
23+
assert construct_hostname('as-east-3', 'account1.eu-central-1') == \
24+
'account1.as-east-3.snowflakecomputing.com'
25+
26+
assert construct_hostname('', 'account1.eu-central-1') == \
27+
'account1.eu-central-1.snowflakecomputing.com'
28+
29+
assert construct_hostname(None, 'account1.eu-central-1') == \
30+
'account1.eu-central-1.snowflakecomputing.com'

test/test_unit_split_statement.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2012-2017 Snowflake Computing Inc. All right reserved.
5+
#
16
from io import StringIO
27

38
import pytest

util_text.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,16 @@ def split_rows_from_stream(stream):
180180
row.append(value)
181181
elif event == 'start_array':
182182
in_row = True
183+
184+
185+
def construct_hostname(region, account):
186+
"""
187+
Constructs hostname from region and account
188+
"""
189+
if region:
190+
if account.find(u'.') > 0:
191+
account = account[0:account.find(u'.')]
192+
host = u'{0}.{1}.snowflakecomputing.com'.format(account, region)
193+
else:
194+
host = u'{0}.snowflakecomputing.com'.format(account)
195+
return host

0 commit comments

Comments
 (0)