From aa4531a34edb4f432532c614c078f47ea0a258b2 Mon Sep 17 00:00:00 2001 From: Nut He <18328704+hetao92@users.noreply.github.com> Date: Thu, 6 Jan 2022 11:29:20 +0800 Subject: [PATCH] mod: update cypher parameter (#75) --- go.mod | 2 +- go.sum | 2 + service/pool/pool.go | 89 +------------------------------------------- 3 files changed, 4 insertions(+), 89 deletions(-) diff --git a/go.mod b/go.mod index 5370871..cdae5e0 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/prometheus/client_golang v1.9.0 // indirect github.com/satori/go.uuid v1.2.0 github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect - github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211229125609-91a3d1eac8b5 + github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20220106021349-6ef61ed6077f github.com/vesoft-inc/nebula-importer v1.0.1-0.20211213064541-05a8646be295 golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect diff --git a/go.sum b/go.sum index 6f66f73..dae20ac 100644 --- a/go.sum +++ b/go.sum @@ -325,6 +325,8 @@ github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211221081231-40030d441885 h1:mf9MR github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211221081231-40030d441885/go.mod h1:fehDUs97/mpmxXi9WezhznX0Dg7hmQRUoOWgDZv9zG0= github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211229125609-91a3d1eac8b5 h1:DMshLSon/oU1y3IealRdJ605QzrZjqQ5HIivYA97yM4= github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211229125609-91a3d1eac8b5/go.mod h1:YRIuog6zyRKz0SagwwTcqHXCPjJ4GfQelIl+/FgSC+Y= +github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20220106021349-6ef61ed6077f h1:3hUyg8U8FCYqDKsGr5LfIGr97l6KDVtLbY5XJF+oKq0= +github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20220106021349-6ef61ed6077f/go.mod h1:YRIuog6zyRKz0SagwwTcqHXCPjJ4GfQelIl+/FgSC+Y= github.com/vesoft-inc/nebula-importer v1.0.1-0.20211213064541-05a8646be295 h1:YdBNGn+5YyIuQ6cWjIPCvSJW/3qj5ck5UIWGeh4hXNI= github.com/vesoft-inc/nebula-importer v1.0.1-0.20211213064541-05a8646be295/go.mod h1:0nHCbr2/nckhfxAA8sDbwxkNzA9YyXazWKyVMT/PfPo= github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc= diff --git a/service/pool/pool.go b/service/pool/pool.go index 92ac19c..4950519 100644 --- a/service/pool/pool.go +++ b/service/pool/pool.go @@ -3,7 +3,6 @@ package pool import ( "encoding/json" "errors" - "fmt" "regexp" "strings" "sync" @@ -15,7 +14,6 @@ import ( uuid "github.com/satori/go.uuid" nebula "github.com/vesoft-inc/nebula-go/v2" - nebulatype "github.com/vesoft-inc/nebula-go/v2/nebula" ) var ( @@ -91,83 +89,6 @@ func isThriftTransportError(err error) bool { return false } -// construct Slice to nebula.NList -func Slice2Nlist(list []interface{}) (*nebulatype.NList, error) { - sv := []*nebulatype.Value{} - var ret nebulatype.NList - for _, item := range list { - nv, er := Base2Value(item) - if er != nil { - return nil, er - } - sv = append(sv, nv) - } - ret.Values = sv - return &ret, nil -} - -// construct map to nebula.NMap -func Map2Nmap(m map[string]interface{}) (*nebulatype.NMap, error) { - var ret nebulatype.NMap - kvs := map[string]*nebulatype.Value{} - for k, v := range m { - nv, err := Base2Value(v) - if err != nil { - return nil, err - } - kvs[k] = nv - } - ret.Kvs = kvs - return &ret, nil -} - -// construct go-type to nebula.Value -func Base2Value(any interface{}) (value *nebulatype.Value, err error) { - value = nebulatype.NewValue() - if v, ok := any.(bool); ok { - value.BVal = &v - } else if v, ok := any.(int); ok { - ival := int64(v) - value.IVal = &ival - } else if v, ok := any.(float64); ok { - if v == float64(int64(v)) { - iv := int64(v) - value.IVal = &iv - } else { - value.FVal = &v - } - } else if v, ok := any.(float32); ok { - if v == float32(int64(v)) { - iv := int64(v) - value.IVal = &iv - } else { - fval := float64(v) - value.FVal = &fval - } - } else if v, ok := any.(string); ok { - value.SVal = []byte(v) - } else if any == nil { - nval := nebulatype.NullType___NULL__ - value.NVal = &nval - } else if v, ok := any.([]interface{}); ok { - nv, er := Slice2Nlist([]interface{}(v)) - if er != nil { - err = er - } - value.LVal = nv - } else if v, ok := any.(map[string]interface{}); ok { - nv, er := Map2Nmap(map[string]interface{}(v)) - if er != nil { - err = er - } - value.MVal = nv - } else { - // unsupport other Value type, use this function carefully - err = fmt.Errorf("Only support convert boolean/float/int/string/map/list to nebula.Value but %T", any) - } - return -} - func isCmd(query string) (isLocal bool, localCmd int, args []string) { isLocal = false localCmd = Unknown @@ -343,15 +264,7 @@ func NewConnection(address string, port int, username string, password string) ( } if len(request.Gql) > 0 { - params := make(map[string]*nebulatype.Value) - for k, v := range connection.parameterMap { - value, paramError := Base2Value(v) - if paramError != nil { - err = paramError - } - params[k] = value - } - response, err := connection.session.ExecuteWithParameter(request.Gql, params) + response, err := connection.session.ExecuteWithParameter(request.Gql, connection.parameterMap) if err != nil && (isThriftProtoError(err) || isThriftTransportError(err)) { err = ConnectionClosedError }