e6data-python-connector 2.0.0__tar.gz → 2.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {e6data-python-connector-2.0.0/e6data_python_connector.egg-info → e6data-python-connector-2.0.2}/PKG-INFO +11 -4
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/README.md +10 -3
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/common.py +1 -1
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/datainputstream.py +31 -11
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/e6data_grpc.py +1 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2/e6data_python_connector.egg-info}/PKG-INFO +11 -4
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector.egg-info/SOURCES.txt +1 -10
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector.egg-info/top_level.txt +0 -1
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/setup.py +1 -1
- e6data-python-connector-2.0.0/e6xdb/__init__.py +0 -10
- e6data-python-connector-2.0.0/e6xdb/common.py +0 -269
- e6data-python-connector-2.0.0/e6xdb/constants.py +0 -32
- e6data-python-connector-2.0.0/e6xdb/datainputstream.py +0 -225
- e6data-python-connector-2.0.0/e6xdb/date_time_utils.py +0 -167
- e6data-python-connector-2.0.0/e6xdb/e6x.py +0 -515
- e6data-python-connector-2.0.0/e6xdb/exceptions.py +0 -15
- e6data-python-connector-2.0.0/e6xdb/sqlalchemy_e6x.py +0 -396
- e6data-python-connector-2.0.0/e6xdb/typeId.py +0 -73
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/LICENSE +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/MANIFEST.in +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/__init__.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/constants.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/date_time_utils.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/dialect.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/e6x_vector/__init__.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/e6x_vector/constants.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/e6x_vector/ttypes.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/exceptions.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/server/QueryEngineService.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/server/__init__.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/server/constants.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/server/e6x_engine_pb2.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/server/e6x_engine_pb2.pyi +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/server/e6x_engine_pb2_grpc.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/server/ttypes.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/typeId.py +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector.egg-info/dependency_links.txt +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector.egg-info/entry_points.txt +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector.egg-info/requires.txt +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/pyproject.toml +0 -0
- {e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: e6data-python-connector
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.2
|
|
4
4
|
Summary: Client for the e6data distributed SQL Engine.
|
|
5
5
|
Home-page: https://github.com/e6x-labs/e6data-python-connector
|
|
6
6
|
Author: Uniphi, Inc.
|
|
@@ -27,20 +27,27 @@ Requires-Dist: sqlalchemy
|
|
|
27
27
|
|
|
28
28
|
# e6data Python Connector
|
|
29
29
|
|
|
30
|
-

|
|
31
31
|
|
|
32
32
|
## Introduction
|
|
33
33
|
|
|
34
34
|
The e6data Connector for Python provides an interface for writing Python applications that can connect to e6data and perform operations.
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
Make sure to install
|
|
36
|
+
### Dependencies
|
|
37
|
+
Make sure to install below dependencies and wheel before install e6data-python-connector.
|
|
38
38
|
```shell
|
|
39
|
+
# Amazon Linux / CentOS dependencies
|
|
39
40
|
yum install python3-devel gcc-c++ -y
|
|
40
41
|
|
|
42
|
+
# Ubuntu/Debian dependencies
|
|
43
|
+
apt install python3-dev g++ -y
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# Pip dependencies
|
|
41
47
|
pip install wheel
|
|
42
48
|
```
|
|
43
49
|
|
|
50
|
+
|
|
44
51
|
To install the Python package, use the command below:
|
|
45
52
|
```shell
|
|
46
53
|
pip install --no-cache-dir e6data-python-connector
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
# e6data Python Connector
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
7
7
|
The e6data Connector for Python provides an interface for writing Python applications that can connect to e6data and perform operations.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
Make sure to install
|
|
9
|
+
### Dependencies
|
|
10
|
+
Make sure to install below dependencies and wheel before install e6data-python-connector.
|
|
11
11
|
```shell
|
|
12
|
+
# Amazon Linux / CentOS dependencies
|
|
12
13
|
yum install python3-devel gcc-c++ -y
|
|
13
14
|
|
|
15
|
+
# Ubuntu/Debian dependencies
|
|
16
|
+
apt install python3-dev g++ -y
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Pip dependencies
|
|
14
20
|
pip install wheel
|
|
15
21
|
```
|
|
16
22
|
|
|
23
|
+
|
|
17
24
|
To install the Python package, use the command below:
|
|
18
25
|
```shell
|
|
19
26
|
pip install --no-cache-dir e6data-python-connector
|
{e6data-python-connector-2.0.0 → e6data-python-connector-2.0.2}/e6data_python_connector/common.py
RENAMED
|
@@ -18,7 +18,7 @@ from builtins import str
|
|
|
18
18
|
from future.utils import with_metaclass
|
|
19
19
|
from past.builtins import basestring
|
|
20
20
|
|
|
21
|
-
from
|
|
21
|
+
from e6data_python_connector.exceptions import ProgrammingError
|
|
22
22
|
|
|
23
23
|
_logger = logging.getLogger(__name__)
|
|
24
24
|
|
|
@@ -7,8 +7,19 @@ from thrift.protocol import TBinaryProtocol
|
|
|
7
7
|
from thrift.transport import TTransport
|
|
8
8
|
|
|
9
9
|
from e6data_python_connector.e6x_vector.ttypes import Chunk, Vector, VectorType
|
|
10
|
-
from
|
|
11
|
-
from
|
|
10
|
+
from e6data_python_connector.constants import ZONE
|
|
11
|
+
from e6data_python_connector.date_time_utils import floor_div, floor_mod, get_zone
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
from thrift.protocol import fastbinary
|
|
15
|
+
except ImportError:
|
|
16
|
+
raise Exception(
|
|
17
|
+
"""
|
|
18
|
+
Failed to import fastbinary.
|
|
19
|
+
Did you install system dependencies?
|
|
20
|
+
Please verify https://github.com/e6x-labs/e6data-python-connector#dependencies
|
|
21
|
+
"""
|
|
22
|
+
)
|
|
12
23
|
|
|
13
24
|
_logger = logging.getLogger(__name__)
|
|
14
25
|
|
|
@@ -195,13 +206,16 @@ def get_column_from_chunk(vector: Vector) -> list:
|
|
|
195
206
|
if vector.nullSet[row]:
|
|
196
207
|
value_array.append(None)
|
|
197
208
|
continue
|
|
198
|
-
value_array.append(vector.data.int64Data.data[
|
|
209
|
+
value_array.append(vector.data.int64Data.data[
|
|
210
|
+
row] if not vector.isConstantVector else vector.data.numericConstantData.data)
|
|
199
211
|
elif d_type == VectorType.DATE:
|
|
200
212
|
for row in range(vector.size):
|
|
201
213
|
if vector.nullSet[row]:
|
|
202
214
|
value_array.append(None)
|
|
203
215
|
continue
|
|
204
|
-
epoch_seconds = floor_div(vector.data.dateData.data[
|
|
216
|
+
epoch_seconds = floor_div(vector.data.dateData.data[
|
|
217
|
+
row] if not vector.isConstantVector else vector.data.dateConstantData.data,
|
|
218
|
+
1000_000)
|
|
205
219
|
zone_offset = pytz.timezone('UTC') if vector.zoneOffset == 'Z' else pytz.timezone(vector.zoneOffset)
|
|
206
220
|
date = datetime.fromtimestamp(epoch_seconds, zone_offset)
|
|
207
221
|
value_array.append(date.strftime("%Y-%m-%d"))
|
|
@@ -213,7 +227,7 @@ def get_column_from_chunk(vector: Vector) -> list:
|
|
|
213
227
|
epoch_micros = vector.data.timeData.data[row] if not vector.isConstantVector else vector.data.timeConstantData.data
|
|
214
228
|
epoch_seconds = floor_div(epoch_micros, 1000_000)
|
|
215
229
|
micros_of_the_day = floor_mod(epoch_micros, 1000_000)
|
|
216
|
-
zone_offset = pytz.timezone('UTC') if vector.zoneOffset == 'Z' else pytz.timezone(vector.zoneOffset)
|
|
230
|
+
zone_offset = pytz.timezone('UTC') if vector.zoneOffset == 'Z' else pytz.timezone(get_zone(vector.zoneOffset))
|
|
217
231
|
date_time = datetime.fromtimestamp(epoch_seconds, zone_offset)
|
|
218
232
|
date_time = date_time + timedelta(microseconds=micros_of_the_day)
|
|
219
233
|
value_array.append(date_time.strftime("%Y-%m-%d %H:%M:%S"))
|
|
@@ -222,37 +236,43 @@ def get_column_from_chunk(vector: Vector) -> list:
|
|
|
222
236
|
if vector.nullSet[row]:
|
|
223
237
|
value_array.append(None)
|
|
224
238
|
continue
|
|
225
|
-
value_array.append(vector.data.varcharData.data[
|
|
239
|
+
value_array.append(vector.data.varcharData.data[
|
|
240
|
+
row] if not vector.isConstantVector else vector.data.varcharConstantData.data)
|
|
226
241
|
elif d_type == VectorType.DOUBLE:
|
|
227
242
|
for row in range(vector.size):
|
|
228
243
|
if vector.nullSet[row]:
|
|
229
244
|
value_array.append(None)
|
|
230
245
|
continue
|
|
231
|
-
value_array.append(vector.data.float64Data.data[
|
|
246
|
+
value_array.append(vector.data.float64Data.data[
|
|
247
|
+
row] if not vector.isConstantVector else vector.data.numericDecimalConstantData.data)
|
|
232
248
|
elif d_type == VectorType.BINARY:
|
|
233
249
|
for row in range(vector.size):
|
|
234
250
|
if vector.nullSet[row]:
|
|
235
251
|
value_array.append(None)
|
|
236
252
|
continue
|
|
237
|
-
value_array.append(vector.data.varcharData.data[
|
|
253
|
+
value_array.append(vector.data.varcharData.data[
|
|
254
|
+
row] if not vector.isConstantVector else vector.data.varcharConstantData.data)
|
|
238
255
|
elif d_type == VectorType.FLOAT:
|
|
239
256
|
for row in range(vector.size):
|
|
240
257
|
if vector.nullSet[row]:
|
|
241
258
|
value_array.append(None)
|
|
242
259
|
continue
|
|
243
|
-
value_array.append(vector.data.float32Data.data[
|
|
260
|
+
value_array.append(vector.data.float32Data.data[
|
|
261
|
+
row] if not vector.isConstantVector else vector.data.numericDecimalConstantData.data)
|
|
244
262
|
elif d_type == VectorType.BOOLEAN:
|
|
245
263
|
for row in range(vector.size):
|
|
246
264
|
if vector.nullSet[row]:
|
|
247
265
|
value_array.append(None)
|
|
248
266
|
continue
|
|
249
|
-
value_array.append(vector.data.boolData.data[
|
|
267
|
+
value_array.append(vector.data.boolData.data[
|
|
268
|
+
row] if not vector.isConstantVector else vector.data.boolConstantData.data)
|
|
250
269
|
elif d_type == VectorType.INTEGER:
|
|
251
270
|
for row in range(vector.size):
|
|
252
271
|
if vector.nullSet[row]:
|
|
253
272
|
value_array.append(None)
|
|
254
273
|
continue
|
|
255
|
-
value_array.append(vector.data.int32Data.data[
|
|
274
|
+
value_array.append(vector.data.int32Data.data[
|
|
275
|
+
row] if not vector.isConstantVector else vector.data.numericConstantData.data)
|
|
256
276
|
else:
|
|
257
277
|
value_array.append(None)
|
|
258
278
|
except Exception as e:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: e6data-python-connector
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.2
|
|
4
4
|
Summary: Client for the e6data distributed SQL Engine.
|
|
5
5
|
Home-page: https://github.com/e6x-labs/e6data-python-connector
|
|
6
6
|
Author: Uniphi, Inc.
|
|
@@ -27,20 +27,27 @@ Requires-Dist: sqlalchemy
|
|
|
27
27
|
|
|
28
28
|
# e6data Python Connector
|
|
29
29
|
|
|
30
|
-

|
|
31
31
|
|
|
32
32
|
## Introduction
|
|
33
33
|
|
|
34
34
|
The e6data Connector for Python provides an interface for writing Python applications that can connect to e6data and perform operations.
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
Make sure to install
|
|
36
|
+
### Dependencies
|
|
37
|
+
Make sure to install below dependencies and wheel before install e6data-python-connector.
|
|
38
38
|
```shell
|
|
39
|
+
# Amazon Linux / CentOS dependencies
|
|
39
40
|
yum install python3-devel gcc-c++ -y
|
|
40
41
|
|
|
42
|
+
# Ubuntu/Debian dependencies
|
|
43
|
+
apt install python3-dev g++ -y
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# Pip dependencies
|
|
41
47
|
pip install wheel
|
|
42
48
|
```
|
|
43
49
|
|
|
50
|
+
|
|
44
51
|
To install the Python package, use the command below:
|
|
45
52
|
```shell
|
|
46
53
|
pip install --no-cache-dir e6data-python-connector
|
|
@@ -28,13 +28,4 @@ e6data_python_connector/server/constants.py
|
|
|
28
28
|
e6data_python_connector/server/e6x_engine_pb2.py
|
|
29
29
|
e6data_python_connector/server/e6x_engine_pb2.pyi
|
|
30
30
|
e6data_python_connector/server/e6x_engine_pb2_grpc.py
|
|
31
|
-
e6data_python_connector/server/ttypes.py
|
|
32
|
-
e6xdb/__init__.py
|
|
33
|
-
e6xdb/common.py
|
|
34
|
-
e6xdb/constants.py
|
|
35
|
-
e6xdb/datainputstream.py
|
|
36
|
-
e6xdb/date_time_utils.py
|
|
37
|
-
e6xdb/e6x.py
|
|
38
|
-
e6xdb/exceptions.py
|
|
39
|
-
e6xdb/sqlalchemy_e6x.py
|
|
40
|
-
e6xdb/typeId.py
|
|
31
|
+
e6data_python_connector/server/ttypes.py
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
THIS SPECIFIC FILE IS DISTRIBUTED UNDER THE UNLICENSE: http://unlicense.org.
|
|
3
|
-
|
|
4
|
-
THIS MEANS YOU CAN USE THIS CODE EXAMPLE TO KICKSTART A PROJECT YOUR OWN.
|
|
5
|
-
AFTER YOU CREATED YOUR OWN ORIGINAL WORK, YOU CAN REPLACE THIS HEADER :)
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from __future__ import absolute_import
|
|
9
|
-
from __future__ import unicode_literals
|
|
10
|
-
__version__ = '0.0.1'
|
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
"""Package private common utilities. Do not use directly.
|
|
2
|
-
Many docstrings in this file are based on PEP-249, which is in the public domain.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from __future__ import absolute_import
|
|
6
|
-
from __future__ import unicode_literals
|
|
7
|
-
|
|
8
|
-
import abc
|
|
9
|
-
import collections
|
|
10
|
-
import datetime
|
|
11
|
-
import logging
|
|
12
|
-
import time
|
|
13
|
-
from builtins import bytes
|
|
14
|
-
from builtins import int
|
|
15
|
-
from builtins import object
|
|
16
|
-
from builtins import str
|
|
17
|
-
|
|
18
|
-
from future.utils import with_metaclass
|
|
19
|
-
from past.builtins import basestring
|
|
20
|
-
|
|
21
|
-
from e6xdb.exceptions import ProgrammingError
|
|
22
|
-
|
|
23
|
-
_logger = logging.getLogger(__name__)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class DBAPICursor(with_metaclass(abc.ABCMeta, object)):
|
|
27
|
-
"""Base class for some common DB-API logic"""
|
|
28
|
-
|
|
29
|
-
_STATE_NONE = 0
|
|
30
|
-
_STATE_RUNNING = 1
|
|
31
|
-
_STATE_FINISHED = 2
|
|
32
|
-
|
|
33
|
-
def __init__(self, poll_interval=1):
|
|
34
|
-
self._poll_interval = poll_interval
|
|
35
|
-
self._reset_state()
|
|
36
|
-
self.lastrowid = None
|
|
37
|
-
self._data = None
|
|
38
|
-
|
|
39
|
-
def _reset_state(self):
|
|
40
|
-
"""Reset state about the previous query in preparation for running another query"""
|
|
41
|
-
# State to return as part of DB-API
|
|
42
|
-
self._rownumber = 0
|
|
43
|
-
|
|
44
|
-
# Internal helper state
|
|
45
|
-
self._data = collections.deque()
|
|
46
|
-
self._columns = None
|
|
47
|
-
|
|
48
|
-
def _fetch_while(self, fn):
|
|
49
|
-
_logger.info("Commons - fetch while.... fn type - {}".format(type(fn)))
|
|
50
|
-
while fn():
|
|
51
|
-
_logger.info("fetching next fetch more from fetch while")
|
|
52
|
-
self._fetch_more()
|
|
53
|
-
if fn():
|
|
54
|
-
time.sleep(self._poll_interval)
|
|
55
|
-
|
|
56
|
-
@abc.abstractmethod
|
|
57
|
-
def description(self):
|
|
58
|
-
raise NotImplementedError # pragma: no cover
|
|
59
|
-
|
|
60
|
-
def close(self):
|
|
61
|
-
"""By default, do nothing"""
|
|
62
|
-
pass
|
|
63
|
-
|
|
64
|
-
@abc.abstractmethod
|
|
65
|
-
def _fetch_more(self):
|
|
66
|
-
"""Get more results, append it to ``self._data``, and update ``self._state``."""
|
|
67
|
-
raise NotImplementedError # pragma: no cover
|
|
68
|
-
|
|
69
|
-
@property
|
|
70
|
-
def rowcount(self):
|
|
71
|
-
"""By default, return -1 to indicate that this is not supported."""
|
|
72
|
-
return self.rowcount
|
|
73
|
-
|
|
74
|
-
@abc.abstractmethod
|
|
75
|
-
def execute(self, operation, parameters=None):
|
|
76
|
-
"""Prepare and execute a database operation (query or command).
|
|
77
|
-
Parameters may be provided as sequence or mapping and will be bound to variables in the
|
|
78
|
-
operation. Variables are specified in a database-specific notation (see the e6xdb's
|
|
79
|
-
``paramstyle`` attribute for details).
|
|
80
|
-
Return values are not defined.
|
|
81
|
-
"""
|
|
82
|
-
raise NotImplementedError # pragma: no cover
|
|
83
|
-
|
|
84
|
-
def executemany(self, operation, seq_of_parameters):
|
|
85
|
-
"""Prepare a database operation (query or command) and then execute it against all parameter
|
|
86
|
-
sequences or mappings found in the sequence ``seq_of_parameters``.
|
|
87
|
-
Only the final result set is retained.
|
|
88
|
-
Return values are not defined.
|
|
89
|
-
"""
|
|
90
|
-
for parameters in seq_of_parameters[:-1]:
|
|
91
|
-
self.execute(operation, parameters)
|
|
92
|
-
# while self._state != self._STATE_FINISHED:
|
|
93
|
-
# self._fetch_more()
|
|
94
|
-
if seq_of_parameters:
|
|
95
|
-
self.execute(operation, seq_of_parameters[-1])
|
|
96
|
-
|
|
97
|
-
def fetchone(self):
|
|
98
|
-
"""Fetch the next row of a query result set, returning a single sequence, or ``None`` when
|
|
99
|
-
no more data is available.
|
|
100
|
-
An :py:class:`~pyhive.exc.Error` (or subclass) exception is raised if the previous call to
|
|
101
|
-
:py:meth:`execute` did not produce any result set or no call was issued yet.
|
|
102
|
-
"""
|
|
103
|
-
# if self._state == self._STATE_NONE:
|
|
104
|
-
# raise ProgrammingError("No query yet")
|
|
105
|
-
#
|
|
106
|
-
# # Sleep until we're done or we have some data to return
|
|
107
|
-
# self._fetch_while(lambda: not self._data and self._state != self._STATE_FINISHED)
|
|
108
|
-
|
|
109
|
-
# Sleep until we're done or we have some data to return
|
|
110
|
-
# self._fetch_while(lambda: not self._data and self._state != self._STATE_FINISHED)
|
|
111
|
-
if not self._data:
|
|
112
|
-
return None
|
|
113
|
-
else:
|
|
114
|
-
# if self._rownumber <= 1000:
|
|
115
|
-
# _logger.info("Commons - Breaking the loop after 1000Commons - fetch many records")
|
|
116
|
-
# return None
|
|
117
|
-
self._rownumber += 1
|
|
118
|
-
return self._data.popleft()
|
|
119
|
-
|
|
120
|
-
def fetchmany(self, size=None):
|
|
121
|
-
"""Fetch the next set of rows of a query result, returning a sequence of sequences (e.g. a
|
|
122
|
-
list of tuples). An empty sequence is returned when no more rows are available.
|
|
123
|
-
The number of rows to fetch per call is specified by the parameter. If it is not given, the
|
|
124
|
-
cursor's arraysize determines the number of rows to be fetched. The method should try to
|
|
125
|
-
fetch as many rows as indicated by the size parameter. If this is not possible due to the
|
|
126
|
-
specified number of rows not being available, fewer rows may be returned.
|
|
127
|
-
An :py:class:`~pyhive.exc.Error` (or subclass) exception is raised if the previous call to
|
|
128
|
-
:py:meth:`execute` did not produce any result set or no call was issued yet.
|
|
129
|
-
"""
|
|
130
|
-
_logger.info("Commons - fetch many.... size - {}".format(size))
|
|
131
|
-
rowsToReturn = self.fetchone()
|
|
132
|
-
|
|
133
|
-
if rowsToReturn is None:
|
|
134
|
-
return list()
|
|
135
|
-
return list(rowsToReturn)
|
|
136
|
-
|
|
137
|
-
def fetchall(self):
|
|
138
|
-
"""Fetch all (remaining) rows of a query result, returning them as a sequence of sequences
|
|
139
|
-
(e.g. a list of tuples).
|
|
140
|
-
An :py:class:`~pyhive.exc.Error` (or subclass) exception is raised if the previous call to
|
|
141
|
-
:py:meth:`execute` did not produce any result set or no call was issued yet.
|
|
142
|
-
"""
|
|
143
|
-
_logger.info("Commons - fetch all")
|
|
144
|
-
return list(iter(self.fetchone, None))
|
|
145
|
-
|
|
146
|
-
@property
|
|
147
|
-
def arraysize(self):
|
|
148
|
-
"""This read/write attribute specifies the number of rows to fetch at a time with
|
|
149
|
-
:py:meth:`fetchmany`. It defaults to 1 meaning to fetch a single row at a time.
|
|
150
|
-
"""
|
|
151
|
-
return self._arraysize
|
|
152
|
-
|
|
153
|
-
@arraysize.setter
|
|
154
|
-
def arraysize(self, value):
|
|
155
|
-
self._arraysize = value
|
|
156
|
-
|
|
157
|
-
def setinputsizes(self, sizes):
|
|
158
|
-
"""Does nothing by default"""
|
|
159
|
-
pass
|
|
160
|
-
|
|
161
|
-
def setoutputsize(self, size, column=None):
|
|
162
|
-
"""Does nothing by default"""
|
|
163
|
-
pass
|
|
164
|
-
|
|
165
|
-
#
|
|
166
|
-
# Optional DB API Extensions
|
|
167
|
-
#
|
|
168
|
-
|
|
169
|
-
@property
|
|
170
|
-
def rownumber(self):
|
|
171
|
-
"""This read-only attribute should provide the current 0-based index of the cursor in the
|
|
172
|
-
result set.
|
|
173
|
-
The index can be seen as index of the cursor in a sequence (the result set). The next fetch
|
|
174
|
-
operation will fetch the row indexed by ``rownumber`` in that sequence.
|
|
175
|
-
"""
|
|
176
|
-
return self._rownumber
|
|
177
|
-
|
|
178
|
-
def __next__(self):
|
|
179
|
-
"""Return the next row from the currently executing SQL statement using the same semantics
|
|
180
|
-
as :py:meth:`fetchone`. A ``StopIteration`` exception is raised when the result set is
|
|
181
|
-
exhausted.
|
|
182
|
-
"""
|
|
183
|
-
_logger.info("Commons - fetching the next row")
|
|
184
|
-
one = self.fetchone()
|
|
185
|
-
if one is None:
|
|
186
|
-
raise StopIteration
|
|
187
|
-
else:
|
|
188
|
-
return one
|
|
189
|
-
|
|
190
|
-
next = __next__
|
|
191
|
-
|
|
192
|
-
def __iter__(self):
|
|
193
|
-
"""Return self to make cursors compatible to the iteration protocol."""
|
|
194
|
-
return self
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
class DBAPITypeObject(object):
|
|
198
|
-
# Taken from http://www.python.org/dev/peps/pep-0249/#implementation-hints
|
|
199
|
-
def __init__(self, *values):
|
|
200
|
-
self.values = values
|
|
201
|
-
|
|
202
|
-
def __cmp__(self, other):
|
|
203
|
-
if other in self.values:
|
|
204
|
-
return 0
|
|
205
|
-
if other < self.values:
|
|
206
|
-
return 1
|
|
207
|
-
else:
|
|
208
|
-
return -1
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
class ParamEscaper(object):
|
|
212
|
-
_DATE_FORMAT = "%Y-%m-%d"
|
|
213
|
-
_TIME_FORMAT = "%H:%M:%S.%f"
|
|
214
|
-
_DATETIME_FORMAT = "{} {}".format(_DATE_FORMAT, _TIME_FORMAT)
|
|
215
|
-
|
|
216
|
-
def escape_args(self, parameters):
|
|
217
|
-
if isinstance(parameters, dict):
|
|
218
|
-
return {k: self.escape_item(v) for k, v in parameters.items()}
|
|
219
|
-
elif isinstance(parameters, (list, tuple)):
|
|
220
|
-
return tuple(self.escape_item(x) for x in parameters)
|
|
221
|
-
else:
|
|
222
|
-
raise ProgrammingError("Unsupported param format: {}".format(parameters))
|
|
223
|
-
|
|
224
|
-
def escape_number(self, item):
|
|
225
|
-
return item
|
|
226
|
-
|
|
227
|
-
def escape_string(self, item):
|
|
228
|
-
# Need to decode UTF-8 because of old sqlalchemy.
|
|
229
|
-
# Newer SQLAlchemy checks dialect.supports_unicode_binds before encoding Unicode strings
|
|
230
|
-
# as byte strings. The old version always encodes Unicode as byte strings, which breaks
|
|
231
|
-
# string formatting here.
|
|
232
|
-
if isinstance(item, bytes):
|
|
233
|
-
item = item.decode('utf-8')
|
|
234
|
-
# This is good enough when backslashes are literal, newlines are just followed, and the way
|
|
235
|
-
# to escape a single quote is to put two single quotes.
|
|
236
|
-
# (i.e. only special character is single quote)
|
|
237
|
-
return "'{}'".format(item.replace("'", "''"))
|
|
238
|
-
|
|
239
|
-
def escape_sequence(self, item):
|
|
240
|
-
l = map(str, map(self.escape_item, item))
|
|
241
|
-
return '(' + ','.join(l) + ')'
|
|
242
|
-
|
|
243
|
-
def escape_datetime(self, item, format, cutoff=0):
|
|
244
|
-
dt_str = item.strftime(format)
|
|
245
|
-
formatted = dt_str[:-cutoff] if cutoff and format.endswith(".%f") else dt_str
|
|
246
|
-
return "'{}'".format(formatted)
|
|
247
|
-
|
|
248
|
-
def escape_item(self, item):
|
|
249
|
-
if item is None:
|
|
250
|
-
return 'NULL'
|
|
251
|
-
elif isinstance(item, (int, float)):
|
|
252
|
-
return self.escape_number(item)
|
|
253
|
-
elif isinstance(item, basestring):
|
|
254
|
-
return self.escape_string(item)
|
|
255
|
-
elif isinstance(item, collections.Iterable):
|
|
256
|
-
return self.escape_sequence(item)
|
|
257
|
-
elif isinstance(item, datetime.datetime):
|
|
258
|
-
return self.escape_datetime(item, self._DATETIME_FORMAT)
|
|
259
|
-
elif isinstance(item, datetime.date):
|
|
260
|
-
return self.escape_datetime(item, self._DATE_FORMAT)
|
|
261
|
-
else:
|
|
262
|
-
raise ProgrammingError("Unsupported object {}".format(item))
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
class UniversalSet(object):
|
|
266
|
-
"""set containing everything"""
|
|
267
|
-
|
|
268
|
-
def __contains__(self, item):
|
|
269
|
-
return True
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import pytz
|
|
2
|
-
|
|
3
|
-
PRIMITIVE_TYPES = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 16, 17, 18, 19, 20, 21}
|
|
4
|
-
COMPLEX_TYPES = {10, 11, 12, 13, 14}
|
|
5
|
-
COLLECTION_TYPES = {10, 11}
|
|
6
|
-
TYPE_NAMES = {
|
|
7
|
-
0: "BOOLEAN",
|
|
8
|
-
1: "TINYINT",
|
|
9
|
-
2: "SMALLINT",
|
|
10
|
-
3: "INT",
|
|
11
|
-
4: "BIGINT",
|
|
12
|
-
5: "FLOAT",
|
|
13
|
-
6: "DOUBLE",
|
|
14
|
-
7: "STRING",
|
|
15
|
-
8: "TIMESTAMP",
|
|
16
|
-
9: "BINARY",
|
|
17
|
-
10: "ARRAY",
|
|
18
|
-
11: "MAP",
|
|
19
|
-
12: "STRUCT",
|
|
20
|
-
13: "UNIONTYPE",
|
|
21
|
-
15: "DECIMAL",
|
|
22
|
-
16: "NULL",
|
|
23
|
-
17: "DATE",
|
|
24
|
-
18: "VARCHAR",
|
|
25
|
-
19: "CHAR",
|
|
26
|
-
20: "INTERVAL_YEAR_MONTH",
|
|
27
|
-
21: "INTERVAL_DAY_TIME",
|
|
28
|
-
}
|
|
29
|
-
CHARACTER_MAXIMUM_LENGTH = "characterMaximumLength"
|
|
30
|
-
PRECISION = "precision"
|
|
31
|
-
SCALE = "scale"
|
|
32
|
-
ZONE = pytz.timezone('UTC')
|