Skip to content

Commit

Permalink
Check client version.
Browse files Browse the repository at this point in the history
  • Loading branch information
CPWstatic committed Oct 11, 2021
1 parent f78992c commit 636a6a3
Show file tree
Hide file tree
Showing 28 changed files with 1,224 additions and 1,468 deletions.
23 changes: 2 additions & 21 deletions example/GraphClientSimpleExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from nebula2.gclient.net import ConnectionPool
from nebula2.Config import Config
from nebula2.common import *
from FormatResp import print_resp

if __name__ == '__main__':
Expand Down Expand Up @@ -45,36 +44,18 @@
assert resp.is_succeeded(), resp.error_msg()

# insert edges
resp = client.execute(
client.execute(
'INSERT EDGE like(likeness) VALUES "Bob"->"Lily":(80.0);')
assert resp.is_succeeded(), resp.error_msg()

resp = client.execute('FETCH PROP ON person "Bob"')
assert resp.is_succeeded(), resp.error_msg()
print_resp(resp)

bval = ttypes.Value()
bval.set_bVal(True)
ival = ttypes.Value()
ival.set_iVal(3)
sval = ttypes.Value()
sval.set_sVal("Cypher Parameter")
params={"p1":ival,"p2":bval,"p3":sval}

# test parameter interface
resp = client.execute_parameter('RETURN abs($p1)+3, toBoolean($p2) and false, toLower($p3)+1',params)
assert resp.is_succeeded(), resp.error_msg()
print_resp(resp)
# test compatibility
resp = client.execute('RETURN 3')
resp = client.execute('FETCH PROP ON like "Bob"->"Lily"')
assert resp.is_succeeded(), resp.error_msg()
print_resp(resp)

# get the result in json format
resp_json = client.execute_json_with_parameter("yield 1", params)
json_obj = json.loads(resp_json)
print(json.dumps(json_obj, indent=2, sort_keys=True))

# drop space
resp = client.execute('DROP SPACE test')
assert resp.is_succeeded(), resp.error_msg()
Expand Down
3 changes: 3 additions & 0 deletions nebula2/Exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ def __init__(self, code=E_UNKNOWN, message=None):
self.type = code
self.message = message

class ClientServerIncompatibleException(Exception):
def __init__(self, message):
Exception.__init__(self, f'Current client is not compatible with remote server: {message}')
4 changes: 3 additions & 1 deletion nebula2/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@



from .ttypes import UTF8STRINGS, NullType, ErrorCode, SchemaID, Date, Time, DateTime, Value, NList, NMap, NSet, Row, DataSet, Tag, Vertex, Edge, Step, Path, HostAddr, KeyValue, LogInfo, DirInfo, NodeInfo, PartitionBackupInfo, CheckpointInfo, GraphSpaceID, PartitionID, TagID, EdgeType, EdgeRanking, LogID, TermID, Timestamp, IndexID, Port, SessionID, ExecutionPlanID
from .ttypes import UTF8STRINGS, NullType, ErrorCode, SchemaID, Date, Time, DateTime, Value, NList, NMap, NSet, Row, DataSet, Geography, Tag, Vertex, Edge, Step, Path, HostAddr, KeyValue, LogInfo, DirInfo, NodeInfo, PartitionBackupInfo, CheckpointInfo, GraphSpaceID, PartitionID, TagID, EdgeType, EdgeRanking, LogID, TermID, Timestamp, IndexID, Port, SessionID, ExecutionPlanID

version = "2.6.0"

141 changes: 138 additions & 3 deletions nebula2/common/ttypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import pprint
import warnings
from nebula2.fbthrift import Thrift
from thrift import Thrift
from nebula2.fbthrift.transport import TTransport
from nebula2.fbthrift.protocol import TBinaryProtocol
from nebula2.fbthrift.protocol import TCompactProtocol
Expand All @@ -29,7 +29,7 @@
all_structs = []
UTF8STRINGS = bool(0) or sys.version_info.major >= 3

__all__ = ['UTF8STRINGS', 'NullType', 'ErrorCode', 'SchemaID', 'Date', 'Time', 'DateTime', 'Value', 'NList', 'NMap', 'NSet', 'Row', 'DataSet', 'Tag', 'Vertex', 'Edge', 'Step', 'Path', 'HostAddr', 'KeyValue', 'LogInfo', 'DirInfo', 'NodeInfo', 'PartitionBackupInfo', 'CheckpointInfo', 'GraphSpaceID', 'PartitionID', 'TagID', 'EdgeType', 'EdgeRanking', 'LogID', 'TermID', 'Timestamp', 'IndexID', 'Port', 'SessionID', 'ExecutionPlanID']
__all__ = ['UTF8STRINGS', 'NullType', 'ErrorCode', 'SchemaID', 'Date', 'Time', 'DateTime', 'Value', 'NList', 'NMap', 'NSet', 'Row', 'DataSet', 'Geography', 'Tag', 'Vertex', 'Edge', 'Step', 'Path', 'HostAddr', 'KeyValue', 'LogInfo', 'DirInfo', 'NodeInfo', 'PartitionBackupInfo', 'CheckpointInfo', 'GraphSpaceID', 'PartitionID', 'TagID', 'EdgeType', 'EdgeRanking', 'LogID', 'TermID', 'Timestamp', 'IndexID', 'Port', 'SessionID', 'ExecutionPlanID']

class NullType:
__NULL__ = 0
Expand Down Expand Up @@ -183,6 +183,7 @@ class ErrorCode:
E_OUTDATED_TERM = -3071
E_OUTDATED_EDGE = -3072
E_WRITE_WRITE_CONFLICT = -3073
E_CLIENT_SERVER_INCOMPATIBLE = -3061
E_UNKNOWN = -8000

_VALUES_TO_NAMES = {
Expand Down Expand Up @@ -305,6 +306,7 @@ class ErrorCode:
-3071: "E_OUTDATED_TERM",
-3072: "E_OUTDATED_EDGE",
-3073: "E_WRITE_WRITE_CONFLICT",
-3061: "E_CLIENT_SERVER_INCOMPATIBLE",
-8000: "E_UNKNOWN",
}

Expand Down Expand Up @@ -428,6 +430,7 @@ class ErrorCode:
"E_OUTDATED_TERM": -3071,
"E_OUTDATED_EDGE": -3072,
"E_WRITE_WRITE_CONFLICT": -3073,
"E_CLIENT_SERVER_INCOMPATIBLE": -3061,
"E_UNKNOWN": -8000,
}

