|
24 | 24 |
|
25 | 25 | _TIMESTAMP_PATTERN = re.compile(r'(\d+-\d+-\d+ \d+:\d+:\d+(\.\d{,6})?)') |
26 | 26 |
|
27 | | -TYPES_CONVERTER = {"decimal": Decimal} |
| 27 | + |
| 28 | +def _parse_timestamp(value): |
| 29 | + if type(value) is datetime.datetime: |
| 30 | + # The cmd exec server will return a datetime.datetime, so no further parsing is needed |
| 31 | + return value |
| 32 | + elif value: |
| 33 | + match = _TIMESTAMP_PATTERN.match(value) |
| 34 | + if match: |
| 35 | + if match.group(2): |
| 36 | + format = '%Y-%m-%d %H:%M:%S.%f' |
| 37 | + # use the pattern to truncate the value |
| 38 | + value = match.group() |
| 39 | + else: |
| 40 | + format = '%Y-%m-%d %H:%M:%S' |
| 41 | + value = datetime.datetime.strptime(value, format) |
| 42 | + return value |
| 43 | + else: |
| 44 | + raise Exception('Cannot convert "{}" into a datetime'.format(value)) |
| 45 | + else: |
| 46 | + return None |
| 47 | + |
| 48 | + |
| 49 | +TYPES_CONVERTER = { |
| 50 | + "decimal": Decimal, |
| 51 | + "timestamp": _parse_timestamp, |
| 52 | +} |
28 | 53 |
|
29 | 54 |
|
30 | 55 | class Connection: |
@@ -56,6 +81,8 @@ def __init__(self, server_hostname, http_path, access_token, metadata=None, **kw |
56 | 81 | # verification. If not provide, uses system truststore. |
57 | 82 | # _tls_client_cert_file, _tls_client_cert_key_file |
58 | 83 | # Set client SSL certificate. |
| 84 | + # _session_id |
| 85 | + # Specify the session id of the connection. For Redash use only. |
59 | 86 |
|
60 | 87 | self.host = server_hostname |
61 | 88 | self.port = kwargs.get("_port", 443) |
@@ -94,7 +121,7 @@ def __init__(self, server_hostname, http_path, access_token, metadata=None, **kw |
94 | 121 |
|
95 | 122 | open_session_request = messages_pb2.OpenSessionRequest( |
96 | 123 | configuration={}, |
97 | | - client_session_id=None, |
| 124 | + client_session_id=kwargs.get("_session_id"), |
98 | 125 | ) |
99 | 126 |
|
100 | 127 | resp = self.base_client.make_request(self.base_client.stub.OpenSession, |
|
0 commit comments