Skip to content

Commit

Permalink
Fix json format (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiee authored Sep 28, 2021
1 parent 136f006 commit e5c719f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 44 deletions.
82 changes: 44 additions & 38 deletions nebula2/gclient/net/Session.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,52 +65,58 @@ def execute_json(self, stmt):
Date and Datetime will be returned in UTC
JSON struct:
{
"results":[
"results": [
{
"columns":[],
"data":[
"columns": [],
"data": [
{
"row":row-data,
"meta":metadata]
"row": [
"row-data"
],
"meta": [
"metadata"
]
}
],
"latencyInUs":0,
"spaceName":"",
"planDesc ":{
"planNodeDescs":[
{
"name":"",
"id":0,
"outputVar":"",
"description":{
"key":""
],
"latencyInUs": 0,
"spaceName": "",
"planDesc ": {
"planNodeDescs": [
{
"name": "",
"id": 0,
"outputVar": "",
"description": {
"key": ""
},
"profiles":[
{
"rows":1,
"execDurationInUs":0,
"totalDurationInUs":0,
"otherStats":{}
}
"profiles": [
{
"rows": 1,
"execDurationInUs": 0,
"totalDurationInUs": 0,
"otherStats": {}
}
],
"branchInfo":{
"isDoBranch":false,
"conditionNodeId":-1
"branchInfo": {
"isDoBranch": false,
"conditionNodeId": -1
},
"dependencies":[]
}
"dependencies": []
}
],
"nodeIndexMap":{},
"format":"",
"optimize_time_in_us":0
},
"comment ":"",
"errors":{
"errorCode":0,
"errorMsg":""
}
"nodeIndexMap": {},
"format": "",
"optimize_time_in_us": 0
},
"comment ": ""
}
],
"errors": [
{
"code": 0,
"message": ""
}
]
]
}
:param stmt: the ngql
Expand Down
19 changes: 13 additions & 6 deletions tests/test_data_from_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,19 @@ def test_path_type(self):

class TestExecuteJson(TestBaseCase):
def test_basic_types(self):
resp = self.session.execute_json('YIELD 1, 2.2, "hello", [1,2,"abc"], {key: "value"}, "汉字"')
exp = [1, 2.2, "hello", [1,2,"abc"], {"key": "value"}, "汉字"]
resp = self.session.execute_json(
'YIELD 1, 2.2, "hello", [1,2,"abc"], {key: "value"}, "汉字"')
exp = [1, 2.2, "hello", [1, 2, "abc"], {"key": "value"}, "汉字"]
json_obj = json.loads(resp)

# Get errorcode
resp_error_code = json_obj["errors"][0]["code"]
assert 0 == resp_error_code

# Get data
assert exp == json_obj["results"][0]["data"][0]["row"]

#Get space name
# Get space name
respSpace = json_obj["results"][0]["spaceName"]
assert "test_data" == respSpace

Expand Down Expand Up @@ -285,10 +292,10 @@ def test_error(self):

json_obj = json.loads(resp)

error_code = "E_SEMANTIC_ERROR"
resp_error_code = json_obj["results"][0]["errors"]["errorCode"]
error_code = -1009
resp_error_code = json_obj["errors"][0]["code"]
assert error_code == resp_error_code

error_msg = "SemanticError: `invalidTag': Unknown tag"
resp_error_msg = json_obj["results"][0]["errors"]["errorMsg"]
resp_error_msg = json_obj["errors"][0]["message"]
assert error_msg == resp_error_msg

0 comments on commit e5c719f

Please sign in to comment.