iginx-pyclient 0.6.1__tar.gz → 0.7.0__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.
Files changed (33) hide show
  1. {iginx-pyclient-0.6.1/iginx_pyclient.egg-info → iginx-pyclient-0.7.0}/PKG-INFO +38 -38
  2. iginx-pyclient-0.7.0/iginx_pyclient/__init__.py +19 -0
  3. iginx-pyclient-0.7.0/iginx_pyclient/cluster_info.py +68 -0
  4. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0}/iginx_pyclient/dataset.py +109 -22
  5. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0}/iginx_pyclient/session.py +41 -19
  6. iginx-pyclient-0.7.0/iginx_pyclient/thrift/__init__.py +18 -0
  7. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0}/iginx_pyclient/thrift/rpc/IService.py +585 -0
  8. iginx-pyclient-0.7.0/iginx_pyclient/thrift/rpc/__init__.py +19 -0
  9. iginx-pyclient-0.7.0/iginx_pyclient/thrift/rpc/constants.py +32 -0
  10. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0}/iginx_pyclient/thrift/rpc/ttypes.py +862 -251
  11. iginx-pyclient-0.7.0/iginx_pyclient/time_series.py +37 -0
  12. iginx-pyclient-0.7.0/iginx_pyclient/utils/__init__.py +19 -0
  13. iginx-pyclient-0.7.0/iginx_pyclient/utils/bitmap.py +41 -0
  14. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0}/iginx_pyclient/utils/byte_utils.py +28 -22
  15. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0/iginx_pyclient.egg-info}/PKG-INFO +38 -38
  16. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0}/setup.cfg +4 -4
  17. iginx-pyclient-0.7.0/setup.py +60 -0
  18. iginx-pyclient-0.6.1/iginx_pyclient/__init__.py +0 -17
  19. iginx-pyclient-0.6.1/iginx_pyclient/cluster_info.py +0 -53
  20. iginx-pyclient-0.6.1/iginx_pyclient/thrift/__init__.py +0 -0
  21. iginx-pyclient-0.6.1/iginx_pyclient/thrift/rpc/__init__.py +0 -1
  22. iginx-pyclient-0.6.1/iginx_pyclient/thrift/rpc/constants.py +0 -14
  23. iginx-pyclient-0.6.1/iginx_pyclient/time_series.py +0 -36
  24. iginx-pyclient-0.6.1/iginx_pyclient/utils/__init__.py +0 -17
  25. iginx-pyclient-0.6.1/iginx_pyclient/utils/bitmap.py +0 -41
  26. iginx-pyclient-0.6.1/setup.py +0 -35
  27. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0}/LICENSE +0 -0
  28. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0}/MANIFEST.in +0 -0
  29. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0}/README.md +0 -0
  30. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0}/iginx_pyclient.egg-info/SOURCES.txt +0 -0
  31. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0}/iginx_pyclient.egg-info/dependency_links.txt +0 -0
  32. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0}/iginx_pyclient.egg-info/requires.txt +0 -0
  33. {iginx-pyclient-0.6.1 → iginx-pyclient-0.7.0}/iginx_pyclient.egg-info/top_level.txt +0 -0
