From e5c719fbc4c5b04b44c84f970c073800207f51bd Mon Sep 17 00:00:00 2001 From: Yichen Wang <18348405+Aiee@users.noreply.github.com> Date: Tue, 28 Sep 2021 19:07:03 +0800 Subject: [PATCH] Fix json format (#145) --- nebula2/gclient/net/Session.py | 82 ++++++++++++++++++---------------- tests/test_data_from_server.py | 19 +++++--- 2 files changed, 57 insertions(+), 44 deletions(-) diff --git a/nebula2/gclient/net/Session.py b/nebula2/gclient/net/Session.py index 95eaab25..16bd3095 100644 --- a/nebula2/gclient/net/Session.py +++ b/nebula2/gclient/net/Session.py @@ -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 diff --git a/tests/test_data_from_server.py b/tests/test_data_from_server.py index 3a172eee..87b82f5b 100644 --- a/tests/test_data_from_server.py +++ b/tests/test_data_from_server.py @@ -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 @@ -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