PyStellarDB 0.10.0__py2.py3-none-any.whl → 0.13.1__py2.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.
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2014 Transwarp, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -1,38 +1,34 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyStellarDB
3
- Version: 0.10.0
3
+ Version: 0.13.1
4
4
  Summary: Python interface to StellarDB
5
5
  Home-page: https://github.com/WarpCloud/PyStellarDB
6
6
  Author: Zhiping Wang
7
7
  Author-email: zhiping.wang@transwarp.io
8
8
  License: Apache License, Version 2.0
9
- Platform: UNKNOWN
10
9
  Classifier: Intended Audience :: Developers
11
10
  Classifier: License :: OSI Approved :: Apache Software License
12
11
  Classifier: Operating System :: OS Independent
13
12
  Classifier: Topic :: Database :: Front-Ends
14
- Requires-Python: >=2.7,<=3.7
15
- Provides-Extra: kerberos
16
- Provides-Extra: hive
17
- Provides-Extra: sqlalchemy
18
- Provides-Extra: presto
13
+ Requires-Python: >=2.7
14
+ License-File: LICENSE
19
15
  Requires-Dist: future
20
16
  Requires-Dist: python-dateutil
21
17
  Requires-Dist: pyhive
22
18
  Requires-Dist: sasl
23
19
  Requires-Dist: thrift
24
- Requires-Dist: thrift-sasl
25
- Requires-Dist: pyspark (>=2.4.0)
20
+ Requires-Dist: thrift-sasl >=0.3.0
26
21
  Provides-Extra: hive
27
- Requires-Dist: sasl (>=0.2.1); extra == 'hive'
28
- Requires-Dist: thrift (>=0.10.0); extra == 'hive'
29
- Requires-Dist: thrift-sasl (>=0.1.0); extra == 'hive'
22
+ Requires-Dist: sasl >=0.2.1 ; extra == 'hive'
23
+ Requires-Dist: thrift >=0.10.0 ; extra == 'hive'
30
24
  Provides-Extra: kerberos
31
- Requires-Dist: requests-kerberos (>=0.12.0); extra == 'kerberos'
25
+ Requires-Dist: requests-kerberos >=0.12.0 ; extra == 'kerberos'
32
26
  Provides-Extra: presto
33
- Requires-Dist: requests (>=1.0.0); extra == 'presto'
27
+ Requires-Dist: requests >=1.0.0 ; extra == 'presto'
28
+ Provides-Extra: pyspark
29
+ Requires-Dist: pyspark >=2.4.0 ; extra == 'pyspark'
34
30
  Provides-Extra: sqlalchemy
35
- Requires-Dist: sqlalchemy (>=1.3.0); extra == 'sqlalchemy'
31
+ Requires-Dist: sqlalchemy >=1.3.0 ; extra == 'sqlalchemy'
36
32
 
37
33
  PyStellarDB
38
34
  ===========
@@ -129,7 +125,7 @@ Execute Graph Query and change to a PySpark RDD object
129
125
 
130
126
  from pyspark import SparkContext
131
127
  from pystellardb import stellar_hive
132
-
128
+
133
129
  sc = SparkContext("local", "Demo App")
134
130
 
135
131
  conn = stellar_hive.StellarConnection(host="localhost", port=10000, graph_name='pokemon')
@@ -154,7 +150,7 @@ Execute Hive Query and change to a PySpark RDD object
154
150
 
155
151
  from pyspark import SparkContext
156
152
  from pystellardb import stellar_hive
157
-
153
+
158
154
  sc = SparkContext("local", "Demo App")
159
155
 
160
156
  conn = stellar_hive.StellarConnection(host="localhost", port=10000)
@@ -175,15 +171,11 @@ Dependencies
175
171
  Required:
176
172
  ------------
177
173
 
178
- - Python 2.7+ / Less than Python 3.7
174
+ - Python 2.7+ / Python 3
179
175
 