@@ -1,38 +1,38 @@
1
- Metadata-Version: 2.1
2
- Name: iginx-pyclient
3
- Version: 0.6.1
4
- Summary: IGinX-PyClient
5
- Author: THU IGinX
6
- Author-email: TSIginX@gmail.com
7
- License: Apache License 2.0
8
- Requires-Python: >=3.8
9
- Description-Content-Type: text/markdown
10
- License-File: LICENSE
11
-
12
- # IGinX-PyClient
13
-
14
- ## What is it?
15
-
16
- [IGinX (Intelligent enGine X)](https://github.com/IGinX-THU/IGinX) is an open source polystore system. A polystore system provides an integrated data management service over a set of one or more potentially heterogeneous database/storage engines, serving heterogeneous workloads.
17
-
18
- IGinX-PyClient is a Python interface library designed for IGinX, offering a convenient Session interface for users to effortlessly leverage the powerful features of IGinX within a Python environment. With this interface, users can perform database queries, manage data streams, and execute other operations supported by IGinX without leaving the Python ecosystem.
19
-
20
- ## Where to get?
21
-
22
- Python binary installers for the latest released version are available at the [Python package index](https://pypi.org/project/iginx-pyclient)
23
-
24
- ```bash
25
- pip install iginx-pyclient
26
- ```
27
-
28
- ## Dependencies
29
-
30
- - pandas(>=2.0.3)
31
-
32
- ## Example
33
-
34
- Please refer to code below:
35
-
36
- - [SQL example code](https://github.com/IGinX-THU/IGinX/blob/main/session_py/example.py)
37
- - [file operation example code](https://github.com/IGinX-THU/IGinX/blob/main/session_py/file_example.py)
38
-
1
+ Metadata-Version: 2.1
2
+ Name: iginx-pyclient
3
+ Version: 0.7.0
4
+ Summary: IGinX-PyClient
5
+ Author: THU IGinX
6
+ Author-email: TSIginX@gmail.com
7
+ License: Apache License 2.0
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+
12
+ # IGinX-PyClient
13
+
14
+ ## What is it?
15
+
16
+ [IGinX (Intelligent enGine X)](https://github.com/IGinX-THU/IGinX) is an open source polystore system. A polystore system provides an integrated data management service over a set of one or more potentially heterogeneous database/storage engines, serving heterogeneous workloads.
17
+
18
+ IGinX-PyClient is a Python interface library designed for IGinX, offering a convenient Session interface for users to effortlessly leverage the powerful features of IGinX within a Python environment. With this interface, users can perform database queries, manage data streams, and execute other operations supported by IGinX without leaving the Python ecosystem.
19
+
20
+ ## Where to get?
21
+
22
+ Python binary installers for the latest released version are available at the [Python package index](https://pypi.org/project/iginx-pyclient)
23
+
24
+ ```bash
25
+ pip install iginx-pyclient
26
+ ```
27
+
28
+ ## Dependencies
29
+
30
+ - pandas(>=2.0.3)
31
+
32
+ ## Example
33
+
34
+ Please refer to code below:
35
+
36
+ - [SQL example code](https://github.com/IGinX-THU/IGinX/blob/main/session_py/example.py)
37
+ - [file operation example code](https://github.com/IGinX-THU/IGinX/blob/main/session_py/file_example.py)
38
+
@@ -0,0 +1,19 @@
1
+ #
2
+ # IGinX - the polystore system with high performance
3
+ # Copyright (C) Tsinghua University
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ #
@@ -0,0 +1,68 @@
1
+ #
2
+ # IGinX - the polystore system with high performance
3
+ # Copyright (C) Tsinghua University
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ from .thrift.rpc.ttypes import StorageEngineType
20
+ class ClusterInfo(object):
21
+
22
+ def __init__(self, resp):
23
+ self.__iginx_list = resp.iginxInfos
24
+ self.__storage_engine_list = StorageEngineInfosWrapper(resp.storageEngineInfos)
25
+ self.__meta_storage_list = resp.metaStorageInfos
26
+ self.__local_meta_storage = resp.localMetaStorageInfo
27
+
28
+
29
+ def get_iginx_list(self):
30
+ return self.__iginx_list
31
+
32
+
33
+ def get_storage_engine_list(self):
34
+ return self.__storage_engine_list
35
+
36
+
37
+ def get_local_meta_storage(self):
38
+ return self.__local_meta_storage
39
+
40
+
41
+ def get_meta_storage_list(self):
42
+ return self.__meta_storage_list
43
+
44
+
45
+ def is_use_local_meta_storage(self):
46
+ return self.__local_meta_storage is not None
47
+
48
+
49
+ def __str__(self):
50
+ value = str(self.__iginx_list) + "\n" + str(self.__storage_engine_list) + "\n"
51
+ if self.__meta_storage_list:
52
+ value += str(self.__meta_storage_list)
53
+ else:
54
+ value += str(self.__local_meta_storage)
55
+ return value
56
+
57
+
58
+ class StorageEngineInfosWrapper:
59
+ def __init__(self, storage_engine_infos):
60
+ self.storage_engine_infos = storage_engine_infos
61
+
62
+ def __repr__(self):
63
+ res = []
64
+ for sei in self.storage_engine_infos:
65
+ L = ['%s=%r' % (key, value if key != "type" else StorageEngineType._VALUES_TO_NAMES.get(int(value)))
66
+ for key, value in sei.__dict__.items()]
67
+ res.append('%s(%s)' % (sei.__class__.__name__, ', '.join(L)))
68
+ return '[%s]' % (', '.join(res))
@@ -1,20 +1,21 @@
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
1
  #
9
- # http://www.apache.org/licenses/LICENSE-2.0
2
+ # IGinX - the polystore system with high performance
3
+ # Copyright (C) Tsinghua University
10
4
  #
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.
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
17
9
  #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
18
19
  from enum import Enum
19
20
 
20
21
  import pandas as pd
@@ -22,6 +23,84 @@ import pandas as pd
22
23
  from .thrift.rpc.ttypes import SqlType, AggregateType, ExecuteSqlResp
23
24
  from .utils.bitmap import Bitmap
24
25
  from .utils.byte_utils import get_long_array, get_values_by_data_type, BytesParser
26
+ from .thrift.rpc.ttypes import DataType
27
+
28
+ def map_dtype(dtype):
29
+ if pd.api.types.is_bool_dtype(dtype):
30
+ return DataType.BOOLEAN
31
+ elif pd.api.types.is_integer_dtype(dtype):
32
+ if dtype == 'int32':
33
+ return DataType.INTEGER
34
+ else:
35
+ return DataType.LONG
36
+ elif pd.api.types.is_float_dtype(dtype):
37
+ if dtype == 'float32':
38
+ return DataType.FLOAT
39
+ else:
40
+ return DataType.DOUBLE
41
+ elif pd.api.types.is_numeric_dtype(dtype):
42
+ return DataType.DOUBLE
43
+ else:
44
+ return DataType.BINARY # all other types are treated as BINARY
45
+
46
+ # TODO: process NA values
47
+ def column_dataset_from_df(df: pd.DataFrame, prefix: str = ""):
48
+ # if no prefix is provided, the column names must contain at least one '.' except key.
49
+ column_list = df.columns.tolist()
50
+ if prefix == "":
51
+ for col in column_list:
52
+ if '.' not in col and col != 'key':
53
+ raise RuntimeError(f"The paths in data must contain '.' or prefix must be set")
54
+ else:
55
+ prefix = prefix + '.'
56
+
57
+ if 'key' in column_list:
58
+ # examine key type
59
+ key_dtype = df['key'].dtype
60
+ valid_key = False
61
+ if key_dtype == 'int64':
62
+ valid_key = True
63
+ elif pd.api.types.is_integer_dtype(key_dtype):
64
+ df['key'] = df['key'].astype('int64')
65
+ valid_key = True
66
+
67
+ if not valid_key:
68
+ raise RuntimeError(f"Invalid key type is provided. Required long/int but was %s.", df['key'].dtype)
69
+ key_list = df['key'].tolist()
70
+ df = df.drop(columns=['key'])
71
+ # if there is no key column in data, creat one
72
+ else:
73
+ key_list = list(range(len(df)))
74
+
75
+ mapped_types = [map_dtype(dtype) for col, dtype in df.dtypes.items()]
76
+ values_list = [df[col].tolist() for col in df.columns]
77
+ column_list = [prefix + col for col in df.columns.tolist()]
78
+ return ColumnDataSet(column_list, mapped_types, key_list, values_list)
79
+
80
+
81
+ class ColumnDataSet(object):
82
+ def __init__(self, paths, types, keys, values_list):
83
+ self.__paths = paths
84
+ self.__types = types
85
+ self.__keys = keys
86
+ self.__values_list = values_list
87
+
88
+ def get_insert_args(self):
89
+ return self.__paths, self.__keys, self.__values_list, self.__types
90
+
91
+ def __str__(self):
92
+ column_names = ['key'] + self.__paths
93
+ num_rows = len(self.__keys)
94
+ columns = [self.__keys] + self.__values_list
95
+ output = []
96
+
97
+ output.append('\t'.join(column_names))
98
+
99
+ for i in range(num_rows):
100
+ row = [str(columns[j][i]) for j in range(len(columns))]
101
+ output.append('\t'.join(row))
102
+
103
+ return '\n'.join(output)
25
104
 
26
105
 
27
106
  class Point(object):
@@ -99,15 +178,20 @@ class QueryDataSet(object):
99
178
  return value
100
179
 
101
180
  def to_df(self):
102
- columns = ["key"]
181
+ has_key = self.__timestamps != []
182
+ columns = ["key"] if has_key else []
103
183
  for column in self.__paths:
104
184
  columns.append(str(column))
105
185
 
106
186
  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)
187
+ if has_key:
188
+ for i in range(len(self.__timestamps)):
189
+ value = [self.__timestamps[i]]
190
+ value.extend(self.__values[i])
191
+ value_matrix.append(value)
192
+ else:
193
+ for i in range(len(self.__values)):
194
+ value_matrix.append(self.__values[i])
111
195
 
112
196
  return pd.DataFrame(value_matrix, columns=columns)
113
197
 
@@ -244,11 +328,14 @@ class StatementExecuteDataSet(object):
244
328
  return None
245
329
 
246
330
  values_buffer = self.__values_list[self.__index]
331
+ bitmap_buffer = self.__bitmap_list[self.__index]
247
332
  self.__index += 1
248
- bytes_value = BytesParser(values_buffer).get_bytes_from_types(self.__types)
333
+
334
+ bitmap = Bitmap(len(self.__types), bitmap_buffer)
335
+ bytes_list = BytesParser(values_buffer).get_bytes_from_types(self.__types, bitmap)
249
336
  if remove_key:
250
- bytes_value = bytes_value[8:]
251
- return bytes_value
337
+ bytes_list = bytes_list[1:]
338
+ return bytes_list
252
339
 
253
340
  def close(self):
254
341
  self.__session._close_statement(query_id=self.__query_id)
@@ -1,31 +1,33 @@
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
1
  #
9
- # http://www.apache.org/licenses/LICENSE-2.0
2
+ # IGinX - the polystore system with high performance
3
+ # Copyright (C) Tsinghua University
10
4
  #
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.
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
17
9
  #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
18
19
  import csv
19
20
  import logging
20
21
  import os.path
21
22
  from datetime import datetime
22
23
 
24
+ import pandas as pd
23
25
  from thrift.protocol import TBinaryProtocol
24
26
  from thrift.transport import TSocket, TTransport
25
27
  from pathlib import Path
26
28
 
27
29
  from .cluster_info import ClusterInfo
28
- from .dataset import QueryDataSet, AggregateQueryDataSet, StatementExecuteDataSet
30
+ from .dataset import column_dataset_from_df, QueryDataSet, AggregateQueryDataSet, StatementExecuteDataSet
29
31
  from .thrift.rpc.IService import Client
30
32
  from .thrift.rpc.ttypes import (
31
33
  OpenSessionReq,
@@ -62,14 +64,19 @@ from .utils.byte_utils import timestamps_to_bytes, row_values_to_bytes, column_v
62
64
 
63
65
  logger = logging.getLogger("IginX")
64
66
 
67
+ # key value boundary for IGinX(defined in shared.GlobalConstant)
68
+ MAX_KEY = 9223372036854775807
69
+ MIN_KEY = -9223372036854775807
70
+
71
+
65
72
  def isPyReg(statement:str):
66
73
  statement = statement.strip().lower()
67
- return statement.startswith("register") and ("python task" in statement)
74
+ return statement.startswith("create") and ("function" in statement)
68
75
 
69
76
 
70
77
  def process_py_reg(statement:str):
71
- assert len(statement.split("\"")) == 7
72
- path = statement.split("\"")[3]
78
+ assert len(statement.split("\"")) >= 7
79
+ path = statement.split("\"")[-1]
73
80
  if os.path.isabs(path):
74
81
  return statement
75
82
  else:
@@ -400,6 +407,17 @@ class Session(object):
400
407
  status = self.__client.insertNonAlignedColumnRecords(req)
401
408
  Session.verify_status(status)
402
409
 
410
+ def insert_df(self, df: pd.DataFrame, prefix: str = ""):
411
+ """
412
+ insert dataframe data into IGinX
413
+ :param df: dataframe that contains data
414
+ :param prefix: (optional) path names in IGinX
415
+ must contain '.'. If columns in dataframe does not meet the requirement, a prefix can be used
416
+ """
417
+ dataset = column_dataset_from_df(df, prefix)
418
+ paths, keys, value_list, type_list = dataset.get_insert_args()
419
+ self.insert_column_records(paths, keys, value_list, type_list)
420
+
403
421
  def query(self, paths, start_time, end_time, timePrecision=None):
404
422
  req = QueryDataReq(sessionId=self.__session_id, paths=Session.merge_and_sort_paths(paths),
405
423
  startKey=start_time, endKey=end_time, timePrecision=timePrecision)
@@ -424,6 +442,10 @@ class Session(object):
424
442
  return QueryDataSet(paths, data_types, raw_data_set.keys, raw_data_set.valuesList,
425
443
  raw_data_set.bitmapList)
426
444
 
445
+ def downsample_query_no_interval(self, paths, type, precision, timePrecision=None):
446
+ return self.downsample_query(paths, MIN_KEY, MAX_KEY, type, precision, timePrecision)
447
+
448
+
427
449
  def downsample_query(self, paths, start_time, end_time, type, precision, timePrecision=None):
428
450
  req = DownsampleQueryReq(sessionId=self.__session_id, paths=paths, startKey=start_time, endKey=end_time,
429
451
  aggregateType=type,
@@ -624,7 +646,7 @@ class Session(object):
624
646
  with open(column, mode) as fos:
625
647
  for value in binary_data_list:
626
648
  # 写入对应列的数据
627
- fos.write(value)
649
+ fos.write(value[i-1])
628
650
  except IOError as e:
629
651
  raise RuntimeError(f"Encounter an error when writing file {column}, because {e}")
630
652
 
@@ -0,0 +1,18 @@
1
+ #
2
+ # IGinX - the polystore system with high performance
3
+ # Copyright (C) Tsinghua University
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+