Skip to content

Commit d788358

Browse files
Merge pull request #9 from WPSemantix/task/improve-queries-runtime-performance
Task/improve queries runtime performance
2 parents 34cd0df + 4756c99 commit d788358

File tree

5 files changed

+75
-16
lines changed

5 files changed

+75
-16
lines changed

pyproject.toml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ classifiers = [
4646
"Development Status :: 5 - Production/Stable",
4747
"Intended Audience :: Developers",
4848
"Topic :: Software Development :: Build Tools",
49-
"License :: OSI Approved :: MIT License",
50-
"License :: OSI Approved :: Apache Software License",
51-
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
52-
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
53-
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
5449
"Programming Language :: Python :: 3",
5550
"Programming Language :: Python :: 3.9",
5651
"Programming Language :: Python :: 3.10",
@@ -59,14 +54,15 @@ classifiers = [
5954
]
6055
requires-python = ">=3.9"
6156
dependencies = [
62-
"future==1.0.0",
63-
"python-dateutil==2.9.0",
57+
"future>=0.18.2",
58+
"python-dateutil>=2.8.2",
6459
"ldap3",
65-
"thrift_sasl==0.4.3",
60+
"thrift>=0.16.0",
61+
"thrift_sasl>=0.4.3",
6662
"pure-sasl>=0.6.2",
6763
"sqlalchemy>=1.4.36,<2.0.0",
68-
"requests_kerberos==0.15.0",
69-
"pyhive==0.7.0"
64+
"requests_kerberos>=0.12.0",
65+
"pyhive>=0.7.0"
7066
]
7167

7268
[project.urls]

pytimbr_sqla/__init__.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,63 @@
11
"""Timbr Python SQLAlchemy connector."""
22

3-
__version__ = "2.0.0"
3+
__version__ = "2.0.1"
4+
5+
try:
6+
from thrift.transport import THttpClient
7+
def timbr_flush(self):
8+
if self.__http_response is not None:
9+
self.__http_response.close()
10+
self.__http_response = None
11+
12+
if not self.isOpen():
13+
self.open()
14+
15+
# Pull data out of buffer
16+
data = self.__wbuf.getvalue()
17+
self.__wbuf = BytesIO()
18+
19+
# HTTP request
20+
if self.using_proxy() and self.scheme == "http":
21+
# need full URL of real host for HTTP proxy here (HTTPS uses CONNECT tunnel)
22+
self.__http.putrequest('POST', "http://%s:%s%s" %
23+
(self.realhost, self.realport, self.path))
24+
else:
25+
self.__http.putrequest('POST', self.path)
26+
27+
# Write headers
28+
self.__http.putheader('Content-Type', 'application/x-thrift')
29+
self.__http.putheader('Content-Length', str(len(data)))
30+
if self.using_proxy() and self.scheme == "http" and self.proxy_auth is not None:
31+
self.__http.putheader("Proxy-Authorization", self.proxy_auth)
32+
33+
if not self.__custom_headers or 'User-Agent' not in self.__custom_headers:
34+
user_agent = 'Python/THttpClient'
35+
script = os.path.basename(sys.argv[0])
36+
if script:
37+
user_agent = '%s (%s)' % (user_agent, urllib.parse.quote(script))
38+
self.__http.putheader('User-Agent', user_agent)
39+
40+
if self.__custom_headers:
41+
for key, val in six.iteritems(self.__custom_headers):
42+
self.__http.putheader(key, val)
43+
44+
# Saves the cookie sent by the server in the previous response.
45+
# HTTPConnection.putheader can only be called after a request has been
46+
# started, and before it's been sent.
47+
if self.headers and 'Set-Cookie' in self.headers:
48+
self.__http.putheader('Cookie', self.headers['Set-Cookie'])
49+
50+
self.__http.endheaders()
51+
52+
# Write payload
53+
self.__http.send(data)
54+
55+
# Get reply to flush the request
56+
self.__http_response = self.__http.getresponse()
57+
self.code = self.__http_response.status
58+
self.message = self.__http_response.reason
59+
self.headers = self.__http_response.msg
60+
61+
THttpClient.flush = timbr_flush
62+
except:
63+
pass

pytimbr_sqla/hive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ class Cursor(common.DBAPICursor):
366366
visible by other cursors or connections.
367367
"""
368368

369-
def __init__(self, connection, arraysize=1000):
369+
def __init__(self, connection, arraysize=10000):
370370
self._operationHandle = None
371371
super(Cursor, self).__init__()
372372
self._arraysize = arraysize
@@ -391,7 +391,7 @@ def arraysize(self):
391391
@arraysize.setter
392392
def arraysize(self, value):
393393
"""Array size cannot be None, and should be an integer"""
394-
default_arraysize = 1000
394+
default_arraysize = 10000
395395
try:
396396
self._arraysize = int(value) or default_arraysize
397397
except TypeError:

test/requirements.txt

0 Bytes
Binary file not shown.

thrift/transport/THttpClient.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,12 @@ def write(self, buf):
172172
self.__wbuf.write(buf)
173173

174174
def flush(self):
175-
if self.isOpen():
176-
self.close()
177-
self.open()
175+
if self.__http_response is not None:
176+
self.__http_response.close()
177+
self.__http_response = None
178+
179+
if not self.isOpen():
180+
self.open()
178181

179182
# Pull data out of buffer
180183
data = self.__wbuf.getvalue()

0 commit comments

Comments
 (0)