180
176
  System SASL
181
177
  ------------
182
178
 
183
- Different systems require different packages to be installed to enable SASL support
184
- in Impyla. Some examples of how to install the packages on different distributions
185
- follow.
186
-
187
179
  Ubuntu:
188
180
 
189
181
  .. code-block:: bash
@@ -198,14 +190,14 @@ RHEL/CentOS:
198
190
  yum install cyrus-sasl-md5 cyrus-sasl-plain cyrus-sasl-gssapi cyrus-sasl-devel
199
191
  yum install gcc-c++ python-devel.x86_64 #Update python and gcc if needed
200
192
 
201
- # If your Python environment is 3.X, then you may need to compile and reinstall Python
202
193
  # if pip3 install fails with a message like 'Can't connect to HTTPS URL because the SSL module is not available'
194
+ # you may need to update ssl & reinstall python
203
195
 
204
196
  # 1. Download a higher version of openssl, e.g: https://www.openssl.org/source/openssl-1.1.1k.tar.gz
205
197
  # 2. Install openssl: ./config && make && make install
206
198
  # 3. Link openssl: echo /usr/local/lib64/ > /etc/ld.so.conf.d/openssl-1.1.1.conf
207
199
  # 4. Update dynamic lib: ldconfig -v
208
- # 5. Download a Python source package
200
+ # 5. Uninstall Python & Download a new Python source package
209
201
  # 6. vim Modules/Setup, search '_socket socketmodule.c', uncomment
210
202
  # _socket socketmodule.c
211
203
  # SSL=/usr/local/ssl
@@ -215,11 +207,19 @@ RHEL/CentOS:
215
207
  #
216
208
  # 7. Install Python: ./configure && make && make install
217
209
 
210
+ Windows:
211
+
212
+ .. code-block:: bash
213
+
214
+ # There are 3 ways of installing sasl for python on windows
215
+ # 1. (recommended) Download a .whl version of sasl from https://www.lfd.uci.edu/~gohlke/pythonlibs/#sasl
216
+ # 2. (recommended) If using anaconda, use conda install sasl.
217
+ # 3. Install Microsoft Visual C++ 9.0/14.0 buildtools for python2.7/3.x, then pip install sasl.
218
+
218
219
  Notices
219
220
  =======
220
221
 
221
- If you install pystellardb >= 0.9, then it will install a beeline command into system.
222
- Delete /usr/local/bin/beeline if you don't need it.
222
+ Pystellardb >= 0.9 contains beeline installation to /usr/local/bin/beeline.
223
223
 
224
224
  Requirements
225
225
  ============
@@ -233,8 +233,83 @@ PyHive works with
233
233
  - For Hive: `HiveServer2 <https://cwiki.apache.org/confluence/display/Hive/Setting+up+HiveServer2>`_ daemon
234
234
 
235
235
 
