iginx-pyclient 0.6.0__py3-none-any.whl
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.
- iginx_pyclient/__init__.py +17 -0
- iginx_pyclient/cluster_info.py +53 -0
- iginx_pyclient/dataset.py +266 -0
- iginx_pyclient/session.py +739 -0
- iginx_pyclient/thrift/__init__.py +0 -0
- iginx_pyclient/thrift/rpc/IService.py +6863 -0
- iginx_pyclient/thrift/rpc/__init__.py +1 -0
- iginx_pyclient/thrift/rpc/constants.py +14 -0
- iginx_pyclient/thrift/rpc/ttypes.py +8961 -0
- iginx_pyclient/time_series.py +36 -0
- iginx_pyclient/utils/__init__.py +17 -0
- iginx_pyclient/utils/bitmap.py +41 -0
- iginx_pyclient/utils/byte_utils.py +212 -0
- iginx_pyclient-0.6.0.dist-info/LICENSE +201 -0
- iginx_pyclient-0.6.0.dist-info/METADATA +38 -0
- iginx_pyclient-0.6.0.dist-info/RECORD +26 -0
- iginx_pyclient-0.6.0.dist-info/WHEEL +5 -0
- iginx_pyclient-0.6.0.dist-info/top_level.txt +1 -0
- thrift/__init__.py +0 -0
- thrift/rpc/IService.py +6863 -0
- thrift/rpc/__init__.py +1 -0
- thrift/rpc/constants.py +14 -0
- thrift/rpc/ttypes.py +8961 -0
- utils/__init__.py +17 -0
- utils/bitmap.py +41 -0
- utils/byte_utils.py +212 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
|
3
|
+
# distributed with this work for additional information
|
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
|
6
|
+
# "License"); you may not use this file except in compliance
|
|
7
|
+
# with the License. You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
#
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
|
3
|
+
# distributed with this work for additional information
|
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
|
6
|
+
# "License"); you may not use this file except in compliance
|
|
7
|
+
# with the License. You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
#
|
|
18
|
+
class ClusterInfo(object):
|
|
19
|
+
|
|
20
|
+
def __init__(self, resp):
|
|
21
|
+
self.__iginx_list = resp.iginxInfos
|
|
22
|
+
self.__storage_engine_list = resp.storageEngineInfos
|
|
23
|
+
self.__meta_storage_list = resp.metaStorageInfos
|
|
24
|
+
self.__local_meta_storage = resp.localMetaStorageInfo
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def get_iginx_list(self):
|
|
28
|
+
return self.__iginx_list
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get_storage_engine_list(self):
|
|
32
|
+
return self.__storage_engine_list
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_local_meta_storage(self):
|
|
36
|
+
return self.__local_meta_storage
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def get_meta_storage_list(self):
|
|
40
|
+
return self.__meta_storage_list
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def is_use_local_meta_storage(self):
|
|
44
|
+
return self.__local_meta_storage is not None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def __str__(self):
|
|
48
|
+
value = str(self.__iginx_list) + "\n" + str(self.__storage_engine_list) + "\n"
|
|
49
|
+
if self.__meta_storage_list:
|
|
50
|
+
value += str(self.__meta_storage_list)
|
|
51
|
+
else:
|
|
52
|
+
value += str(self.__local_meta_storage)
|
|
53
|
+
return value
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
|
3
|
+
# distributed with this work for additional information
|
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
|
6
|
+
# "License"); you may not use this file except in compliance
|
|
7
|
+
# with the License. You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
#
|
|
18
|
+
from enum import Enum
|
|
19
|
+
|
|
20
|
+
import pandas as pd
|
|
21
|
+
|
|
22
|
+
from .thrift.rpc.ttypes import SqlType, AggregateType, ExecuteSqlResp
|
|
23
|
+
from .utils.bitmap import Bitmap
|
|
24
|
+
from .utils.byte_utils import get_long_array, get_values_by_data_type, BytesParser
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Point(object):
|
|
28
|
+
|
|
29
|
+
def __init__(self, path, type, timestamp, value):
|
|
30
|
+
self.__path = path
|
|
31
|
+
self.__type = type
|
|
32
|
+
self.__timestamp = timestamp
|
|
33
|
+
self.__value = value
|
|
34
|
+
|
|
35
|
+
def get_path(self):
|
|
36
|
+
return self.__path
|
|
37
|
+
|
|
38
|
+
def get_type(self):
|
|
39
|
+
return self.__type
|
|
40
|
+
|
|
41
|
+
def get_timestamp(self):
|
|
42
|
+
return self.__timestamp
|
|
43
|
+
|
|
44
|
+
def get_value(self):
|
|
45
|
+
return self.__value
|
|
46
|
+
|
|
47
|
+
def to_df(self):
|
|
48
|
+
df = pd.DataFrame([BytesParser(self.__timestamp).next_long(), BytesParser(self.__value).next(self.__type)],
|
|
49
|
+
columns=["key", str(self.__path)])
|
|
50
|
+
return df
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class QueryDataSet(object):
|
|
54
|
+
|
|
55
|
+
def __init__(self, paths, types, timestamps, values_list, bitmap_list):
|
|
56
|
+
self.__paths = paths
|
|
57
|
+
|
|
58
|
+
if timestamps is None:
|
|
59
|
+
self.__timestamps = []
|
|
60
|
+
else:
|
|
61
|
+
self.__timestamps = get_long_array(timestamps)
|
|
62
|
+
|
|
63
|
+
self.__values = []
|
|
64
|
+
if values_list is not None:
|
|
65
|
+
for i in range(len(values_list)):
|
|
66
|
+
values = []
|
|
67
|
+
bitmap = Bitmap(len(types), bitmap_list[i])
|
|
68
|
+
value_parser = BytesParser(values_list[i])
|
|
69
|
+
for j in range(len(types)):
|
|
70
|
+
if bitmap.get(j):
|
|
71
|
+
values.append(value_parser.next(types[j]))
|
|
72
|
+
else:
|
|
73
|
+
values.append(None)
|
|
74
|
+
self.__values.append(values)
|
|
75
|
+
|
|
76
|
+
def get_paths(self):
|
|
77
|
+
return self.__paths
|
|
78
|
+
|
|
79
|
+
def get_timestamps(self):
|
|
80
|
+
return self.__timestamps
|
|
81
|
+
|
|
82
|
+
def get_values(self):
|
|
83
|
+
return self.__values
|
|
84
|
+
|
|
85
|
+
def __str__(self):
|
|
86
|
+
value = "Time\t"
|
|
87
|
+
for path in self.__paths:
|
|
88
|
+
value += path + "\t"
|
|
89
|
+
value += "\n"
|
|
90
|
+
|
|
91
|
+
for i in range(len(self.__timestamps)):
|
|
92
|
+
value += str(self.__timestamps[i]) + "\t"
|
|
93
|
+
for j in range(len(self.__paths)):
|
|
94
|
+
if self.__values[i][j] is None:
|
|
95
|
+
value += "null\t"
|
|
96
|
+
else:
|
|
97
|
+
value += str(self.__values[i][j]) + "\t"
|
|
98
|
+
value += "\n"
|
|
99
|
+
return value
|
|
100
|
+
|
|
101
|
+
def to_df(self):
|
|
102
|
+
columns = ["key"]
|
|
103
|
+
for column in self.__paths:
|
|
104
|
+
columns.append(str(column))
|
|
105
|
+
|
|
106
|
+
value_matrix = []
|
|
107
|
+
for i in range(len(self.__timestamps)):
|
|
108
|
+
value = [self.__timestamps[i]]
|
|
109
|
+
value.extend(self.__values[i])
|
|
110
|
+
value_matrix.append(value)
|
|
111
|
+
|
|
112
|
+
return pd.DataFrame(value_matrix, columns=columns)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class AggregateQueryDataSet(object):
|
|
116
|
+
|
|
117
|
+
def __init__(self, resp, type):
|
|
118
|
+
self.__type = type
|
|
119
|
+
self.__paths = resp.paths
|
|
120
|
+
self.__timestamps = None
|
|
121
|
+
if resp.keys is not None:
|
|
122
|
+
self.__timestamps = get_long_array(resp.keys)
|
|
123
|
+
self.__values = get_values_by_data_type(resp.valuesList, resp.dataTypeList)
|
|
124
|
+
|
|
125
|
+
def get_type(self):
|
|
126
|
+
return self.__type
|
|
127
|
+
|
|
128
|
+
def get_paths(self):
|
|
129
|
+
return self.__paths
|
|
130
|
+
|
|
131
|
+
def get_timestamps(self):
|
|
132
|
+
return self.__timestamps
|
|
133
|
+
|
|
134
|
+
def get_values(self):
|
|
135
|
+
return self.__values
|
|
136
|
+
|
|
137
|
+
def __str__(self):
|
|
138
|
+
value = ""
|
|
139
|
+
if self.__timestamps:
|
|
140
|
+
for i in range(len(self.__timestamps)):
|
|
141
|
+
value += "Time\t" + AggregateType._VALUES_TO_NAMES[self.__type] + "(" + self.__paths[i] + ")\n"
|
|
142
|
+
value += str(self.__timestamps[i]) + "\t" + str(self.__values[i]) + "\n"
|
|
143
|
+
else:
|
|
144
|
+
for path in self.__paths:
|
|
145
|
+
value += AggregateType._VALUES_TO_NAMES[self.__type] + "(" + path + ")\t"
|
|
146
|
+
value += "\n"
|
|
147
|
+
for v in self.__values:
|
|
148
|
+
value += str(v) + "\t"
|
|
149
|
+
value += "\n"
|
|
150
|
+
return value
|
|
151
|
+
|
|
152
|
+
def to_df(self):
|
|
153
|
+
columns = []
|
|
154
|
+
values = []
|
|
155
|
+
# multiple row with different keys, each path, and it's value will be turned into a dataframe
|
|
156
|
+
if self.__timestamps:
|
|
157
|
+
df_list = []
|
|
158
|
+
for i in range(len(self.__timestamps)):
|
|
159
|
+
columns = ["key", AggregateType._VALUES_TO_NAMES[self.__type] + "(" + self.__paths[i] + ")"]
|
|
160
|
+
values = [self.__timestamps[i], self.__values[i]]
|
|
161
|
+
df_list.append(pd.DataFrame(data=[values], columns=columns))
|
|
162
|
+
return df_list
|
|
163
|
+
# no timestamp specified, only need to match paths and its value
|
|
164
|
+
else:
|
|
165
|
+
for path in self.__paths:
|
|
166
|
+
columns.append(AggregateType._VALUES_TO_NAMES[self.__type] + "(" + path + ")")
|
|
167
|
+
for v in self.__values:
|
|
168
|
+
values.append(v)
|
|
169
|
+
return [pd.DataFrame(data=[values], columns=columns)]
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class StatementExecuteDataSet(object):
|
|
173
|
+
class State(Enum):
|
|
174
|
+
HAS_MORE = 1,
|
|
175
|
+
NO_MORE = 2,
|
|
176
|
+
UNKNOWN = 3
|
|
177
|
+
|
|
178
|
+
def __init__(self, session, query_id, columns, types, fetch_size, values_list, bitmap_list, exportStreamDir=None,
|
|
179
|
+
exportCSV=None):
|
|
180
|
+
self.__session = session
|
|
181
|
+
self.__query_id = query_id
|
|
182
|
+
self.__columns = columns
|
|
183
|
+
self.__types = types
|
|
184
|
+
self.__fetch_size = fetch_size
|
|
185
|
+
self.__values_list = values_list
|
|
186
|
+
self.__bitmap_list = bitmap_list
|
|
187
|
+
self.__state = StatementExecuteDataSet.State.UNKNOWN
|
|
188
|
+
self.__exportStreamDir = exportStreamDir
|
|
189
|
+
self.__exportCSV = exportCSV
|
|
190
|
+
self.__index = 0
|
|
191
|
+
|
|
192
|
+
def fetch(self):
|
|
193
|
+
if self.__bitmap_list and self.__index != len(self.__bitmap_list):
|
|
194
|
+
return
|
|
195
|
+
|
|
196
|
+
self.__bitmap_list = None
|
|
197
|
+
self.__values_list = None
|
|
198
|
+
self.__index = 0
|
|
199
|
+
|
|
200
|
+
tp = self.__session._fetch(self.__query_id, self.__fetch_size)
|
|
201
|
+
|
|
202
|
+
if tp[0]:
|
|
203
|
+
self.__state = StatementExecuteDataSet.State.HAS_MORE
|
|
204
|
+
else:
|
|
205
|
+
self.__state = StatementExecuteDataSet.State.NO_MORE
|
|
206
|
+
|
|
207
|
+
if tp[1]:
|
|
208
|
+
self.__bitmap_list = tp[1].bitmapList
|
|
209
|
+
self.__values_list = tp[1].valuesList
|
|
210
|
+
|
|
211
|
+
def has_more(self):
|
|
212
|
+
if self.__values_list and self.__index < len(self.__values_list):
|
|
213
|
+
return True
|
|
214
|
+
|
|
215
|
+
self.__bitmap_list = None
|
|
216
|
+
self.__values_list = None
|
|
217
|
+
self.__index = 0
|
|
218
|
+
|
|
219
|
+
if self.__state == StatementExecuteDataSet.State.HAS_MORE or self.__state == StatementExecuteDataSet.State.UNKNOWN:
|
|
220
|
+
self.fetch()
|
|
221
|
+
|
|
222
|
+
return self.__values_list
|
|
223
|
+
|
|
224
|
+
def next(self):
|
|
225
|
+
if not self.has_more():
|
|
226
|
+
return None
|
|
227
|
+
|
|
228
|
+
values_buffer = self.__values_list[self.__index]
|
|
229
|
+
bitmap_buffer = self.__bitmap_list[self.__index]
|
|
230
|
+
self.__index += 1
|
|
231
|
+
|
|
232
|
+
bitmap = Bitmap(len(self.__types), bitmap_buffer)
|
|
233
|
+
value_parser = BytesParser(values_buffer)
|
|
234
|
+
values = []
|
|
235
|
+
for i in range(len(self.__types)):
|
|
236
|
+
if bitmap.get(i):
|
|
237
|
+
values.append(value_parser.next(self.__types[i]))
|
|
238
|
+
else:
|
|
239
|
+
values.append(None)
|
|
240
|
+
return values
|
|
241
|
+
|
|
242
|
+
def next_row_as_bytes(self, remove_key):
|
|
243
|
+
if not self.has_more():
|
|
244
|
+
return None
|
|
245
|
+
|
|
246
|
+
values_buffer = self.__values_list[self.__index]
|
|
247
|
+
self.__index += 1
|
|
248
|
+
bytes_value = BytesParser(values_buffer).get_bytes_from_types(self.__types)
|
|
249
|
+
if remove_key:
|
|
250
|
+
bytes_value = bytes_value[8:]
|
|
251
|
+
return bytes_value
|
|
252
|
+
|
|
253
|
+
def close(self):
|
|
254
|
+
self.__session._close_statement(query_id=self.__query_id)
|
|
255
|
+
|
|
256
|
+
def columns(self):
|
|
257
|
+
return self.__columns
|
|
258
|
+
|
|
259
|
+
def types(self):
|
|
260
|
+
return self.__types
|
|
261
|
+
|
|
262
|
+
def get_export_stream_dir(self):
|
|
263
|
+
return self.__exportStreamDir
|
|
264
|
+
|
|
265
|
+
def get_export_csv(self):
|
|
266
|
+
return self.__exportCSV
|