Expand Down Expand Up @@ -936,6 +939,7 @@ class Value(object):
- mVal
- uVal
- gVal
- ggVal
"""

thrift_spec = None
Expand All @@ -957,6 +961,7 @@ class Value(object):
MVAL = 13
UVAL = 14
GVAL = 15
GGVAL = 16

@staticmethod
def isUnion():
Expand Down Expand Up @@ -1022,6 +1027,10 @@ def get_gVal(self):
assert self.field == 15
return self.value

def get_ggVal(self):
assert self.field == 16
return self.value

def set_nVal(self, value):
self.field = 1
self.value = value
Expand Down Expand Up @@ -1082,6 +1091,10 @@ def set_gVal(self, value):
self.field = 15
self.value = value

def set_ggVal(self, value):
self.field = 16
self.value = value

def getType(self):
return self.field

Expand Down Expand Up @@ -1148,6 +1161,10 @@ def __repr__(self):
padding = ' ' * 5
value = padding.join(value.splitlines(True))
member = '\n %s=%s' % ('gVal', value)
if self.field == 16:
padding = ' ' * 6
value = padding.join(value.splitlines(True))
member = '\n %s=%s' % ('ggVal', value)
return "%s(%s)" % (self.__class__.__name__, member)

def read(self, iprot):
Expand Down Expand Up @@ -1280,6 +1297,14 @@ def read(self, iprot):
self.set_gVal(gVal)
else:
iprot.skip(ftype)
elif fid == 16:
if ftype == TType.STRUCT:
ggVal = Geography()
ggVal.read(iprot)
assert self.field == 0 and self.value is None
self.set_ggVal(ggVal)
else:
iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
Expand Down Expand Up @@ -1368,6 +1393,11 @@ def write(self, oprot):
gVal = self.value
gVal.write(oprot)
oprot.writeFieldEnd()
if self.field == 16:
oprot.writeFieldBegin('ggVal', TType.STRUCT, 16)
ggVal = self.value
ggVal.write(oprot)
oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeUnionEnd()

Expand Down Expand Up @@ -1850,6 +1880,79 @@ def __ne__(self, other):
if not six.PY2:
__hash__ = object.__hash__

class Geography:
"""
Attributes:
- wkb
"""

thrift_spec = None
thrift_field_annotations = None
thrift_struct_annotations = None
__init__ = None
@staticmethod
def isUnion():
return False

def read(self, iprot):
if (isinstance(iprot, TBinaryProtocol.TBinaryProtocolAccelerated) or (isinstance(iprot, THeaderProtocol.THeaderProtocolAccelerate) and iprot.get_protocol_id() == THeaderProtocol.THeaderProtocol.T_BINARY_PROTOCOL)) and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastproto is not None:
fastproto.decode(self, iprot.trans, [self.__class__, self.thrift_spec, False], utf8strings=UTF8STRINGS, protoid=0)
return
if (isinstance(iprot, TCompactProtocol.TCompactProtocolAccelerated) or (isinstance(iprot, THeaderProtocol.THeaderProtocolAccelerate) and iprot.get_protocol_id() == THeaderProtocol.THeaderProtocol.T_COMPACT_PROTOCOL)) and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastproto is not None:
fastproto.decode(self, iprot.trans, [self.__class__, self.thrift_spec, False], utf8strings=UTF8STRINGS, protoid=2)
return
iprot.readStructBegin()
while True:
(fname, ftype, fid) = iprot.readFieldBegin()
if ftype == TType.STOP:
break
if fid == 1:
if ftype == TType.STRING:
self.wkb = iprot.readString().decode('utf-8') if UTF8STRINGS else iprot.readString()
else:
iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
iprot.readStructEnd()

def write(self, oprot):
if (isinstance(oprot, TBinaryProtocol.TBinaryProtocolAccelerated) or (isinstance(oprot, THeaderProtocol.THeaderProtocolAccelerate) and oprot.get_protocol_id() == THeaderProtocol.THeaderProtocol.T_BINARY_PROTOCOL)) and self.thrift_spec is not None and fastproto is not None:
oprot.trans.write(fastproto.encode(self, [self.__class__, self.thrift_spec, False], utf8strings=UTF8STRINGS, protoid=0))
return
if (isinstance(oprot, TCompactProtocol.TCompactProtocolAccelerated) or (isinstance(oprot, THeaderProtocol.THeaderProtocolAccelerate) and oprot.get_protocol_id() == THeaderProtocol.THeaderProtocol.T_COMPACT_PROTOCOL)) and self.thrift_spec is not None and fastproto is not None:
oprot.trans.write(fastproto.encode(self, [self.__class__, self.thrift_spec, False], utf8strings=UTF8STRINGS, protoid=2))
return
oprot.writeStructBegin('Geography')
if self.wkb != None:
oprot.writeFieldBegin('wkb', TType.STRING, 1)
oprot.writeString(self.wkb.encode('utf-8')) if UTF8STRINGS and not isinstance(self.wkb, bytes) else oprot.writeString(self.wkb)
oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()

def __repr__(self):
L = []
padding = ' ' * 4
if self.wkb is not None:
value = pprint.pformat(self.wkb, indent=0)
value = padding.join(value.splitlines(True))
L.append(' wkb=%s' % (value))
return "%s(%s)" % (self.__class__.__name__, "\n" + ",\n".join(L) if L else '')

def __eq__(self, other):
if not isinstance(other, self.__class__):
return False

return self.__dict__ == other.__dict__

def __ne__(self, other):
return not (self == other)

# Override the __hash__ function for Python3 - t10434117
if not six.PY2:
__hash__ = object.__hash__

class Tag:
"""
Attributes:
Expand Down Expand Up @@ -3262,6 +3365,7 @@ def DateTime__setstate__(self, state):
(13, TType.STRUCT, 'mVal', [NMap, NMap.thrift_spec, False], None, 2, ), # 13
(14, TType.STRUCT, 'uVal', [NSet, NSet.thrift_spec, False], None, 2, ), # 14
(15, TType.STRUCT, 'gVal', [DataSet, DataSet.thrift_spec, False], None, 2, ), # 15
(16, TType.STRUCT, 'ggVal', [Geography, Geography.thrift_spec, False], None, 2, ), # 16
)

