Skip to content

Commit

Permalink
Re-format JSON format and add test for Chinses character
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiee committed Sep 24, 2021
1 parent d0ebbdd commit 6826c78
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 42 deletions.
5 changes: 3 additions & 2 deletions client_test.go
Expand Up @@ -896,15 +896,16 @@ func TestExecuteJson(t *testing.T) {

// Simple query
{
jsonStrResult, err := session.ExecuteJson(`YIELD 1, 2.2, "hello", [1,2,"abc"], {key: "value"}`)
jsonStrResult, err := session.ExecuteJson(`YIELD 1, 2.2, "hello", [1,2,"abc"], {key: "value"}, "汉字"`)
if err != nil {
t.Fatalf("fail to get the result in json format, %s", err.Error())
}
var jsonObj map[string]interface{}
exp := []interface{}{
float64(1), float64(2.2), "hello",
[]interface{}{float64(1), float64(2), "abc"},
map[string]interface{}{"key": "value"}}
map[string]interface{}{"key": "value"},
"汉字"}

// Parse JSON
// Get data
Expand Down
89 changes: 49 additions & 40 deletions session.go
Expand Up @@ -71,46 +71,55 @@ func (session *Session) Execute(stmt string) (*ResultSet, error) {

// ExecuteJson returns the result of the given query as a json string
// Date and Datetime will be returned in UTC
// JSON struct:
// "results": [
// {
// "columns": [],
// "data": [
// {
// "row": [ row-data ],
// "meta": [ metadata ]
// },
// ],
// "latencyInUs" : 0,
// "spaceName": "",
// "planDesc ": {
// "planNodeDescs": [ {
// "name" : "",
// "id" : 0,
// "outputVar" : "",
// "description" : {"key" : ""},
// "profiles" : [{
// "rows" : 1,
// "execDurationInUs" : 0,
// "totalDurationInUs" : 0,
// "otherStats" : {}, // map
// }],
// "branchInfo" : {
// "isDoBranch" : false,
// "conditionNodeId" : -1,
// },
// "dependencies" : [] // vector of ints
// }
// ],
// "nodeIndexMap" : {},
// "format" : "",
// "optimize_time_in_us" : 0,
// },
// "comment ": "",
// "errors" : "" // errorMsg
// }
// ]
// }]
// JSON struct:
// {
// "results":[
// {
// "columns":[],
// "data":[
// {
// "row":row-data,
// "meta":metadata]
// }
// ],
// "latencyInUs":0,
// "spaceName":"",
// "planDesc ":{
// "planNodeDescs":[
// {
// "name":"",
// "id":0,
// "outputVar":"",
// "description":{
// "key":""
// },
// "profiles":[
// {
// "rows":1,
// "execDurationInUs":0,
// "totalDurationInUs":0,
// "otherStats":{}
// }
// ],
// "branchInfo":{
// "isDoBranch":false,
// "conditionNodeId":-1
// },
// "dependencies":[]
// }
// ],
// "nodeIndexMap":{},
// "format":"",
// "optimize_time_in_us":0
// },
// "comment ":"",
// "errors":{
// "errorCode":0,
// "errorMsg":""
// }
// }
// ]
// }
func (session *Session) ExecuteJson(stmt string) ([]byte, error) {
if session.connection == nil {
return nil, fmt.Errorf("failed to execute: Session has been released")
Expand Down

0 comments on commit 6826c78

Please sign in to comment.