236
+ Windows Kerberos Configuration
237
+ ==============================
238
+
239
+ Windows Kerberos configuration can be a little bit tricky and may need a few instructions.
240
+ First, you'll need to install & configure Kerberos for Windows.
241
+ Get it from http://web.mit.edu/kerberos/dist/
242
+
243
+ After installation, configure the environment variables.
244
+ Make sure the position of your Kerberos variable is ahead of JDK variable, avoid using kinit command located in JDK path.
245
+
246
+ Find /etc/krb5.conf on your KDC, copy it into krb5.ini on Windows with some modifications.
247
+ e.g.(krb5.conf on KDC):
248
+
249
+ .. code-block:: bash
250
+
251
+ [logging]
252
+ default = FILE:/var/log/krb5libs.log
253
+ kdc = FILE:/var/log/krb5kdc.log
254
+ admin_server = FILE:/var/log/kadmind.log
255
+
256
+ [libdefaults]
257
+ default_realm = DEFAULT
258
+ dns_lookup_realm = false
259
+ dns_lookup_kdc = false
260
+ ticket_lifetime = 24h
261
+ renew_lifetime = 7d
262
+ forwardable = true
263
+ allow_weak_crypto = true
264
+ udp_preference_limit = 32700
265
+ default_ccache_name = FILE:/tmp/krb5cc_%{uid}
266
+
267
+ [realms]
268
+ DEFAULT = {
269
+ kdc = host1:1088
270
+ kdc = host2:1088
271
+ }
272
+
273
+ Modify it, delete [logging] and default_ccache_name in [libdefaults]:
274
+
275
+ .. code-block:: bash
276
+
277
+ [libdefaults]
278
+ default_realm = DEFAULT
279
+ dns_lookup_realm = false
280
+ dns_lookup_kdc = false
281
+ ticket_lifetime = 24h
282
+ renew_lifetime = 7d
283
+ forwardable = true
284
+ allow_weak_crypto = true
285
+ udp_preference_limit = 32700
286
+
287
+ [realms]
288
+ DEFAULT = {
289
+ kdc = host1:1088
290
+ kdc = host2:1088
291
+ }
292
+
293
+ Above is your krb5.ini for Kerberos on Windows. Put it at 3 places:
294
+
295
+ C:\ProgramData\MIT\Kerberos5\krb5.ini
296
+
297
+ C:\Program Files\MIT\Kerberos\krb5.ini
298
+
299
+ C:\Windows\krb5.ini
300
+
301
+
302
+ Finally, configure hosts file at: C:/Windows/System32/drivers/etc/hosts
303
+ Add ip mappings of host1, host2 in the previous example. e.g.
304
+
305
+ .. code-block:: bash
306
+
307
+ 10.6.6.96 host1
308
+ 10.6.6.97 host2
309
+
310
+ Now, you can try running kinit in your command line!
311
+
236
312
  Testing
237
313
  =======
238
314
 
239
315
  On his way
