From 8a8c640914a3f12485bbf74d867ff75995eeaf8d Mon Sep 17 00:00:00 2001 From: Yichen Wang <18348405+Aiee@users.noreply.github.com> Date: Wed, 4 Jan 2023 15:42:19 +0800 Subject: [PATCH] Revert commented cases (#240) * Revert cases * Update comments --- client_test.go | 71 +++++++++++++-------------- connection.go | 9 ++-- session.go | 112 +++++++++++++++++++++--------------------- session_pool.go | 114 ++++++++++++++++++++++--------------------- session_pool_test.go | 2 +- value_wrapper.go | 8 +-- 6 files changed, 159 insertions(+), 157 deletions(-) diff --git a/client_test.go b/client_test.go index ce65f210..1b2546c1 100644 --- a/client_test.go +++ b/client_test.go @@ -1147,42 +1147,41 @@ func TestExecuteWithParameter(t *testing.T) { col3) } // Complex result - // FIXME(Aiee) uncomment this after https://github.com/vesoft-inc/nebula/issues/4877 is fixed - // { - // query := "MATCH (v:person {name: $p4.b}) WHERE v.person.age>$p2-3 and $p1==true RETURN v ORDER BY $p3[0] LIMIT $p2" - // resp, err := tryToExecuteWithParameter(session, query, params) - // if err != nil { - // t.Fatalf(err.Error()) - // return - // } - // checkResultSet(t, query, resp) - - // assert.Equal(t, 1, resp.GetRowSize()) - // record, err := resp.GetRowValuesByIndex(0) - // if err != nil { - // t.Fatalf(err.Error()) - // return - // } - // valWrap, err := record.GetValueByIndex(0) - // if err != nil { - // t.Fatalf(err.Error()) - // return - // } - // node, err := valWrap.AsNode() - // if err != nil { - // t.Fatalf(err.Error()) - // return - // } - // assert.Equal(t, - // "(\"Bob\" :student{interval: P1MT100.000020000S, name: \"Bob\"} "+ - // ":person{age: 10, birthday: 2010-09-10T10:08:02.000000, book_num: 100, "+ - // "child_name: \"Hello Worl\", expend: 100.0, "+ - // "first_out_city: 1111, friends: 10, grade: 3, "+ - // "hobby: __NULL__, is_girl: false, "+ - // "morning: 07:10:00.000000, name: \"Bob\", "+ - // "property: 1000.0, start_school: 2017-09-10})", - // node.String()) - // } + { + query := "MATCH (v:person {name: $p4.b}) WHERE v.person.age>$p2-3 and $p1==true RETURN v ORDER BY $p3[0] LIMIT $p2" + resp, err := tryToExecuteWithParameter(session, query, params) + if err != nil { + t.Fatalf(err.Error()) + return + } + checkResultSet(t, query, resp) + + assert.Equal(t, 1, resp.GetRowSize()) + record, err := resp.GetRowValuesByIndex(0) + if err != nil { + t.Fatalf(err.Error()) + return + } + valWrap, err := record.GetValueByIndex(0) + if err != nil { + t.Fatalf(err.Error()) + return + } + node, err := valWrap.AsNode() + if err != nil { + t.Fatalf(err.Error()) + return + } + assert.Equal(t, + "(\"Bob\" :student{interval: P1MT100.000020000S, name: \"Bob\"} "+ + ":person{age: 10, birthday: 2010-09-10T10:08:02.000000, book_num: 100, "+ + "child_name: \"Hello Worl\", expend: 100.0, "+ + "first_out_city: 1111, friends: 10, grade: 3, "+ + "hobby: __NULL__, is_girl: false, "+ + "morning: 07:10:00.000000, name: \"Bob\", "+ + "property: 1000.0, start_school: 2017-09-10})", + node.String()) + } } func TestReconnect(t *testing.T) { diff --git a/connection.go b/connection.go index bf09a6cd..8a6411b2 100644 --- a/connection.go +++ b/connection.go @@ -11,7 +11,6 @@ package nebula_go import ( "crypto/tls" "fmt" - "math" "net" "strconv" "time" @@ -47,7 +46,6 @@ func (cn *connection) open(hostAddress HostAddress, timeout time.Duration, sslCo newAdd := net.JoinHostPort(ip, strconv.Itoa(port)) cn.timeout = timeout bufferSize := 128 << 10 - frameMaxLength := uint32(math.MaxUint32) var err error var sock thrift.Transport @@ -60,10 +58,11 @@ func (cn *connection) open(hostAddress HostAddress, timeout time.Duration, sslCo return fmt.Errorf("failed to create a net.Conn-backed Transport,: %s", err.Error()) } - // Set transport buffer + // // Set transport bufferedTranFactory := thrift.NewBufferedTransportFactory(bufferSize) - transport := thrift.NewFramedTransportMaxLength(bufferedTranFactory.GetTransport(sock), frameMaxLength) - pf := thrift.NewBinaryProtocolFactoryDefault() + transport := thrift.NewHeaderTransport(bufferedTranFactory.GetTransport(sock)) + pf := thrift.NewHeaderProtocolFactory() + cn.graph = graph.NewGraphServiceClientFactory(transport, pf) if err = cn.graph.Open(); err != nil { return fmt.Errorf("failed to open transport, error: %s", err.Error()) diff --git a/session.go b/session.go index 2708aa94..3b611b2f 100644 --- a/session.go +++ b/session.go @@ -103,62 +103,64 @@ 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":{} -// } -// ], -// "branchInfo":{ -// "isDoBranch":false, -// "conditionNodeId":-1 -// }, -// "dependencies":[] -// } -// ], -// "nodeIndexMap":{}, -// "format":"", -// "optimize_time_in_us":0 -// }, -// "comment ":"" -// } -// ], -// "errors":[ -// { -// "code": 0, -// "message": "" -// } -// ] -// } +// +// { +// "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":[ +// { +// "code": 0, +// "message": "" +// } +// ] +// } func (session *Session) ExecuteJson(stmt string) ([]byte, error) { return session.ExecuteJsonWithParameter(stmt, map[string]interface{}{}) } diff --git a/session_pool.go b/session_pool.go index 37fa1c44..5883d77e 100644 --- a/session_pool.go +++ b/session_pool.go @@ -146,62 +146,64 @@ func (pool *SessionPool) ExecuteWithParameter(stmt string, params map[string]int // 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":{} -// } -// ], -// "branchInfo":{ -// "isDoBranch":false, -// "conditionNodeId":-1 -// }, -// "dependencies":[] -// } -// ], -// "nodeIndexMap":{}, -// "format":"", -// "optimize_time_in_us":0 -// }, -// "comment ":"" -// } -// ], -// "errors":[ -// { -// "code": 0, -// "message": "" -// } -// ] -// } +// +// { +// "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":[ +// { +// "code": 0, +// "message": "" +// } +// ] +// } func (pool *SessionPool) ExecuteJson(stmt string) ([]byte, error) { return pool.ExecuteJsonWithParameter(stmt, map[string]interface{}{}) } @@ -209,7 +211,7 @@ func (pool *SessionPool) ExecuteJson(stmt string) ([]byte, error) { // ExecuteJson returns the result of the given query as a json string // Date and Datetime will be returned in UTC // The result is a JSON string in the same format as ExecuteJson() -//TODO(Aiee) check the space name +// TODO(Aiee) check the space name func (pool *SessionPool) ExecuteJsonWithParameter(stmt string, params map[string]interface{}) ([]byte, error) { return nil, fmt.Errorf("not implemented") diff --git a/session_pool_test.go b/session_pool_test.go index cd4c5006..df38fa28 100644 --- a/session_pool_test.go +++ b/session_pool_test.go @@ -55,7 +55,7 @@ func TestSessionPoolBasic(t *testing.T) { prepareSpace("client_test") defer dropSpace("client_test") - hostAddress := HostAddress{Host: address, Port: port} + hostAddress := HostAddress{Host: address, Port: 3700} config, err := NewSessionPoolConf( "root", "nebula", diff --git a/value_wrapper.go b/value_wrapper.go index 74f09da8..069bd415 100644 --- a/value_wrapper.go +++ b/value_wrapper.go @@ -301,10 +301,10 @@ func (valWrap ValueWrapper) GetType() string { // // Maps in the output will be sorted by key value in alphabetical order. // -// For vetex, the output is in form (vid: tagName{propKey: propVal, propKey2, propVal2}), -// For edge, the output is in form (SrcVid)-[name]->(DstVid)@Ranking{prop1: val1, prop2: val2} -// where arrow direction depends on edgeType. -// For path, the output is in form (v1)-[name@edgeRanking]->(v2)-[name@edgeRanking]->(v3) +// For vetex, the output is in form (vid: tagName{propKey: propVal, propKey2, propVal2}), +// For edge, the output is in form (SrcVid)-[name]->(DstVid)@Ranking{prop1: val1, prop2: val2} +// where arrow direction depends on edgeType. +// For path, the output is in form (v1)-[name@edgeRanking]->(v2)-[name@edgeRanking]->(v3) // // For time, and dateTime, String returns the value calculated using the timezone offset // from graph service by default.