Value.thrift_struct_annotations = {
Expand Down Expand Up @@ -3289,9 +3393,12 @@ def DateTime__setstate__(self, state):
15: {
"cpp.ref_type": "unique",
},
16: {
"cpp.ref_type": "unique",
},
}

def Value__init__(self, nVal=None, bVal=None, iVal=None, fVal=None, sVal=None, dVal=None, tVal=None, dtVal=None, vVal=None, eVal=None, pVal=None, lVal=None, mVal=None, uVal=None, gVal=None,):
def Value__init__(self, nVal=None, bVal=None, iVal=None, fVal=None, sVal=None, dVal=None, tVal=None, dtVal=None, vVal=None, eVal=None, pVal=None, lVal=None, mVal=None, uVal=None, gVal=None, ggVal=None,):
self.field = 0
self.value = None
if nVal is not None:
Expand Down Expand Up @@ -3354,6 +3461,10 @@ def Value__init__(self, nVal=None, bVal=None, iVal=None, fVal=None, sVal=None, d
assert self.field == 0 and self.value is None
self.field = 15
self.value = gVal
if ggVal is not None:
assert self.field == 0 and self.value is None
self.field = 16
self.value = ggVal

Value.__init__ = Value__init__

Expand Down Expand Up @@ -3480,6 +3591,30 @@ def DataSet__setstate__(self, state):
DataSet.__getstate__ = lambda self: self.__dict__.copy()
DataSet.__setstate__ = DataSet__setstate__

all_structs.append(Geography)
Geography.thrift_spec = (
None, # 0
(1, TType.STRING, 'wkb', True, None, 2, ), # 1
)

Geography.thrift_struct_annotations = {
"cpp.type": "nebula::Geography",
}
Geography.thrift_field_annotations = {
}

def Geography__init__(self, wkb=None,):
self.wkb = wkb

Geography.__init__ = Geography__init__

def Geography__setstate__(self, state):
state.setdefault('wkb', None)
self.__dict__ = state

Geography.__getstate__ = lambda self: self.__dict__.copy()
Geography.__setstate__ = Geography__setstate__

all_structs.append(Tag)
Tag.thrift_spec = (
None, # 0
Expand Down
4 changes: 2 additions & 2 deletions nebula2/fbthrift/server/TAsyncioServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ async def ThriftAsyncServerFactory(
ssl is an instance of ssl.SSLContext. If None (default) or False SSL/TLS is
not used.
event_handler must be a subclass of nebula2.fbthrift.server.TServer. If None,
nebula2.fbthrift.server.TServer.TServerEventHandler is used. Specify a custom handler
event_handler must be a subclass of thrift.server.TServer. If None,
thrift.server.TServer.TServerEventHandler is used. Specify a custom handler
for custom event handling (e.g. handling new connections)
protocol_factory is a function that takes a triplet of
Expand Down
2 changes: 1 addition & 1 deletion nebula2/fbthrift/util/TValidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from nebula2.fbthrift.Thrift import TType

import logging
_log = logging.getLogger('nebula2.fbthrift.validator')
_log = logging.getLogger('thrift.validator')

import sys
if sys.version_info[0] >= 3:
Expand Down
Loading

0 comments on commit 636a6a3

Please sign in to comment.