Skip to content

Commit 09abe8e

Browse files
committed
SNOW-26262: bypassed numeric value conversions for SnowSQL to improve performance.
1 parent b243231 commit 09abe8e

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

connection.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ def errorhandler(self):
214214
"""
215215
return self._errorhandler
216216

217+
@property
218+
def converter_class(self):
219+
"""
220+
Converter Class
221+
"""
222+
return self._converter_class
223+
217224
@errorhandler.setter
218225
def errorhandler(self, value):
219226
if value is None:

converter.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
import pytz
1212

13-
from .compat import (IS_UNICODE, IS_BYTES, IS_BINARY, TO_UNICODE, IS_NUMERIC)
14-
from .constants import (UTF8)
13+
from .compat import (IS_BINARY, TO_UNICODE, IS_NUMERIC)
1514
from .errorcode import (ER_NOT_SUPPORT_DATA_TYPE)
1615
from .errors import (ProgrammingError)
1716
from .sfbinaryformat import (binary_to_python,
@@ -335,11 +334,7 @@ def _TIME_to_python(self, value, col_desc, *_):
335334
_TIME_numpy_to_python = _TIME_to_python
336335

337336
def _VARIANT_to_python(self, value, *_):
338-
if IS_UNICODE(value):
339-
return value
340-
elif IS_BYTES(value):
341-
return value.decode(UTF8)
342-
return TO_UNICODE(value)
337+
return value
343338

344339
_VARIANT_numpy_to_python = _VARIANT_to_python
345340

@@ -359,7 +354,7 @@ def _BOOLEAN_to_python(self, value, *_):
359354
_BOOLEAN_numpy_to_python = _BOOLEAN_to_python
360355

361356
#
362-
# TO Snowflake
357+
# From Python to Snowflake
363358
#
364359
def to_snowflake(self, value):
365360
type_name = value.__class__.__name__.lower()

converter_snowsql.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ def to_python_method(self, type_name, row_type):
6666
# no type is defined, pass through it
6767
return self._TEXT_to_python, None
6868

69+
def _BOOLEAN_to_python(self, value, *_):
70+
"""
71+
No conversion for SnowSQL
72+
"""
73+
return u"True" if value in (u'1', u"True") else u"False"
74+
6975
def _FIXED_to_python(self, value, *_):
7076
"""
7177
No conversion for SnowSQL

file_transfer_agent.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
#
66
import glob
77
import mimetypes
8+
import os
9+
import shutil
810
import sys
11+
import tempfile
912
import threading
1013
from logging import getLogger
1114
from multiprocessing.pool import ThreadPool
1215
from time import (time, sleep)
1316

1417
import botocore.exceptions
15-
import os
16-
import shutil
17-
import tempfile
18+
1819
from .compat import (GET_CWD, TO_UNICODE)
1920
from .constants import (SHA256_DIGEST)
21+
from .converter_snowsql import SnowflakeConverterSnowSQL
2022
from .errorcode import (ER_INVALID_STAGE_FS, ER_INVALID_STAGE_LOCATION,
2123
ER_LOCAL_PATH_NOT_DIRECTORY,
2224
ER_FILE_NOT_EXISTS,
@@ -510,6 +512,7 @@ def renew_expired_aws_token(self):
510512
use_accelerate_endpoint=self._use_accelerate_endpoint)
511513

512514
def result(self):
515+
converter_class = self._cursor._connection.converter_class
513516
rowset = []
514517
if self._command_type == CMD_TYPE_UPLOAD:
515518
if hasattr(self, u'_results'):
@@ -531,11 +534,19 @@ def result(self):
531534
else:
532535
error_details = u''
533536

537+
src_file_size = meta[u'src_file_size'] \
538+
if converter_class != SnowflakeConverterSnowSQL \
539+
else TO_UNICODE(meta[u'src_file_size'])
540+
541+
dst_file_size = meta[u'dst_file_size'] \
542+
if converter_class != SnowflakeConverterSnowSQL \
543+
else TO_UNICODE(meta[u'dst_file_size'])
544+
534545
rowset.append([
535546
meta[u'name'],
536547
meta[u'dst_file_name'],
537-
meta[u'src_file_size'],
538-
meta[u'dst_file_size'],
548+
src_file_size,
549+
dst_file_size,
539550
src_compression_type,
540551
dst_compression_type,
541552
meta[u'result_status'],
@@ -557,13 +568,17 @@ def result(self):
557568
else: # DOWNLOAD
558569
if hasattr(self, u'_results'):
559570
for meta in self._results:
571+
dst_file_size = meta[u'dst_file_size'] \
572+
if converter_class != SnowflakeConverterSnowSQL \
573+
else TO_UNICODE(meta[u'dst_file_size'])
574+
560575
if u'error_details' in meta:
561576
error_details = meta[u'error_details']
562577
else:
563578
error_details = u''
564579
rowset.append([
565580
meta[u'dst_file_name'],
566-
meta[u'dst_file_size'],
581+
dst_file_size,
567582
meta[u'result_status'],
568583
error_details
569584
])

0 commit comments

Comments
 (0)