240
-
@@ -0,0 +1,10 @@
1
+ pystellardb/__init__.py,sha256=JOl41NviMN-qDV0Z8ZPmhNIxvgyauGGJHdB4A-8MhqM,93
2
+ pystellardb/_version.py,sha256=Enm9C1OfbLkTuBMZ_UZNpU-dIdr1fSxOb6XVICKMawU,498
3
+ pystellardb/graph_types.py,sha256=S8XIRwKP2-DLbOpgUHXzbs68SHFZeydlKs7h4jVcdIg,12351
4
+ pystellardb/stellar_hive.py,sha256=Bes99go4oKszP0RiD3OYG3W5g0Sx0cnaXf2yWOosXk0,14010
5
+ pystellardb/stellar_rdd.py,sha256=TYwsWYeCxfOliGq1kV3ArNXdye55cKWZF7s9M9nDdt4,1324
6
+ PyStellarDB-0.13.1.dist-info/LICENSE,sha256=1qDFxrywejs7xNBfOr6T-7lOuqDgSNIES77kTYege3w,560
7
+ PyStellarDB-0.13.1.dist-info/METADATA,sha256=1ZD8HOiC_gp2E3mMcyQVDdJynVWar6EANpDALj52V1w,9390
8
+ PyStellarDB-0.13.1.dist-info/WHEEL,sha256=_4XEmVmaBFWtekSGrbfOGNjC2I5lUr0lZSRblBllIFA,109
9
+ PyStellarDB-0.13.1.dist-info/top_level.txt,sha256=DRk-SeGVCdVAzv2CwFmdu75Yo7DgjUA3Hpu-9l8qPuU,12
10
+ PyStellarDB-0.13.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.31.1)
2
+ Generator: setuptools (70.1.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2-none-any
5
5
  Tag: py3-none-any
pystellardb/_version.py CHANGED
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2021-05-27T19:02:40+0800",
11
+ "date": "2024-08-20T10:49:46+0800",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "43719bd5c27d93c6809c68f12f87e8a6b4e94dc1",
15
- "version": "0.10.0"
14
+ "full-revisionid": "b83cfb5780b16466ce79235a756422bb00844b1b",
15
+ "version": "0.13.1"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
@@ -69,7 +69,7 @@ class Vertex(GraphElement):
69
69
  return m
70
70
 
71
71
  def __str__(self):
72
- return json.dumps(self.toJSON())
72
+ return json.dumps(self.toJSON(), ensure_ascii=False)
73
73
 
74
74
  @staticmethod
75
75
  def parseVertexFromJson(json_str):
@@ -84,23 +84,26 @@ class Vertex(GraphElement):
84
84
  if 'labels' not in m:
85
85
  raise ValueError("Could not find label in JSON")
86
86
 
87
- if '__uid' not in m['properties']:
87
+ prop_dict = m['properties']
88
+
89
+ if '__uid' not in prop_dict:
88
90
  raise ValueError("Could not find uid in JSON")
89
91
 
90
- vertex = Vertex(m['properties']['__uid'], m['labels'][0])
92
+ vertex = Vertex(prop_dict['__uid'], m['labels'][0])
91
93
 
92
- for key in m['properties'].keys():
94
+ for key in prop_dict.keys():
93
95
  if key != '__uid' and key != '__tags':
94
- vertex.setFeild(key, m['properties'][key])
96
+ vertex.setFeild(key, prop_dict[key])
95
97
 
96
- vertex.setTags(m['properties']['__tags'])
98
+ if '__tags' in prop_dict:
99
+ vertex.setTags(prop_dict['__tags'])
97
100
 
98
101
  return vertex
99
102
 
100
103
  @staticmethod
101
104
  def parseUidFromRK(rk):
102
105
  """Parse user-defined id from vertex row key in byte array"""
103
- return ''.join([chr(x) for x in rk[:-2]])
106
+ return bytearray([x & 0xFF for x in rk[:-2]]).decode('utf-8')
104
107
 
105
108
  @staticmethod
106
109
  def parseLabelIdxFromRK(rk):
@@ -110,6 +113,31 @@ class Vertex(GraphElement):
110
113
  label_in_little_endian.reverse()
111
114
  return int(binascii.hexlify(bytearray(label_in_little_endian)), 16)
112
115
 
116
+ @staticmethod
117
+ def parseShardIdFromRKV18(rk):
118
+ """Parse shard id from vertex row key in byte array for graphSchema V18"""
119
+ shard_id = (rk[0] & 0xFF) << 8
120
+ shard_id |= rk[1] & 0xF0
121
+ return int(shard_id >> 4)
122
+
123
+ @staticmethod
124
+ def parseLabelIdxFromRKV18(rk):
125
+ """Parse label index from vertex row key in byte array for graphSchema V18"""
126
+ label_index = (rk[1] & 0x0F) << 8
127
+ label_index |= rk[2] & 0xFF
128
+ return int(label_index)
129
+
130
+ @staticmethod
131
+ def parseInnerIdFromRKV18(rk, offset):
132
+ """Parse long type inner id from vertex row key in byte array for graphSchema V18"""
133
+ ID_LEN = 8
134
+ inner_id = rk[offset + ID_LEN - 1] & 0x00FF
135
+ inner_id |= (rk[offset + ID_LEN - 2] & 0x00FF) << 8
136
+ inner_id |= (rk[offset + ID_LEN - 3] & 0x00FF) << 16
137
+ inner_id |= (rk[offset + ID_LEN - 4] & 0x00FF) << 24
138
+ inner_id |= (rk[offset + ID_LEN - 5] & 0x00FF) << 32
139
+ return int(inner_id)
140
+
113
141
 
114
142
  class Edge(GraphElement):
115
143
  """
@@ -159,7 +187,7 @@ class Edge(GraphElement):
159
187
  return m
160
188
 
161
189
  def __str__(self):
162
- return json.dumps(self.toJSON())
190
+ return json.dumps(self.toJSON(), ensure_ascii=False)
163
191
 
164
192
  @staticmethod
165
193
  def parseEdgeFromJson(schema, json_str):
@@ -176,12 +204,18 @@ class Edge(GraphElement):
176
204
 
177
205
  edge = Edge(m['labels'][0])
178
206
 
207
+ prop_dict = m['properties']
208
+
179
209
  # parse start node
180
210
  if 'startKey' not in m:
181
211
  raise ValueError("Could not find start node entity key in JSON")
182
212
 
183
- startUid = Vertex.parseUidFromRK(m['startKey'])
184
- startLabelIdx = Vertex.parseLabelIdxFromRK(m['startKey'])
213
+ if schema.getVersion() == 18:
214
+ startUid = prop_dict['__srcuid']
215
+ startLabelIdx = Vertex.parseLabelIdxFromRKV18(m['startKey'])
216
+ else:
217
+ startUid = Vertex.parseUidFromRK(m['startKey'])
218
+ startLabelIdx = Vertex.parseLabelIdxFromRK(m['startKey'])
185
219
  startLabel = schema.getVertexLabel(startLabelIdx)
186
220
 
187
221
  if startLabel is None:
@@ -195,8 +229,12 @@ class Edge(GraphElement):
195
229
  if 'endKey' not in m:
196
230
  raise ValueError("Could not find end node entity key in JSON")
197
231
 
198
- endUid = Vertex.parseUidFromRK(m['endKey'])
199
- endLabelIdx = Vertex.parseLabelIdxFromRK(m['endKey'])
232
+ if schema.getVersion() == 18:
233
+ endUid = prop_dict['__dstuid']
234
+ endLabelIdx = Vertex.parseLabelIdxFromRKV18(m['endKey'])
235
+ else:
236
+ endUid = Vertex.parseUidFromRK(m['endKey'])
237
+ endLabelIdx = Vertex.parseLabelIdxFromRK(m['endKey'])
200
238
  endLabel = schema.getVertexLabel(endLabelIdx)
201
239
 
202
240
  if endLabel is None:
@@ -207,16 +245,17 @@ class Edge(GraphElement):
207
245
  edge.setEndNode(Vertex(endUid, endLabel))
208
246
 
209
247
  # parse extra edge id
210
- if '__uid' in m['properties']:
211
- edge.setUid(m['properties']['__uid'])
248
+ if '__uid' in prop_dict:
249
+ edge.setUid(prop_dict['__uid'])
212
250
 
213
251
  # parse properties
214
- for key in m['properties'].keys():
252
+ for key in prop_dict.keys():
215
253
  if key != '__uid' and key != '__tags':
216
254
  edge.setFeild(key, m['properties'][key])
217
255
 
218
256
  # parse tags
219
- edge.setTags(m['properties']['__tags'])
257
+ if '__tags' in prop_dict:
258
+ edge.setTags(prop_dict['__tags'])
220
259
 
221
260
  return edge
222
261
 
@@ -298,6 +337,9 @@ class GraphSchema(object):
298
337
 
299
338
  return None
300
339
 
340
+ def getVersion(self):
341
+ return self._schema_version
342
+
301
343
  def toJSON(self):
302
344
  m = {
303
345
  '__VERSION': self._schema_version,
@@ -320,7 +362,7 @@ class GraphSchema(object):
320
362
  return m
321
363
 
322
364
  def __str__(self):
323
- return json.dumps(self.toJSON())
365
+ return json.dumps(self.toJSON(), ensure_ascii=False)
324
366
 
325
367
  @staticmethod
326
368
  def parseSchemaFromJson(json_str):
@@ -175,6 +175,7 @@ class StellarConnection(object):
175
175
  assert response.serverProtocolVersion == protocol_version, \
176
176
  "Unable to handle protocol version {}".format(response.serverProtocolVersion)
177
177
  with contextlib.closing(self.cursor()) as cursor:
178
+ cursor.execute('set query.lang=sql')
178
179
  cursor.execute('USE `{}`'.format(database))
179
180
  except:
180
181
  self._transport.close()
@@ -304,7 +305,7 @@ class StellarCursor(hive.Cursor):
304
305
  elif type == 'int':
305
306
  return int(data)
306
307
  elif type == 'long':
307
- return long(data)
308
+ return int(data)
308
309
  elif type == 'float' or type == 'double':
309
310
  return float(data)
310
311
  elif type == 'CruxType:Node' or type == 'GraphNode':
@@ -323,9 +324,9 @@ class StellarCursor(hive.Cursor):
323
324
  def _parseList(self, type, data):
324
325
  """Parse 'CruxType:List' type"""
325
326
  parsed_data = json.loads(data)
326
- newType = type[len('CruxType:List') + 1:-2]
327
+ newType = type[len('CruxType:List') + 1:type.find('>')]
327
328
 
328
- return [self._convertData(newType, entry) for entry in parsed_data]
329
+ return [self._convertData(newType, json.dumps(entry)) for entry in parsed_data]
329
330
 
330
331
  def _parseMap(self, type, data):
331
332
  """Parse 'CruxType:Map' type"""
@@ -6,8 +6,13 @@ from __future__ import absolute_import
6
6
  import abc
7
7
  from future.utils import with_metaclass
8
8
  import logging
9
- from pyspark import RDD, SparkContext
10
- from pyspark.serializers import BatchedSerializer
9
+
10
+ try:
11
+ import pyspark
12
+ from pyspark import RDD, SparkContext
13
+ from pyspark.serializers import BatchedSerializer
14
+ except ImportError:
15
+ pyspark = None
11
16
 
12
17
  _logger = logging.getLogger(__name__)
13
18
 
@@ -20,6 +25,9 @@ def transformToRDD(cursor, sc, parallelism=1):
20
25
  param sc: SparkContext
21
26
  param parallelism: Parallelism of RDD
22
27
  """
28
+ if not pyspark:
29
+ raise ImportError("Could not import pyspark! Please run `pip install pyspark` first in your environment!")
30
+
23
31
  # Get all data from cursor
24
32
  data = cursor.fetchall()
25
33
 
@@ -1,9 +0,0 @@
1
- PyStellarDB-0.10.0.dist-info/METADATA,sha256=a56Ql_hi8Qs7um-EJ09SdQNN-g7m9tF8Ts-UE-vET_c,7449
2
- PyStellarDB-0.10.0.dist-info/RECORD,,
3
- PyStellarDB-0.10.0.dist-info/WHEEL,sha256=gduuPyBvFJQSQ0zdyxF7k0zynDXbIbvg5ZBHoXum5uk,110
4
- PyStellarDB-0.10.0.dist-info/top_level.txt,sha256=DRk-SeGVCdVAzv2CwFmdu75Yo7DgjUA3Hpu-9l8qPuU,12
5
- pystellardb/__init__.py,sha256=JOl41NviMN-qDV0Z8ZPmhNIxvgyauGGJHdB4A-8MhqM,93
6
- pystellardb/_version.py,sha256=D2S0_MWfM10J4kvlKlKQ5Bxc8TtsWanAaDppYEAl_G4,498
7
- pystellardb/graph_types.py,sha256=-zMzW2V2egpuDUSiIuD-JZpehkzvqljOLOM8aqaspFc,10770
8
- pystellardb/stellar_hive.py,sha256=jJxwKXTdmdPMoi6b61LghXZX3B6cX9-a5UinVsUbpEA,13930
9
- pystellardb/stellar_rdd.py,sha256=IQjK0WDO2FaIERqT-cwkRFcoqCgwCpBZXGlcYEcdALI,1116