Skip to content

Commit

Permalink
mod: update cypher parameter (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
hetao92 authored Jan 6, 2022
1 parent bbb2a43 commit aa4531a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 89 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
89 changes: 1 addition & 88 deletions service/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pool
import (
"encoding/json"
"errors"
"fmt"
"regexp"
"strings"
"sync"
Expand All @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit aa4531a

Please sign in to comment.