From c3175f3f53d7eb23ea45468ec2147329e0d7e63c Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Tue, 24 Oct 2023 19:38:22 +0530 Subject: [PATCH] setup norm for Nebula --- go.mod | 5 +- go.sum | 15 +- pkg/storage/internalstorage/config.go | 22 +- pkg/storage/internalstorage/register.go | 76 +- .../vesoft-inc/nebula-go/v2/.editorconfig | 12 + .../vesoft-inc/nebula-go/v2/.gitignore | 20 + .../vesoft-inc/nebula-go/v2/Makefile | 21 + .../vesoft-inc/nebula-go/v2/README.md | 52 + .../vesoft-inc/nebula-go/v2/configs.go | 54 + .../vesoft-inc/nebula-go/v2/connection.go | 93 + .../nebula-go/v2/connection_pool.go | 240 ++ .../vesoft-inc/nebula-go/v2/host_address.go | 33 + .../vesoft-inc/nebula-go/v2/logger.go | 36 + .../nebula-go/v2/nebula/constants.go | 23 + .../nebula-go/v2/nebula/graph/constants.go | 26 + .../nebula-go/v2/nebula/graph/graphservice.go | 1561 ++++++++ .../nebula-go/v2/nebula/graph/ttypes.go | 1654 ++++++++ .../vesoft-inc/nebula-go/v2/nebula/ttypes.go | 3365 +++++++++++++++++ .../vesoft-inc/nebula-go/v2/result_set.go | 992 +++++ .../vesoft-inc/nebula-go/v2/session.go | 95 + .../vesoft-inc/nebula-go/v2/value_wrapper.go | 323 ++ .../vesoft-inc/nebula-go/v3/Makefile | 15 +- .../vesoft-inc/nebula-go/v3/README.md | 37 +- .../vesoft-inc/nebula-go/v3/configs.go | 123 + .../vesoft-inc/nebula-go/v3/connection.go | 21 +- .../nebula-go/v3/connection_pool.go | 57 +- .../vesoft-inc/nebula-go/v3/nebula/ttypes.go | 181 +- .../vesoft-inc/nebula-go/v3/result_set.go | 47 +- .../vesoft-inc/nebula-go/v3/session.go | 116 +- .../vesoft-inc/nebula-go/v3/session_pool.go | 514 +++ vendor/github.com/zhihu/norm/LICENSE | 21 + .../zhihu/norm/constants/constant.go | 17 + .../zhihu/norm/dialectors/dialector.go | 53 + .../zhihu/norm/dialectors/nebula.go | 126 + .../norm/internal/converts/insert_edge.go | 51 + .../norm/internal/converts/insert_vertex.go | 119 + .../zhihu/norm/internal/converts/query.go | 167 + .../norm/internal/converts/upsert_edge.go | 43 + .../norm/internal/converts/upsert_vertex.go | 55 + .../zhihu/norm/internal/converts/util.go | 95 + .../zhihu/norm/internal/utils/util.go | 13 + vendor/github.com/zhihu/norm/v3/.gitignore | 91 + .../zhihu/norm/v3/CODE_OF_CONDUCT.md | 132 + .../zhihu/norm/v3/CODE_OF_CONDUCT_CN.md | 87 + .../github.com/zhihu/norm/v3/CONTRIBUTING.md | 0 vendor/github.com/zhihu/norm/v3/LICENSE | 21 + vendor/github.com/zhihu/norm/v3/Makefile | 17 + vendor/github.com/zhihu/norm/v3/README.md | 57 + .../github.com/zhihu/norm/v3/api_chainable.go | 94 + .../github.com/zhihu/norm/v3/api_finished.go | 84 + vendor/github.com/zhihu/norm/v3/config.go | 20 + .../zhihu/norm/v3/dialectors/dialector.go | 53 + .../zhihu/norm/v3/dialectors/nebula.go | 126 + vendor/github.com/zhihu/norm/v3/exector.go | 23 + vendor/github.com/zhihu/norm/v3/logger.go | 9 + vendor/github.com/zhihu/norm/v3/model.go | 94 + vendor/github.com/zhihu/norm/v3/norm.go | 73 + vendor/modules.txt | 17 +- 58 files changed, 11364 insertions(+), 223 deletions(-) create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/.editorconfig create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/.gitignore create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/Makefile create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/README.md create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/configs.go create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/connection.go create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/connection_pool.go create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/host_address.go create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/logger.go create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/nebula/constants.go create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/nebula/graph/constants.go create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/nebula/graph/graphservice.go create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/nebula/graph/ttypes.go create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/nebula/ttypes.go create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/result_set.go create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/session.go create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v2/value_wrapper.go create mode 100644 vendor/github.com/vesoft-inc/nebula-go/v3/session_pool.go create mode 100644 vendor/github.com/zhihu/norm/LICENSE create mode 100644 vendor/github.com/zhihu/norm/constants/constant.go create mode 100644 vendor/github.com/zhihu/norm/dialectors/dialector.go create mode 100644 vendor/github.com/zhihu/norm/dialectors/nebula.go create mode 100644 vendor/github.com/zhihu/norm/internal/converts/insert_edge.go create mode 100644 vendor/github.com/zhihu/norm/internal/converts/insert_vertex.go create mode 100644 vendor/github.com/zhihu/norm/internal/converts/query.go create mode 100644 vendor/github.com/zhihu/norm/internal/converts/upsert_edge.go create mode 100644 vendor/github.com/zhihu/norm/internal/converts/upsert_vertex.go create mode 100644 vendor/github.com/zhihu/norm/internal/converts/util.go create mode 100644 vendor/github.com/zhihu/norm/internal/utils/util.go create mode 100644 vendor/github.com/zhihu/norm/v3/.gitignore create mode 100644 vendor/github.com/zhihu/norm/v3/CODE_OF_CONDUCT.md create mode 100644 vendor/github.com/zhihu/norm/v3/CODE_OF_CONDUCT_CN.md create mode 100644 vendor/github.com/zhihu/norm/v3/CONTRIBUTING.md create mode 100644 vendor/github.com/zhihu/norm/v3/LICENSE create mode 100644 vendor/github.com/zhihu/norm/v3/Makefile create mode 100644 vendor/github.com/zhihu/norm/v3/README.md create mode 100644 vendor/github.com/zhihu/norm/v3/api_chainable.go create mode 100644 vendor/github.com/zhihu/norm/v3/api_finished.go create mode 100644 vendor/github.com/zhihu/norm/v3/config.go create mode 100644 vendor/github.com/zhihu/norm/v3/dialectors/dialector.go create mode 100644 vendor/github.com/zhihu/norm/v3/dialectors/nebula.go create mode 100644 vendor/github.com/zhihu/norm/v3/exector.go create mode 100644 vendor/github.com/zhihu/norm/v3/logger.go create mode 100644 vendor/github.com/zhihu/norm/v3/model.go create mode 100644 vendor/github.com/zhihu/norm/v3/norm.go diff --git a/go.mod b/go.mod index 8f0328e06..67543918e 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,8 @@ require ( github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.3 - github.com/vesoft-inc/nebula-go/v3 v3.0.0 + github.com/vesoft-inc/nebula-go/v3 v3.3.1 + github.com/zhihu/norm/v3 v3.0.0 go.uber.org/atomic v1.10.0 gopkg.in/natefinch/lumberjack.v2 v2.0.0 gorm.io/datatypes v1.0.7 @@ -120,6 +121,8 @@ require ( github.com/shopspring/decimal v1.2.0 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/stoewer/go-strcase v1.2.0 // indirect + github.com/vesoft-inc/nebula-go/v2 v2.0.0-ga // indirect + github.com/zhihu/norm v0.1.11 // indirect go.etcd.io/etcd/api/v3 v3.5.6 // indirect go.etcd.io/etcd/client/pkg/v3 v3.5.6 // indirect go.etcd.io/etcd/client/v2 v2.305.6 // indirect diff --git a/go.sum b/go.sum index cd8782f57..8f3207946 100644 --- a/go.sum +++ b/go.sum @@ -136,6 +136,7 @@ github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww= github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= +github.com/facebook/fbthrift v0.0.0-20190922225929-2f9839604e25/go.mod h1:2tncLx5rmw69e5kMBv/yJneERbzrr1yr5fdlnTbu8lU= github.com/facebook/fbthrift v0.31.1-0.20211129061412-801ed7f9f295 h1:ZA+qQ3d2In0RNzVpk+D/nq1sjDSv+s1Wy2zrAPQAmsg= github.com/facebook/fbthrift v0.31.1-0.20211129061412-801ed7f9f295/go.mod h1:2tncLx5rmw69e5kMBv/yJneERbzrr1yr5fdlnTbu8lU= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= @@ -214,6 +215,7 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -532,6 +534,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= @@ -539,8 +542,10 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 h1:uruHq4dN7GR16kFc5fp3d1RIYzJW5onx8Ybykw2YQFA= -github.com/vesoft-inc/nebula-go/v3 v3.0.0 h1:ii5T3vps4xAQZkzPvGn6NuiUWlH/rm1zdIS5VTEA71A= -github.com/vesoft-inc/nebula-go/v3 v3.0.0/go.mod h1:+sXv05jYQBARdTbTcIEsWVXCnF/6ttOlDK35xQ6m54s= +github.com/vesoft-inc/nebula-go/v2 v2.0.0-ga h1:4t2V73o4mq2io6uJitNFtJeFc6xnr8pVoCCJd/FAiRM= +github.com/vesoft-inc/nebula-go/v2 v2.0.0-ga/go.mod h1:qvrlydV8O1Jbff7b7cXSLOvZNs9BcE8pFZa/1nvB3fo= +github.com/vesoft-inc/nebula-go/v3 v3.3.1 h1:5DxUxswEQvK9gkK6Y/X4fhX+bmIeHIJrn+b2q7tE3HM= +github.com/vesoft-inc/nebula-go/v3 v3.3.1/go.mod h1:+sXv05jYQBARdTbTcIEsWVXCnF/6ttOlDK35xQ6m54s= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -550,6 +555,10 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1 github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= +github.com/zhihu/norm v0.1.11 h1:uFVvfkCuYOZP19ZG7hJOWqOVDSwDOoY+auZ8UPObJcU= +github.com/zhihu/norm v0.1.11/go.mod h1:VBH+aIV1TJfLIM5kyhCD812ghzjp0XIYYv5W/sdOA5A= +github.com/zhihu/norm/v3 v3.0.0 h1:YYpaYfgQ5ysryvsabAca7uD2OGr8F6s3joiMcPPbWm8= +github.com/zhihu/norm/v3 v3.0.0/go.mod h1:9HzBaVWF/Tw2VWaiGJgz4qxS6cr9C0SjHX0S10uFHEc= go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= go.etcd.io/etcd/api/v3 v3.5.6 h1:Cy2qx3npLcYqTKqGJzMypnMv2tiRyifZJ17BlWIWA7A= go.etcd.io/etcd/api/v3 v3.5.6/go.mod h1:KFtNaxGDw4Yx/BA4iPPwevUTAuqcsPxzyX8PHydchN8= @@ -879,6 +888,7 @@ golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= @@ -993,6 +1003,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/pkg/storage/internalstorage/config.go b/pkg/storage/internalstorage/config.go index 60965c4ee..cb5b8d7f2 100644 --- a/pkg/storage/internalstorage/config.go +++ b/pkg/storage/internalstorage/config.go @@ -12,7 +12,7 @@ import ( "github.com/go-sql-driver/mysql" "github.com/jackc/pgx/v4" - gnebula "github.com/vesoft-inc/nebula-go/v3" + "github.com/zhihu/norm/v3/dialectors" "gopkg.in/natefinch/lumberjack.v2" "gorm.io/gorm/logger" "k8s.io/klog/v2" @@ -299,21 +299,19 @@ func (cfg *Config) genSQLiteDSN() (string, error) { return cfg.DSN, nil } -// Initialize logger for nebula -var nebulalog = gnebula.DefaultLogger{} - -func (cfg *Config) genNebulaConfig() (*gnebula.PoolConfig, error) { +func (cfg *Config) genNebulaConfig() (*dialectors.DialectorConfig, error) { if cfg.DSN == "" { return nil, errors.New("nebula: dsn is required") } + var nebulaConfig dialectors.DialectorConfig + nebulaConfig.IdleTime = cfg.Nebula.IdleTime + nebulaConfig.MaxConnPoolSize = cfg.Nebula.MaxConnPoolSize + nebulaConfig.MinConnPoolSize = cfg.Nebula.MinConnPoolSize + nebulaConfig.Timeout = cfg.Nebula.TimeOut + nebulaConfig.Username = cfg.User + nebulaConfig.Password = cfg.Password - nebulaPoolConfig := gnebula.GetDefaultConf() - nebulaPoolConfig.IdleTime = cfg.Nebula.IdleTime - nebulaPoolConfig.MaxConnPoolSize = cfg.Nebula.MaxConnPoolSize - nebulaPoolConfig.MinConnPoolSize = cfg.Nebula.MinConnPoolSize - nebulaPoolConfig.TimeOut = cfg.Nebula.TimeOut - - return &nebulaPoolConfig, nil + return &nebulaConfig, nil } func (cfg *Config) addMysqlErrorNumbers() { diff --git a/pkg/storage/internalstorage/register.go b/pkg/storage/internalstorage/register.go index 99c3312de..45461c5d3 100644 --- a/pkg/storage/internalstorage/register.go +++ b/pkg/storage/internalstorage/register.go @@ -6,12 +6,12 @@ import ( "io" "log" "os" - "strconv" "github.com/go-sql-driver/mysql" "github.com/jackc/pgx/v4/stdlib" "github.com/jinzhu/configor" - gnebula "github.com/vesoft-inc/nebula-go/v3" + "github.com/zhihu/norm/v3" + "github.com/zhihu/norm/v3/dialectors" "gopkg.in/natefinch/lumberjack.v2" gmysql "gorm.io/driver/mysql" gpostgres "gorm.io/driver/postgres" @@ -42,6 +42,7 @@ func NewStorageFactory(configPath string) (storage.StorageFactory, error) { } var dialector gorm.Dialector + var normDialector *dialectors.NebulaDialector switch cfg.Type { case "mysql": mysqlConfig, err := cfg.genMySQLConfig() @@ -71,34 +72,11 @@ func NewStorageFactory(configPath string) (storage.StorageFactory, error) { } dialector = gsqlite.Open(dsn) case "nebula": - nebulaconfig, err := cfg.genNebulaConfig() + NebulaConfig, err := cfg.genNebulaConfig() if err != nil { return nil, err } - // TODO : dialector like for nebula - port, err := strconv.Atoi(cfg.Port) - if err != nil { - return nil, err - } - - hostAddress := gnebula.HostAddress{Host: cfg.Host, Port: port} - hostList := []gnebula.HostAddress{hostAddress} - // Initialize connection pool - pool, err := gnebula.NewConnectionPool(hostList, *nebulaconfig, nebulalog) - if err != nil { - nebulalog.Fatal(fmt.Sprintf("Fail to initialize the connection pool, host: %s, port: %d, %s", cfg.Host, port, err.Error())) - } - // Close all connections in the pool - defer pool.Close() - - // Create session - session, err := pool.GetSession(cfg.User, cfg.Password) - if err != nil { - nebulalog.Fatal(fmt.Sprintf("Fail to create a new session from connection pool, username: %s, password: %s, %s", - cfg.User, cfg.Password, err.Error())) - } - // Release session and return connection back to connection pool - defer session.Release() + normDialector = dialectors.MustNewNebulaDialector(*NebulaConfig) default: return nil, fmt.Errorf("not support storage type: %s", cfg.Type) } @@ -108,27 +86,35 @@ func NewStorageFactory(configPath string) (storage.StorageFactory, error) { return nil, err } - db, err := gorm.Open(dialector, &gorm.Config{SkipDefaultTransaction: true, Logger: logger}) - if err != nil { - return nil, err - } - sqlDB, err := db.DB() - if err != nil { - return nil, err - } - connPool, err := cfg.getConnPoolConfig() - if err != nil { - return nil, err - } - sqlDB.SetMaxIdleConns(connPool.MaxIdleConns) - sqlDB.SetMaxOpenConns(connPool.MaxOpenConns) - sqlDB.SetConnMaxLifetime(connPool.ConnMaxLifetime) + if cfg.Type != "nebula" { + db, err := gorm.Open(dialector, &gorm.Config{SkipDefaultTransaction: true, Logger: logger}) + if err != nil { + return nil, err + } + sqlDB, err := db.DB() + if err != nil { + return nil, err + } + connPool, err := cfg.getConnPoolConfig() + if err != nil { + return nil, err + } + sqlDB.SetMaxIdleConns(connPool.MaxIdleConns) + sqlDB.SetMaxOpenConns(connPool.MaxOpenConns) + sqlDB.SetConnMaxLifetime(connPool.ConnMaxLifetime) - if err := db.AutoMigrate(&Resource{}); err != nil { - return nil, err + if err := db.AutoMigrate(&Resource{}); err != nil { + return nil, err + } + + return &StorageFactory{db}, nil + } + if cfg.Type == "nebula" { + db := norm.MustOpen(normDialector, norm.Config{}) + return &StorageFactory{db}, nil // have to create a new nebula storage factory and possibly this function to cater nebula needs } + return nil, fmt.Errorf("Cannot create a new storage factory based on the database specified") - return &StorageFactory{db}, nil } func newLogger(cfg *Config) (logger.Interface, error) { diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/.editorconfig b/vendor/github.com/vesoft-inc/nebula-go/v2/.editorconfig new file mode 100644 index 000000000..b4195bb85 --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +insert_final_newline = true +charset = utf-8 +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 + +[{Makefile,go.mod,go.sum,*.go}] +indent_style = tab +indent_size = 2 diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/.gitignore b/vendor/github.com/vesoft-inc/nebula-go/v2/.gitignore new file mode 100644 index 000000000..90531103d --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/.gitignore @@ -0,0 +1,20 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +.vscode/ + +# Test binary, build with `go test -c` +*.test + +# Docker compose for testing +nebula-docker-compose/data/ +nebula-docker-compose/logs/ +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +.DS_Store + +.idea/ diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/Makefile b/vendor/github.com/vesoft-inc/nebula-go/v2/Makefile new file mode 100644 index 000000000..887e306fe --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/Makefile @@ -0,0 +1,21 @@ +.PHONY: build test test-dev fmt ci + +default: build + +build: fmt + go mod tidy + go build + +test: + go mod tidy + go test -v -race + +fmt: + go fmt + +ci: + cd ./nebula-docker-compose && docker-compose up -d && \ + sleep 5 && \ + cd .. && \ + go test -v -race; \ + cd ./nebula-docker-compose && docker-compose down -v diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/README.md b/vendor/github.com/vesoft-inc/nebula-go/v2/README.md new file mode 100644 index 000000000..47fc3cd90 --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/README.md @@ -0,0 +1,52 @@ +# nebula-go + +**IMPORTANT: Code of Nebula go client has been transferred from [nebula-clients](https://github.com/vesoft-inc/nebula-clients) to this repository(nebula-go), and new releases in the future will be published in this repository. +Please update your go.mod and imports correspondingly.** + +Official Nebula Go client which communicates with the server using [fbthrift](https://github.com/facebook/fbthrift/). Currently the latest stable release is **[v2.0.0-ga](https://github.com/vesoft-inc/nebula-go/tree/release-v2.0.0-ga)** + +The code in **master branch** will be updated to accommodate the nightly changes made in Nebula Graph. +To Use the console with a stable release of Nebula Graph, please check the branches and use the corresponding version. + +| Client version | Nebula Service Version| +|:--------------:|:-------------------:| +| **[v1.0.0](https://github.com/vesoft-inc/nebula-go/tree/v1.0)** | 1.x.x | +| **[v2.0.0-beta](https://github.com/vesoft-inc/nebula-go/tree/v2.0.0-beta)** | 2.0.0-beta | +| **[v2.0.0-rc1](https://github.com/vesoft-inc/nebula-go/tree/v2.0.0-rc1)** | 2.0.0-rc1 | +| **[v2.0.0-ga](https://github.com/vesoft-inc/nebula-go/tree/v2.0.0-ga)** | 2.0.0-ga | +| **[v2.0.0-master](https://github.com/vesoft-inc/nebula-go/tree/master)** | 2.0.0-nightly | + + +Please be careful not to modify the files in the nebula directory, these codes were all generated by fbthrift. + +## Install + +```shell +$ go get -u -v github.com/vesoft-inc/nebula-go@master +``` + +If you get a message like `cannot use path@version syntax in GOPATH mode`, see the instructions below for [enabling go modules](#enabling-go-modules). + +## Usage example + +[Simple Code Example](https://github.com/vesoft-inc/nebula-go/tree/master/basic_example/graph_client_basic_example.go) + +[Code Example with Gorountines](https://github.com/vesoft-inc/nebula-go/tree/master/gorountines_example/graph_client_goroutines_example.go) + +## Enabling go modules + +Dependency management tools are built into go 1.11+ in the form of [go modules](https://github.com/golang/go/wiki/Modules). +If you are using go 1.11 or 1.12 and are working with a project located within `$GOPATH`, you need to do: + +```sh +export GO111MODULE=on +``` + +Ensure your project has a `go.mod` file defined at the root of your project. +If you do not already have one, `go mod init` will create one for you: + +```sh +go mod init +``` + +And then try to get dependencies of `github.com/vesoft-inc/nebula-go` in your go module by simply `go get -u -v github.com/vesoft-inc/nebula-go@master`. diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/configs.go b/vendor/github.com/vesoft-inc/nebula-go/v2/configs.go new file mode 100644 index 000000000..f66b4c908 --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/configs.go @@ -0,0 +1,54 @@ +/* Copyright (c) 2020 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +package nebula_go + +import ( + "time" +) + +type PoolConfig struct { + // Socket timeout and Socket connection timeout, unit: seconds + TimeOut time.Duration + // The idleTime of the connection, unit: seconds + // If connection's idle time is longer than idleTime, it will be delete + // 0 value means the connection will not expire + IdleTime time.Duration + // The max connections in pool for all addresses + MaxConnPoolSize int + // The min connections in pool for all addresses + MinConnPoolSize int +} + +// Validate config +func (conf *PoolConfig) validateConf(log Logger) { + if conf.TimeOut < 0 { + conf.TimeOut = 0 * time.Millisecond + log.Warn("Illegal Timeout value, the default value of 0 second has been applied") + } + if conf.IdleTime < 0 { + conf.IdleTime = 0 * time.Millisecond + log.Warn("Invalid IdleTime value, the default value of 0 second has been applied") + } + if conf.MaxConnPoolSize < 1 { + conf.MaxConnPoolSize = 10 + log.Warn("Invalid MaxConnPoolSize value, the default value of 10 has been applied") + } + if conf.MinConnPoolSize < 0 { + conf.MinConnPoolSize = 0 + log.Warn("Invalid MinConnPoolSize value, the default value of 0 has been applied") + } +} + +// Return the default config +func GetDefaultConf() PoolConfig { + return PoolConfig{ + TimeOut: 0 * time.Millisecond, + IdleTime: 0 * time.Millisecond, + MaxConnPoolSize: 10, + MinConnPoolSize: 0, + } +} diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/connection.go b/vendor/github.com/vesoft-inc/nebula-go/v2/connection.go new file mode 100644 index 000000000..60c1471cb --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/connection.go @@ -0,0 +1,93 @@ +/* Copyright (c) 2020 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +package nebula_go + +import ( + "fmt" + "time" + + "github.com/facebook/fbthrift/thrift/lib/go/thrift" + "github.com/vesoft-inc/nebula-go/v2/nebula/graph" +) + +type connection struct { + severAddress HostAddress + graph *graph.GraphServiceClient +} + +func newConnection(severAddress HostAddress) *connection { + return &connection{ + severAddress: severAddress, + graph: nil, + } +} + +func (cn *connection) open(hostAddress HostAddress, timeout time.Duration) error { + ip := hostAddress.Host + port := hostAddress.Port + newAdd := fmt.Sprintf("%s:%d", ip, port) + timeoutOption := thrift.SocketTimeout(timeout) + bufferSize := 128 << 10 + addressOption := thrift.SocketAddr(newAdd) + sock, err := thrift.NewSocket(timeoutOption, addressOption) + if err != nil { + return fmt.Errorf("Failed to create a net.Conn-backed Transport,: %s", err.Error()) + } + + transport := thrift.NewBufferedTransport(sock, bufferSize) + pf := thrift.NewBinaryProtocolFactoryDefault() + cn.graph = graph.NewGraphServiceClientFactory(transport, pf) + if err = cn.graph.Transport.Open(); err != nil { + return fmt.Errorf("Failed to open transport, error: %s", err.Error()) + } + if !cn.graph.Transport.IsOpen() { + return fmt.Errorf("Transport is off") + } + return nil +} + +// Authenticate +func (cn *connection) authenticate(username, password string) (*graph.AuthResponse, error) { + resp, err := cn.graph.Authenticate([]byte(username), []byte(password)) + if err != nil { + err = fmt.Errorf("Authentication fails, %s", err.Error()) + if e := cn.graph.Close(); e != nil { + err = fmt.Errorf("Fail to close transport, error: %s", e.Error()) + } + return nil, err + } + if resp.ErrorCode != graph.ErrorCode_SUCCEEDED { + return nil, fmt.Errorf("Fail to authenticate, error: %s", resp.ErrorMsg) + } + return resp, err +} + +func (cn *connection) execute(sessionID int64, stmt string) (*graph.ExecutionResponse, error) { + return cn.graph.Execute(sessionID, []byte(stmt)) +} + +// unsupported +// func (client *GraphClient) ExecuteJson((sessionID int64, stmt string) (*graph.ExecutionResponse, error) { +// return cn.graph.ExecuteJson(sessionID, []byte(stmt)) +// } + +// Check connection to host address +func (cn *connection) ping() bool { + _, err := cn.execute(0, "YIELD 1") + return err == nil +} + +// Sign out and release seesin ID +func (cn *connection) signOut(sessionID int64) error { + // Release session ID to graphd + return cn.graph.Signout(sessionID) +} + +// Close transport +func (cn *connection) close() { + cn.graph.Close() +} diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/connection_pool.go b/vendor/github.com/vesoft-inc/nebula-go/v2/connection_pool.go new file mode 100644 index 000000000..dbd8e92a7 --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/connection_pool.go @@ -0,0 +1,240 @@ +/* Copyright (c) 2020 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +package nebula_go + +import ( + "container/list" + "fmt" + "sync" + "time" + + graph "github.com/vesoft-inc/nebula-go/v2/nebula/graph" +) + +type ConnectionPool struct { + idleConnectionQueue list.List + activeConnectionQueue list.List + addresses []HostAddress + conf PoolConfig + hostIndex int + log Logger + rwLock sync.RWMutex +} + +func NewConnectionPool(addresses []HostAddress, conf PoolConfig, log Logger) (*ConnectionPool, error) { + // Process domain to IP + convAddress, err := DomainToIP(addresses) + if err != nil { + return nil, fmt.Errorf("Failed to find IP, error: %s ", err.Error()) + } + + // Check input + if len(convAddress) == 0 { + return nil, fmt.Errorf("Failed to initialize connection pool: illegal address input") + } + + // Check config + conf.validateConf(log) + + newPool := &ConnectionPool{ + conf: conf, + log: log, + addresses: convAddress, + hostIndex: 0, + } + if err = newPool.initPool(); err != nil { + return nil, err + } + return newPool, nil +} + +func (pool *ConnectionPool) initPool() error { + for i := 0; i < pool.conf.MinConnPoolSize; i++ { + // Simple round-robin + newConn := newConnection(pool.addresses[i%len(pool.addresses)]) + + // Open connection to host + err := newConn.open(newConn.severAddress, pool.conf.TimeOut) + if err != nil { + // If initialization failed, clean idle queue + idleLen := pool.idleConnectionQueue.Len() + for i := 0; i < idleLen; i++ { + pool.idleConnectionQueue.Front().Value.(*connection).close() + pool.idleConnectionQueue.Remove(pool.idleConnectionQueue.Front()) + } + return fmt.Errorf("Failed to open connection, error: %s ", err.Error()) + } + // Mark connection as in use + pool.idleConnectionQueue.PushBack(newConn) + } + pool.log.Info("connection pool is initialized successfully") + return nil +} + +func (pool *ConnectionPool) GetSession(username, password string) (*Session, error) { + // Get valid and usable connection + var conn *connection = nil + var err error = nil + const retryTimes = 3 + for i := 0; i < retryTimes; i++ { + conn, err = pool.getIdleConn() + if err == nil { + break + } + } + if conn == nil { + return nil, err + } + // Authenticate + resp, err := conn.authenticate(username, password) + if err != nil || resp.GetErrorCode() != graph.ErrorCode_SUCCEEDED { + // if authentication failed, put connection back + pool.rwLock.Lock() + defer pool.rwLock.Unlock() + removeFromList(&pool.activeConnectionQueue, conn) + pool.idleConnectionQueue.PushBack(conn) + return nil, err + } + + sessID := resp.GetSessionID() + // Create new session + newSession := Session{ + sessionID: sessID, + connection: conn, + connPool: pool, + log: pool.log, + } + + return &newSession, nil +} + +func (pool *ConnectionPool) getIdleConn() (*connection, error) { + pool.rwLock.Lock() + defer pool.rwLock.Unlock() + + // Take an idle valid connection if possible + if pool.idleConnectionQueue.Len() > 0 { + var newConn *connection = nil + var newEle *list.Element = nil + for ele := pool.idleConnectionQueue.Front(); ele != nil; ele = ele.Next() { + // Check if connection is valid + if res := ele.Value.(*connection).ping(); res { + newConn = ele.Value.(*connection) + newEle = ele + break + } + } + if newConn == nil { + return pool.createConnection() + } + // Remove new connection from idle and add to active if found + pool.idleConnectionQueue.Remove(newEle) + pool.activeConnectionQueue.PushBack(newConn) + return newConn, nil + } + + // Create a new connection if there is no idle connection and total connection < pool max size + newConn, err := pool.createConnection() + // TODO: If no idle avaliable, wait for timeout and reconnect + return newConn, err +} + +// Release connection to pool +func (pool *ConnectionPool) release(conn *connection) { + pool.rwLock.Lock() + defer pool.rwLock.Unlock() + // Remove connection from active queue and add into idle queue + removeFromList(&pool.activeConnectionQueue, conn) + pool.idleConnectionQueue.PushBack(conn) +} + +// Check avaliability of host +func (pool *ConnectionPool) Ping(host HostAddress, timeout time.Duration) error { + newConn := newConnection(host) + // Open connection to host + if err := newConn.open(newConn.severAddress, timeout); err != nil { + return err + } + newConn.close() + return nil +} + +// Close all connection +func (pool *ConnectionPool) Close() { + pool.rwLock.Lock() + defer pool.rwLock.Unlock() + idleLen := pool.idleConnectionQueue.Len() + activeLen := pool.activeConnectionQueue.Len() + + for i := 0; i < idleLen; i++ { + pool.idleConnectionQueue.Front().Value.(*connection).close() + pool.idleConnectionQueue.Remove(pool.idleConnectionQueue.Front()) + } + for i := 0; i < activeLen; i++ { + pool.activeConnectionQueue.Front().Value.(*connection).close() + pool.activeConnectionQueue.Remove(pool.activeConnectionQueue.Front()) + } +} + +func (pool *ConnectionPool) getActiveConnCount() int { + return pool.activeConnectionQueue.Len() +} + +func (pool *ConnectionPool) getIdleConnCount() int { + return pool.idleConnectionQueue.Len() +} + +// Get a valid host (round robin) +func (pool *ConnectionPool) getHost() HostAddress { + if pool.hostIndex == len(pool.addresses) { + pool.hostIndex = 0 + } + host := pool.addresses[pool.hostIndex] + pool.hostIndex++ + return host +} + +// Select a new host to create a new connection +func (pool *ConnectionPool) newConnToHost() (*connection, error) { + // Get a valid host (round robin) + host := pool.getHost() + newConn := newConnection(host) + // Open connection to host + err := newConn.open(newConn.severAddress, pool.conf.TimeOut) + if err != nil { + return nil, err + } + // Add connection to active queue + pool.activeConnectionQueue.PushBack(newConn) + // TODO: update workload + return newConn, nil +} + +// Remove a connection from list +func removeFromList(l *list.List, conn *connection) { + for ele := l.Front(); ele != nil; ele = ele.Next() { + if ele.Value.(*connection) == conn { + l.Remove(ele) + } + } +} + +// Compare total connection number with pool max size and return a connection if capable +func (pool *ConnectionPool) createConnection() (*connection, error) { + totalConn := pool.idleConnectionQueue.Len() + pool.activeConnectionQueue.Len() + // If no idle avaliable and the number of total connection reaches the max pool size, return error/wait for timeout + if totalConn >= pool.conf.MaxConnPoolSize { + return nil, fmt.Errorf("Failed to get connection: No valid connection in the idle queue and connection number has reached the pool capacity") + } + + newConn, err := pool.newConnToHost() + if err != nil { + return nil, err + } + // TODO: update workload + return newConn, nil +} diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/host_address.go b/vendor/github.com/vesoft-inc/nebula-go/v2/host_address.go new file mode 100644 index 000000000..66bf5a104 --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/host_address.go @@ -0,0 +1,33 @@ +/* Copyright (c) 2020 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +package nebula_go + +import ( + "fmt" + "net" + "os" +) + +type HostAddress struct { + Host string + Port int +} + +func DomainToIP(addresses []HostAddress) ([]HostAddress, error) { + var newHostsList []HostAddress + for _, host := range addresses { + // Get ip from domain + ips, err := net.LookupIP(host.Host) + if err != nil { + fmt.Fprintf(os.Stderr, "Could not get IPs: %v\n", err) + return nil, err + } + convHost := HostAddress{Host: ips[0].String(), Port: host.Port} + newHostsList = append(newHostsList, convHost) + } + return newHostsList, nil +} diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/logger.go b/vendor/github.com/vesoft-inc/nebula-go/v2/logger.go new file mode 100644 index 000000000..ac58b15d9 --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/logger.go @@ -0,0 +1,36 @@ +/* Copyright (c) 2020 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +package nebula_go + +import ( + "log" +) + +type Logger interface { + Info(msg string) + Warn(msg string) + Error(msg string) + Fatal(msg string) +} + +type DefaultLogger struct{} + +func (l DefaultLogger) Info(msg string) { + log.Printf("[INFO] %s\n", msg) +} + +func (l DefaultLogger) Warn(msg string) { + log.Printf("[WARNING] %s\n", msg) +} + +func (l DefaultLogger) Error(msg string) { + log.Printf("[ERROR] %s\n", msg) +} + +func (l DefaultLogger) Fatal(msg string) { + log.Fatalf("[FATAL] %s\n", msg) +} diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/constants.go b/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/constants.go new file mode 100644 index 000000000..1e3bf0d82 --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/constants.go @@ -0,0 +1,23 @@ +// Autogenerated by Thrift Compiler (facebook) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +// @generated + +package nebula + +import ( + "bytes" + "sync" + "fmt" + thrift "github.com/facebook/fbthrift/thrift/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = sync.Mutex{} +var _ = bytes.Equal + + +func init() { +} + diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/graph/constants.go b/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/graph/constants.go new file mode 100644 index 000000000..84a258e49 --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/graph/constants.go @@ -0,0 +1,26 @@ +// Autogenerated by Thrift Compiler (facebook) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +// @generated + +package graph + +import ( + "bytes" + "sync" + "fmt" + thrift "github.com/facebook/fbthrift/thrift/lib/go/thrift" + nebula0 "github.com/vesoft-inc/nebula-go/v2/nebula" + +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = sync.Mutex{} +var _ = bytes.Equal + +var _ = nebula0.GoUnusedProtection__ + +func init() { +} + diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/graph/graphservice.go b/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/graph/graphservice.go new file mode 100644 index 000000000..1aa1b10be --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/graph/graphservice.go @@ -0,0 +1,1561 @@ +// Autogenerated by Thrift Compiler (facebook) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +// @generated + +package graph + +import ( + "bytes" + "sync" + "fmt" + thrift "github.com/facebook/fbthrift/thrift/lib/go/thrift" + nebula0 "github.com/vesoft-inc/nebula-go/v2/nebula" + +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = sync.Mutex{} +var _ = bytes.Equal + +var _ = nebula0.GoUnusedProtection__ +type GraphService interface { + // Parameters: + // - Username + // - Password + Authenticate(username []byte, password []byte) (r *AuthResponse, err error) + // Parameters: + // - SessionId + Signout(sessionId int64) (err error) + // Parameters: + // - SessionId + // - Stmt + Execute(sessionId int64, stmt []byte) (r *ExecutionResponse, err error) + // Parameters: + // - SessionId + // - Stmt + ExecuteJson(sessionId int64, stmt []byte) (r []byte, err error) +} + +type GraphServiceClient struct { + Transport thrift.Transport + ProtocolFactory thrift.ProtocolFactory + InputProtocol thrift.Protocol + OutputProtocol thrift.Protocol + SeqId int32 +} + +func (client *GraphServiceClient) Close() error { + return client.Transport.Close() +} + +func NewGraphServiceClientFactory(t thrift.Transport, f thrift.ProtocolFactory) *GraphServiceClient { + return &GraphServiceClient{Transport: t, + ProtocolFactory: f, + InputProtocol: f.GetProtocol(t), + OutputProtocol: f.GetProtocol(t), + SeqId: 0, + } +} + +func NewGraphServiceClient(t thrift.Transport, iprot thrift.Protocol, oprot thrift.Protocol) *GraphServiceClient { + return &GraphServiceClient{Transport: t, + ProtocolFactory: nil, + InputProtocol: iprot, + OutputProtocol: oprot, + SeqId: 0, + } +} + +// Parameters: +// - Username +// - Password +func (p *GraphServiceClient) Authenticate(username []byte, password []byte) (r *AuthResponse, err error) { + if err = p.sendAuthenticate(username, password); err != nil { return } + return p.recvAuthenticate() +} + +func (p *GraphServiceClient) sendAuthenticate(username []byte, password []byte)(err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("authenticate", thrift.CALL, p.SeqId); err != nil { + return + } + args := GraphServiceAuthenticateArgs{ + Username : username, + Password : password, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + + +func (p *GraphServiceClient) recvAuthenticate() (value *AuthResponse, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + method, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if method != "authenticate" { + err = thrift.NewApplicationException(thrift.WRONG_METHOD_NAME, "authenticate failed: wrong method name") + return + } + if p.SeqId != seqId { + err = thrift.NewApplicationException(thrift.BAD_SEQUENCE_ID, "authenticate failed: out of sequence response") + return + } + if mTypeId == thrift.EXCEPTION { + error9 := thrift.NewApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error10 error + error10, err = error9.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error10 + return + } + if mTypeId != thrift.REPLY { + err = thrift.NewApplicationException(thrift.INVALID_MESSAGE_TYPE_EXCEPTION, "authenticate failed: invalid message type") + return + } + result := GraphServiceAuthenticateResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + value = result.GetSuccess() + return +} + +// Parameters: +// - SessionId +func (p *GraphServiceClient) Signout(sessionId int64) (err error) { + if err = p.sendSignout(sessionId); err != nil { return } + return +} + +func (p *GraphServiceClient) sendSignout(sessionId int64)(err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("signout", thrift.ONEWAY, p.SeqId); err != nil { + return + } + args := GraphServiceSignoutArgs{ + SessionId : sessionId, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +// Parameters: +// - SessionId +// - Stmt +func (p *GraphServiceClient) Execute(sessionId int64, stmt []byte) (r *ExecutionResponse, err error) { + if err = p.sendExecute(sessionId, stmt); err != nil { return } + return p.recvExecute() +} + +func (p *GraphServiceClient) sendExecute(sessionId int64, stmt []byte)(err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("execute", thrift.CALL, p.SeqId); err != nil { + return + } + args := GraphServiceExecuteArgs{ + SessionId : sessionId, + Stmt : stmt, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + + +func (p *GraphServiceClient) recvExecute() (value *ExecutionResponse, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + method, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if method != "execute" { + err = thrift.NewApplicationException(thrift.WRONG_METHOD_NAME, "execute failed: wrong method name") + return + } + if p.SeqId != seqId { + err = thrift.NewApplicationException(thrift.BAD_SEQUENCE_ID, "execute failed: out of sequence response") + return + } + if mTypeId == thrift.EXCEPTION { + error11 := thrift.NewApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error12 error + error12, err = error11.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error12 + return + } + if mTypeId != thrift.REPLY { + err = thrift.NewApplicationException(thrift.INVALID_MESSAGE_TYPE_EXCEPTION, "execute failed: invalid message type") + return + } + result := GraphServiceExecuteResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + value = result.GetSuccess() + return +} + +// Parameters: +// - SessionId +// - Stmt +func (p *GraphServiceClient) ExecuteJson(sessionId int64, stmt []byte) (r []byte, err error) { + if err = p.sendExecuteJson(sessionId, stmt); err != nil { return } + return p.recvExecuteJson() +} + +func (p *GraphServiceClient) sendExecuteJson(sessionId int64, stmt []byte)(err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("executeJson", thrift.CALL, p.SeqId); err != nil { + return + } + args := GraphServiceExecuteJsonArgs{ + SessionId : sessionId, + Stmt : stmt, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + + +func (p *GraphServiceClient) recvExecuteJson() (value []byte, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + method, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if method != "executeJson" { + err = thrift.NewApplicationException(thrift.WRONG_METHOD_NAME, "executeJson failed: wrong method name") + return + } + if p.SeqId != seqId { + err = thrift.NewApplicationException(thrift.BAD_SEQUENCE_ID, "executeJson failed: out of sequence response") + return + } + if mTypeId == thrift.EXCEPTION { + error13 := thrift.NewApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error14 error + error14, err = error13.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error14 + return + } + if mTypeId != thrift.REPLY { + err = thrift.NewApplicationException(thrift.INVALID_MESSAGE_TYPE_EXCEPTION, "executeJson failed: invalid message type") + return + } + result := GraphServiceExecuteJsonResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + value = result.GetSuccess() + return +} + + +type GraphServiceThreadsafeClient struct { + Transport thrift.Transport + ProtocolFactory thrift.ProtocolFactory + InputProtocol thrift.Protocol + OutputProtocol thrift.Protocol + SeqId int32 + Mu sync.Mutex +} + +func NewGraphServiceThreadsafeClientFactory(t thrift.Transport, f thrift.ProtocolFactory) *GraphServiceThreadsafeClient { + return &GraphServiceThreadsafeClient{Transport: t, + ProtocolFactory: f, + InputProtocol: f.GetProtocol(t), + OutputProtocol: f.GetProtocol(t), + SeqId: 0, + } +} + +func NewGraphServiceThreadsafeClient(t thrift.Transport, iprot thrift.Protocol, oprot thrift.Protocol) *GraphServiceThreadsafeClient { + return &GraphServiceThreadsafeClient{Transport: t, + ProtocolFactory: nil, + InputProtocol: iprot, + OutputProtocol: oprot, + SeqId: 0, + } +} + +func (p *GraphServiceThreadsafeClient) Threadsafe() {} + +// Parameters: +// - Username +// - Password +func (p *GraphServiceThreadsafeClient) Authenticate(username []byte, password []byte) (r *AuthResponse, err error) { + p.Mu.Lock() + defer p.Mu.Unlock() + if err = p.sendAuthenticate(username, password); err != nil { return } + return p.recvAuthenticate() +} + +func (p *GraphServiceThreadsafeClient) sendAuthenticate(username []byte, password []byte)(err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("authenticate", thrift.CALL, p.SeqId); err != nil { + return + } + args := GraphServiceAuthenticateArgs{ + Username : username, + Password : password, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + + +func (p *GraphServiceThreadsafeClient) recvAuthenticate() (value *AuthResponse, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + method, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if method != "authenticate" { + err = thrift.NewApplicationException(thrift.WRONG_METHOD_NAME, "authenticate failed: wrong method name") + return + } + if p.SeqId != seqId { + err = thrift.NewApplicationException(thrift.BAD_SEQUENCE_ID, "authenticate failed: out of sequence response") + return + } + if mTypeId == thrift.EXCEPTION { + error15 := thrift.NewApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error16 error + error16, err = error15.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error16 + return + } + if mTypeId != thrift.REPLY { + err = thrift.NewApplicationException(thrift.INVALID_MESSAGE_TYPE_EXCEPTION, "authenticate failed: invalid message type") + return + } + result := GraphServiceAuthenticateResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + value = result.GetSuccess() + return +} + +// Parameters: +// - SessionId +func (p *GraphServiceThreadsafeClient) Signout(sessionId int64) (err error) { + p.Mu.Lock() + defer p.Mu.Unlock() + if err = p.sendSignout(sessionId); err != nil { return } + return +} + +func (p *GraphServiceThreadsafeClient) sendSignout(sessionId int64)(err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("signout", thrift.ONEWAY, p.SeqId); err != nil { + return + } + args := GraphServiceSignoutArgs{ + SessionId : sessionId, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +// Parameters: +// - SessionId +// - Stmt +func (p *GraphServiceThreadsafeClient) Execute(sessionId int64, stmt []byte) (r *ExecutionResponse, err error) { + p.Mu.Lock() + defer p.Mu.Unlock() + if err = p.sendExecute(sessionId, stmt); err != nil { return } + return p.recvExecute() +} + +func (p *GraphServiceThreadsafeClient) sendExecute(sessionId int64, stmt []byte)(err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("execute", thrift.CALL, p.SeqId); err != nil { + return + } + args := GraphServiceExecuteArgs{ + SessionId : sessionId, + Stmt : stmt, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + + +func (p *GraphServiceThreadsafeClient) recvExecute() (value *ExecutionResponse, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + method, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if method != "execute" { + err = thrift.NewApplicationException(thrift.WRONG_METHOD_NAME, "execute failed: wrong method name") + return + } + if p.SeqId != seqId { + err = thrift.NewApplicationException(thrift.BAD_SEQUENCE_ID, "execute failed: out of sequence response") + return + } + if mTypeId == thrift.EXCEPTION { + error17 := thrift.NewApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error18 error + error18, err = error17.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error18 + return + } + if mTypeId != thrift.REPLY { + err = thrift.NewApplicationException(thrift.INVALID_MESSAGE_TYPE_EXCEPTION, "execute failed: invalid message type") + return + } + result := GraphServiceExecuteResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + value = result.GetSuccess() + return +} + +// Parameters: +// - SessionId +// - Stmt +func (p *GraphServiceThreadsafeClient) ExecuteJson(sessionId int64, stmt []byte) (r []byte, err error) { + p.Mu.Lock() + defer p.Mu.Unlock() + if err = p.sendExecuteJson(sessionId, stmt); err != nil { return } + return p.recvExecuteJson() +} + +func (p *GraphServiceThreadsafeClient) sendExecuteJson(sessionId int64, stmt []byte)(err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("executeJson", thrift.CALL, p.SeqId); err != nil { + return + } + args := GraphServiceExecuteJsonArgs{ + SessionId : sessionId, + Stmt : stmt, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + + +func (p *GraphServiceThreadsafeClient) recvExecuteJson() (value []byte, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + method, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if method != "executeJson" { + err = thrift.NewApplicationException(thrift.WRONG_METHOD_NAME, "executeJson failed: wrong method name") + return + } + if p.SeqId != seqId { + err = thrift.NewApplicationException(thrift.BAD_SEQUENCE_ID, "executeJson failed: out of sequence response") + return + } + if mTypeId == thrift.EXCEPTION { + error19 := thrift.NewApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error20 error + error20, err = error19.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error20 + return + } + if mTypeId != thrift.REPLY { + err = thrift.NewApplicationException(thrift.INVALID_MESSAGE_TYPE_EXCEPTION, "executeJson failed: invalid message type") + return + } + result := GraphServiceExecuteJsonResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + value = result.GetSuccess() + return +} + + +type GraphServiceProcessor struct { + processorMap map[string]thrift.ProcessorFunction + handler GraphService +} + +func (p *GraphServiceProcessor) AddToProcessorMap(key string, processor thrift.ProcessorFunction) { + p.processorMap[key] = processor +} + +func (p *GraphServiceProcessor) GetProcessorFunction(key string) (processor thrift.ProcessorFunction, err error) { + if processor, ok := p.processorMap[key]; ok { + return processor, nil + } + return nil, nil // generic error message will be sent +} + +func (p *GraphServiceProcessor) ProcessorMap() map[string]thrift.ProcessorFunction { + return p.processorMap +} + +func NewGraphServiceProcessor(handler GraphService) *GraphServiceProcessor { + self21 := &GraphServiceProcessor{handler:handler, processorMap:make(map[string]thrift.ProcessorFunction)} + self21.processorMap["authenticate"] = &graphServiceProcessorAuthenticate{handler:handler} + self21.processorMap["signout"] = &graphServiceProcessorSignout{handler:handler} + self21.processorMap["execute"] = &graphServiceProcessorExecute{handler:handler} + self21.processorMap["executeJson"] = &graphServiceProcessorExecuteJson{handler:handler} + return self21 +} + +type graphServiceProcessorAuthenticate struct { + handler GraphService +} + +func (p *graphServiceProcessorAuthenticate) Read(iprot thrift.Protocol) (thrift.Struct, thrift.Exception) { + args := GraphServiceAuthenticateArgs{} + if err := args.Read(iprot); err != nil { + return nil, err + } + iprot.ReadMessageEnd() + return &args, nil +} + +func (p *graphServiceProcessorAuthenticate) Write(seqId int32, result thrift.WritableStruct, oprot thrift.Protocol) (err thrift.Exception) { + var err2 error + messageType := thrift.REPLY + switch result.(type) { + case thrift.ApplicationException: + messageType = thrift.EXCEPTION + } + if err2 = oprot.WriteMessageBegin("authenticate", messageType, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + return err +} + +func (p *graphServiceProcessorAuthenticate) Run(argStruct thrift.Struct) (thrift.WritableStruct, thrift.ApplicationException) { + args := argStruct.(*GraphServiceAuthenticateArgs) + var result GraphServiceAuthenticateResult + if retval, err := p.handler.Authenticate(args.Username, args.Password); err != nil { + switch err.(type) { + default: + x := thrift.NewApplicationException(thrift.INTERNAL_ERROR, "Internal error processing authenticate: " + err.Error()) + return x, x + } + } else { + result.Success = retval + } + return &result, nil +} + +type graphServiceProcessorSignout struct { + handler GraphService +} + +func (p *graphServiceProcessorSignout) Read(iprot thrift.Protocol) (thrift.Struct, thrift.Exception) { + args := GraphServiceSignoutArgs{} + if err := args.Read(iprot); err != nil { + return nil, err + } + iprot.ReadMessageEnd() + return &args, nil +} + +func (p *graphServiceProcessorSignout) Write(seqId int32, result thrift.WritableStruct, oprot thrift.Protocol) (err thrift.Exception) { + var err2 error + messageType := thrift.REPLY + switch result.(type) { + case thrift.ApplicationException: + messageType = thrift.EXCEPTION + } + if err2 = oprot.WriteMessageBegin("signout", messageType, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + return err +} + +func (p *graphServiceProcessorSignout) Run(argStruct thrift.Struct) (thrift.WritableStruct, thrift.ApplicationException) { + args := argStruct.(*GraphServiceSignoutArgs) + if err := p.handler.Signout(args.SessionId); err != nil { + switch err.(type) { + default: + x := thrift.NewApplicationException(thrift.INTERNAL_ERROR, "Internal error processing signout: " + err.Error()) + return x, x + } + } + return nil, nil +} + +type graphServiceProcessorExecute struct { + handler GraphService +} + +func (p *graphServiceProcessorExecute) Read(iprot thrift.Protocol) (thrift.Struct, thrift.Exception) { + args := GraphServiceExecuteArgs{} + if err := args.Read(iprot); err != nil { + return nil, err + } + iprot.ReadMessageEnd() + return &args, nil +} + +func (p *graphServiceProcessorExecute) Write(seqId int32, result thrift.WritableStruct, oprot thrift.Protocol) (err thrift.Exception) { + var err2 error + messageType := thrift.REPLY + switch result.(type) { + case thrift.ApplicationException: + messageType = thrift.EXCEPTION + } + if err2 = oprot.WriteMessageBegin("execute", messageType, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + return err +} + +func (p *graphServiceProcessorExecute) Run(argStruct thrift.Struct) (thrift.WritableStruct, thrift.ApplicationException) { + args := argStruct.(*GraphServiceExecuteArgs) + var result GraphServiceExecuteResult + if retval, err := p.handler.Execute(args.SessionId, args.Stmt); err != nil { + switch err.(type) { + default: + x := thrift.NewApplicationException(thrift.INTERNAL_ERROR, "Internal error processing execute: " + err.Error()) + return x, x + } + } else { + result.Success = retval + } + return &result, nil +} + +type graphServiceProcessorExecuteJson struct { + handler GraphService +} + +func (p *graphServiceProcessorExecuteJson) Read(iprot thrift.Protocol) (thrift.Struct, thrift.Exception) { + args := GraphServiceExecuteJsonArgs{} + if err := args.Read(iprot); err != nil { + return nil, err + } + iprot.ReadMessageEnd() + return &args, nil +} + +func (p *graphServiceProcessorExecuteJson) Write(seqId int32, result thrift.WritableStruct, oprot thrift.Protocol) (err thrift.Exception) { + var err2 error + messageType := thrift.REPLY + switch result.(type) { + case thrift.ApplicationException: + messageType = thrift.EXCEPTION + } + if err2 = oprot.WriteMessageBegin("executeJson", messageType, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + return err +} + +func (p *graphServiceProcessorExecuteJson) Run(argStruct thrift.Struct) (thrift.WritableStruct, thrift.ApplicationException) { + args := argStruct.(*GraphServiceExecuteJsonArgs) + var result GraphServiceExecuteJsonResult + if retval, err := p.handler.ExecuteJson(args.SessionId, args.Stmt); err != nil { + switch err.(type) { + default: + x := thrift.NewApplicationException(thrift.INTERNAL_ERROR, "Internal error processing executeJson: " + err.Error()) + return x, x + } + } else { + result.Success = retval + } + return &result, nil +} + + +// HELPER FUNCTIONS AND STRUCTURES + +// Attributes: +// - Username +// - Password +type GraphServiceAuthenticateArgs struct { + Username []byte `thrift:"username,1" db:"username" json:"username"` + Password []byte `thrift:"password,2" db:"password" json:"password"` +} + +func NewGraphServiceAuthenticateArgs() *GraphServiceAuthenticateArgs { + return &GraphServiceAuthenticateArgs{} +} + + +func (p *GraphServiceAuthenticateArgs) GetUsername() []byte { + return p.Username +} + +func (p *GraphServiceAuthenticateArgs) GetPassword() []byte { + return p.Password +} +func (p *GraphServiceAuthenticateArgs) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *GraphServiceAuthenticateArgs) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + p.Username = v +} + return nil +} + +func (p *GraphServiceAuthenticateArgs) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + p.Password = v +} + return nil +} + +func (p *GraphServiceAuthenticateArgs) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("authenticate_args"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *GraphServiceAuthenticateArgs) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("username", thrift.STRING, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:username: ", p), err) } + if err := oprot.WriteBinary(p.Username); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.username (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:username: ", p), err) } + return err +} + +func (p *GraphServiceAuthenticateArgs) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("password", thrift.STRING, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:password: ", p), err) } + if err := oprot.WriteBinary(p.Password); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.password (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:password: ", p), err) } + return err +} + +func (p *GraphServiceAuthenticateArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GraphServiceAuthenticateArgs(%+v)", *p) +} + +// Attributes: +// - Success +type GraphServiceAuthenticateResult struct { + Success *AuthResponse `thrift:"success,0" db:"success" json:"success,omitempty"` +} + +func NewGraphServiceAuthenticateResult() *GraphServiceAuthenticateResult { + return &GraphServiceAuthenticateResult{} +} + +var GraphServiceAuthenticateResult_Success_DEFAULT *AuthResponse +func (p *GraphServiceAuthenticateResult) GetSuccess() *AuthResponse { + if !p.IsSetSuccess() { + return GraphServiceAuthenticateResult_Success_DEFAULT + } +return p.Success +} +func (p *GraphServiceAuthenticateResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GraphServiceAuthenticateResult) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *GraphServiceAuthenticateResult) ReadField0(iprot thrift.Protocol) error { + p.Success = NewAuthResponse() + if err := p.Success.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Success), err) + } + return nil +} + +func (p *GraphServiceAuthenticateResult) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("authenticate_result"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField0(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *GraphServiceAuthenticateResult) writeField0(oprot thrift.Protocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err) } + if err := p.Success.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Success), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err) } + } + return err +} + +func (p *GraphServiceAuthenticateResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GraphServiceAuthenticateResult(%+v)", *p) +} + +// Attributes: +// - SessionId +type GraphServiceSignoutArgs struct { + SessionId int64 `thrift:"sessionId,1" db:"sessionId" json:"sessionId"` +} + +func NewGraphServiceSignoutArgs() *GraphServiceSignoutArgs { + return &GraphServiceSignoutArgs{} +} + + +func (p *GraphServiceSignoutArgs) GetSessionId() int64 { + return p.SessionId +} +func (p *GraphServiceSignoutArgs) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *GraphServiceSignoutArgs) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + p.SessionId = v +} + return nil +} + +func (p *GraphServiceSignoutArgs) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("signout_args"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *GraphServiceSignoutArgs) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("sessionId", thrift.I64, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:sessionId: ", p), err) } + if err := oprot.WriteI64(int64(p.SessionId)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.sessionId (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:sessionId: ", p), err) } + return err +} + +func (p *GraphServiceSignoutArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GraphServiceSignoutArgs(%+v)", *p) +} + +// Attributes: +// - SessionId +// - Stmt +type GraphServiceExecuteArgs struct { + SessionId int64 `thrift:"sessionId,1" db:"sessionId" json:"sessionId"` + Stmt []byte `thrift:"stmt,2" db:"stmt" json:"stmt"` +} + +func NewGraphServiceExecuteArgs() *GraphServiceExecuteArgs { + return &GraphServiceExecuteArgs{} +} + + +func (p *GraphServiceExecuteArgs) GetSessionId() int64 { + return p.SessionId +} + +func (p *GraphServiceExecuteArgs) GetStmt() []byte { + return p.Stmt +} +func (p *GraphServiceExecuteArgs) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *GraphServiceExecuteArgs) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + p.SessionId = v +} + return nil +} + +func (p *GraphServiceExecuteArgs) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + p.Stmt = v +} + return nil +} + +func (p *GraphServiceExecuteArgs) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("execute_args"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *GraphServiceExecuteArgs) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("sessionId", thrift.I64, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:sessionId: ", p), err) } + if err := oprot.WriteI64(int64(p.SessionId)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.sessionId (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:sessionId: ", p), err) } + return err +} + +func (p *GraphServiceExecuteArgs) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("stmt", thrift.STRING, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:stmt: ", p), err) } + if err := oprot.WriteBinary(p.Stmt); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.stmt (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:stmt: ", p), err) } + return err +} + +func (p *GraphServiceExecuteArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GraphServiceExecuteArgs(%+v)", *p) +} + +// Attributes: +// - Success +type GraphServiceExecuteResult struct { + Success *ExecutionResponse `thrift:"success,0" db:"success" json:"success,omitempty"` +} + +func NewGraphServiceExecuteResult() *GraphServiceExecuteResult { + return &GraphServiceExecuteResult{} +} + +var GraphServiceExecuteResult_Success_DEFAULT *ExecutionResponse +func (p *GraphServiceExecuteResult) GetSuccess() *ExecutionResponse { + if !p.IsSetSuccess() { + return GraphServiceExecuteResult_Success_DEFAULT + } +return p.Success +} +func (p *GraphServiceExecuteResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GraphServiceExecuteResult) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *GraphServiceExecuteResult) ReadField0(iprot thrift.Protocol) error { + p.Success = NewExecutionResponse() + if err := p.Success.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Success), err) + } + return nil +} + +func (p *GraphServiceExecuteResult) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("execute_result"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField0(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *GraphServiceExecuteResult) writeField0(oprot thrift.Protocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err) } + if err := p.Success.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Success), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err) } + } + return err +} + +func (p *GraphServiceExecuteResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GraphServiceExecuteResult(%+v)", *p) +} + +// Attributes: +// - SessionId +// - Stmt +type GraphServiceExecuteJsonArgs struct { + SessionId int64 `thrift:"sessionId,1" db:"sessionId" json:"sessionId"` + Stmt []byte `thrift:"stmt,2" db:"stmt" json:"stmt"` +} + +func NewGraphServiceExecuteJsonArgs() *GraphServiceExecuteJsonArgs { + return &GraphServiceExecuteJsonArgs{} +} + + +func (p *GraphServiceExecuteJsonArgs) GetSessionId() int64 { + return p.SessionId +} + +func (p *GraphServiceExecuteJsonArgs) GetStmt() []byte { + return p.Stmt +} +func (p *GraphServiceExecuteJsonArgs) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *GraphServiceExecuteJsonArgs) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + p.SessionId = v +} + return nil +} + +func (p *GraphServiceExecuteJsonArgs) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + p.Stmt = v +} + return nil +} + +func (p *GraphServiceExecuteJsonArgs) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("executeJson_args"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *GraphServiceExecuteJsonArgs) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("sessionId", thrift.I64, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:sessionId: ", p), err) } + if err := oprot.WriteI64(int64(p.SessionId)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.sessionId (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:sessionId: ", p), err) } + return err +} + +func (p *GraphServiceExecuteJsonArgs) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("stmt", thrift.STRING, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:stmt: ", p), err) } + if err := oprot.WriteBinary(p.Stmt); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.stmt (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:stmt: ", p), err) } + return err +} + +func (p *GraphServiceExecuteJsonArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GraphServiceExecuteJsonArgs(%+v)", *p) +} + +// Attributes: +// - Success +type GraphServiceExecuteJsonResult struct { + Success []byte `thrift:"success,0" db:"success" json:"success,omitempty"` +} + +func NewGraphServiceExecuteJsonResult() *GraphServiceExecuteJsonResult { + return &GraphServiceExecuteJsonResult{} +} + +var GraphServiceExecuteJsonResult_Success_DEFAULT []byte + +func (p *GraphServiceExecuteJsonResult) GetSuccess() []byte { + return p.Success +} +func (p *GraphServiceExecuteJsonResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GraphServiceExecuteJsonResult) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *GraphServiceExecuteJsonResult) ReadField0(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 0: ", err) +} else { + p.Success = v +} + return nil +} + +func (p *GraphServiceExecuteJsonResult) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("executeJson_result"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField0(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *GraphServiceExecuteJsonResult) writeField0(oprot thrift.Protocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.STRING, 0); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err) } + if err := oprot.WriteBinary(p.Success); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.success (0) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err) } + } + return err +} + +func (p *GraphServiceExecuteJsonResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GraphServiceExecuteJsonResult(%+v)", *p) +} + + diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/graph/ttypes.go b/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/graph/ttypes.go new file mode 100644 index 000000000..92b23d858 --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/graph/ttypes.go @@ -0,0 +1,1654 @@ +// Autogenerated by Thrift Compiler (facebook) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +// @generated + +package graph + +import ( + "bytes" + "sync" + "fmt" + thrift "github.com/facebook/fbthrift/thrift/lib/go/thrift" + nebula0 "github.com/vesoft-inc/nebula-go/v2/nebula" + +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = sync.Mutex{} +var _ = bytes.Equal + +var _ = nebula0.GoUnusedProtection__ +var GoUnusedProtection__ int; + +type ErrorCode int64 +const ( + ErrorCode_SUCCEEDED ErrorCode = 0 + ErrorCode_E_DISCONNECTED ErrorCode = -1 + ErrorCode_E_FAIL_TO_CONNECT ErrorCode = -2 + ErrorCode_E_RPC_FAILURE ErrorCode = -3 + ErrorCode_E_BAD_USERNAME_PASSWORD ErrorCode = -4 + ErrorCode_E_SESSION_INVALID ErrorCode = -5 + ErrorCode_E_SESSION_TIMEOUT ErrorCode = -6 + ErrorCode_E_SYNTAX_ERROR ErrorCode = -7 + ErrorCode_E_EXECUTION_ERROR ErrorCode = -8 + ErrorCode_E_STATEMENT_EMPTY ErrorCode = -9 + ErrorCode_E_USER_NOT_FOUND ErrorCode = -10 + ErrorCode_E_BAD_PERMISSION ErrorCode = -11 + ErrorCode_E_SEMANTIC_ERROR ErrorCode = -12 + ErrorCode_E_TOO_MANY_CONNECTIONS ErrorCode = -13 + ErrorCode_E_PARTIAL_SUCCEEDED ErrorCode = -14 +) + +var ErrorCodeToName = map[ErrorCode]string { + ErrorCode_SUCCEEDED: "SUCCEEDED", + ErrorCode_E_DISCONNECTED: "E_DISCONNECTED", + ErrorCode_E_FAIL_TO_CONNECT: "E_FAIL_TO_CONNECT", + ErrorCode_E_RPC_FAILURE: "E_RPC_FAILURE", + ErrorCode_E_BAD_USERNAME_PASSWORD: "E_BAD_USERNAME_PASSWORD", + ErrorCode_E_SESSION_INVALID: "E_SESSION_INVALID", + ErrorCode_E_SESSION_TIMEOUT: "E_SESSION_TIMEOUT", + ErrorCode_E_SYNTAX_ERROR: "E_SYNTAX_ERROR", + ErrorCode_E_EXECUTION_ERROR: "E_EXECUTION_ERROR", + ErrorCode_E_STATEMENT_EMPTY: "E_STATEMENT_EMPTY", + ErrorCode_E_USER_NOT_FOUND: "E_USER_NOT_FOUND", + ErrorCode_E_BAD_PERMISSION: "E_BAD_PERMISSION", + ErrorCode_E_SEMANTIC_ERROR: "E_SEMANTIC_ERROR", + ErrorCode_E_TOO_MANY_CONNECTIONS: "E_TOO_MANY_CONNECTIONS", + ErrorCode_E_PARTIAL_SUCCEEDED: "E_PARTIAL_SUCCEEDED", +} + +var ErrorCodeToValue = map[string]ErrorCode { + "SUCCEEDED": ErrorCode_SUCCEEDED, + "E_DISCONNECTED": ErrorCode_E_DISCONNECTED, + "E_FAIL_TO_CONNECT": ErrorCode_E_FAIL_TO_CONNECT, + "E_RPC_FAILURE": ErrorCode_E_RPC_FAILURE, + "E_BAD_USERNAME_PASSWORD": ErrorCode_E_BAD_USERNAME_PASSWORD, + "E_SESSION_INVALID": ErrorCode_E_SESSION_INVALID, + "E_SESSION_TIMEOUT": ErrorCode_E_SESSION_TIMEOUT, + "E_SYNTAX_ERROR": ErrorCode_E_SYNTAX_ERROR, + "E_EXECUTION_ERROR": ErrorCode_E_EXECUTION_ERROR, + "E_STATEMENT_EMPTY": ErrorCode_E_STATEMENT_EMPTY, + "E_USER_NOT_FOUND": ErrorCode_E_USER_NOT_FOUND, + "E_BAD_PERMISSION": ErrorCode_E_BAD_PERMISSION, + "E_SEMANTIC_ERROR": ErrorCode_E_SEMANTIC_ERROR, + "E_TOO_MANY_CONNECTIONS": ErrorCode_E_TOO_MANY_CONNECTIONS, + "E_PARTIAL_SUCCEEDED": ErrorCode_E_PARTIAL_SUCCEEDED, +} + +func (p ErrorCode) String() string { + if v, ok := ErrorCodeToName[p]; ok { + return v + } + return "" +} + +func ErrorCodeFromString(s string) (ErrorCode, error) { + if v, ok := ErrorCodeToValue[s]; ok { + return v, nil + } + return ErrorCode(0), fmt.Errorf("not a valid ErrorCode string") +} + +func ErrorCodePtr(v ErrorCode) *ErrorCode { return &v } + +// Attributes: +// - Rows +// - ExecDurationInUs +// - TotalDurationInUs +// - OtherStats +type ProfilingStats struct { + Rows int64 `thrift:"rows,1,required" db:"rows" json:"rows"` + ExecDurationInUs int64 `thrift:"exec_duration_in_us,2,required" db:"exec_duration_in_us" json:"exec_duration_in_us"` + TotalDurationInUs int64 `thrift:"total_duration_in_us,3,required" db:"total_duration_in_us" json:"total_duration_in_us"` + OtherStats map[string][]byte `thrift:"other_stats,4" db:"other_stats" json:"other_stats,omitempty"` +} + +func NewProfilingStats() *ProfilingStats { + return &ProfilingStats{} +} + + +func (p *ProfilingStats) GetRows() int64 { + return p.Rows +} + +func (p *ProfilingStats) GetExecDurationInUs() int64 { + return p.ExecDurationInUs +} + +func (p *ProfilingStats) GetTotalDurationInUs() int64 { + return p.TotalDurationInUs +} +var ProfilingStats_OtherStats_DEFAULT map[string][]byte + +func (p *ProfilingStats) GetOtherStats() map[string][]byte { + return p.OtherStats +} +func (p *ProfilingStats) IsSetOtherStats() bool { + return p.OtherStats != nil +} + +func (p *ProfilingStats) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + var issetRows bool = false; + var issetExecDurationInUs bool = false; + var issetTotalDurationInUs bool = false; + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + issetRows = true + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + issetExecDurationInUs = true + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + issetTotalDurationInUs = true + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + if !issetRows{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Rows is not set")); + } + if !issetExecDurationInUs{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field ExecDurationInUs is not set")); + } + if !issetTotalDurationInUs{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field TotalDurationInUs is not set")); + } + return nil +} + +func (p *ProfilingStats) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + p.Rows = v +} + return nil +} + +func (p *ProfilingStats) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + p.ExecDurationInUs = v +} + return nil +} + +func (p *ProfilingStats) ReadField3(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 3: ", err) +} else { + p.TotalDurationInUs = v +} + return nil +} + +func (p *ProfilingStats) ReadField4(iprot thrift.Protocol) error { + _, _, size, err := iprot.ReadMapBegin() + if err != nil { + return thrift.PrependError("error reading map begin: ", err) + } + tMap := make(map[string][]byte, size) + p.OtherStats = tMap + for i := 0; i < size; i ++ { +var _key1 string + if v, err := iprot.ReadString(); err != nil { + return thrift.PrependError("error reading field 0: ", err) +} else { + _key1 = v +} +var _val2 []byte + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 0: ", err) +} else { + _val2 = v +} + p.OtherStats[_key1] = _val2 + } + if err := iprot.ReadMapEnd(); err != nil { + return thrift.PrependError("error reading map end: ", err) + } + return nil +} + +func (p *ProfilingStats) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("ProfilingStats"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := p.writeField3(oprot); err != nil { return err } + if err := p.writeField4(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *ProfilingStats) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("rows", thrift.I64, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:rows: ", p), err) } + if err := oprot.WriteI64(int64(p.Rows)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.rows (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:rows: ", p), err) } + return err +} + +func (p *ProfilingStats) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("exec_duration_in_us", thrift.I64, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:exec_duration_in_us: ", p), err) } + if err := oprot.WriteI64(int64(p.ExecDurationInUs)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.exec_duration_in_us (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:exec_duration_in_us: ", p), err) } + return err +} + +func (p *ProfilingStats) writeField3(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("total_duration_in_us", thrift.I64, 3); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:total_duration_in_us: ", p), err) } + if err := oprot.WriteI64(int64(p.TotalDurationInUs)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.total_duration_in_us (3) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 3:total_duration_in_us: ", p), err) } + return err +} + +func (p *ProfilingStats) writeField4(oprot thrift.Protocol) (err error) { + if p.IsSetOtherStats() { + if err := oprot.WriteFieldBegin("other_stats", thrift.MAP, 4); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:other_stats: ", p), err) } + if err := oprot.WriteMapBegin(thrift.STRING, thrift.STRING, len(p.OtherStats)); err != nil { + return thrift.PrependError("error writing map begin: ", err) + } + for k, v := range p.OtherStats { + if err := oprot.WriteString(string(k)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err) } + if err := oprot.WriteBinary(v); err != nil { + return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err) } + } + if err := oprot.WriteMapEnd(); err != nil { + return thrift.PrependError("error writing map end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 4:other_stats: ", p), err) } + } + return err +} + +func (p *ProfilingStats) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("ProfilingStats(%+v)", *p) +} + +// Attributes: +// - IsDoBranch +// - ConditionNodeID +type PlanNodeBranchInfo struct { + IsDoBranch bool `thrift:"is_do_branch,1,required" db:"is_do_branch" json:"is_do_branch"` + ConditionNodeID int64 `thrift:"condition_node_id,2,required" db:"condition_node_id" json:"condition_node_id"` +} + +func NewPlanNodeBranchInfo() *PlanNodeBranchInfo { + return &PlanNodeBranchInfo{} +} + + +func (p *PlanNodeBranchInfo) GetIsDoBranch() bool { + return p.IsDoBranch +} + +func (p *PlanNodeBranchInfo) GetConditionNodeID() int64 { + return p.ConditionNodeID +} +func (p *PlanNodeBranchInfo) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + var issetIsDoBranch bool = false; + var issetConditionNodeID bool = false; + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + issetIsDoBranch = true + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + issetConditionNodeID = true + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + if !issetIsDoBranch{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field IsDoBranch is not set")); + } + if !issetConditionNodeID{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field ConditionNodeID is not set")); + } + return nil +} + +func (p *PlanNodeBranchInfo) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadBool(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + p.IsDoBranch = v +} + return nil +} + +func (p *PlanNodeBranchInfo) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + p.ConditionNodeID = v +} + return nil +} + +func (p *PlanNodeBranchInfo) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("PlanNodeBranchInfo"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *PlanNodeBranchInfo) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("is_do_branch", thrift.BOOL, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:is_do_branch: ", p), err) } + if err := oprot.WriteBool(bool(p.IsDoBranch)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.is_do_branch (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:is_do_branch: ", p), err) } + return err +} + +func (p *PlanNodeBranchInfo) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("condition_node_id", thrift.I64, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:condition_node_id: ", p), err) } + if err := oprot.WriteI64(int64(p.ConditionNodeID)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.condition_node_id (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:condition_node_id: ", p), err) } + return err +} + +func (p *PlanNodeBranchInfo) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("PlanNodeBranchInfo(%+v)", *p) +} + +// Attributes: +// - Key +// - Value +type Pair struct { + Key []byte `thrift:"key,1,required" db:"key" json:"key"` + Value []byte `thrift:"value,2,required" db:"value" json:"value"` +} + +func NewPair() *Pair { + return &Pair{} +} + + +func (p *Pair) GetKey() []byte { + return p.Key +} + +func (p *Pair) GetValue() []byte { + return p.Value +} +func (p *Pair) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + var issetKey bool = false; + var issetValue bool = false; + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + issetKey = true + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + issetValue = true + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + if !issetKey{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Key is not set")); + } + if !issetValue{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Value is not set")); + } + return nil +} + +func (p *Pair) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + p.Key = v +} + return nil +} + +func (p *Pair) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + p.Value = v +} + return nil +} + +func (p *Pair) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("Pair"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *Pair) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("key", thrift.STRING, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:key: ", p), err) } + if err := oprot.WriteBinary(p.Key); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.key (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:key: ", p), err) } + return err +} + +func (p *Pair) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("value", thrift.STRING, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:value: ", p), err) } + if err := oprot.WriteBinary(p.Value); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.value (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:value: ", p), err) } + return err +} + +func (p *Pair) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Pair(%+v)", *p) +} + +// Attributes: +// - Name +// - Id +// - OutputVar +// - Description +// - Profiles +// - BranchInfo +// - Dependencies +type PlanNodeDescription struct { + Name []byte `thrift:"name,1,required" db:"name" json:"name"` + Id int64 `thrift:"id,2,required" db:"id" json:"id"` + OutputVar []byte `thrift:"output_var,3,required" db:"output_var" json:"output_var"` + Description []*Pair `thrift:"description,4" db:"description" json:"description,omitempty"` + Profiles []*ProfilingStats `thrift:"profiles,5" db:"profiles" json:"profiles,omitempty"` + BranchInfo *PlanNodeBranchInfo `thrift:"branch_info,6" db:"branch_info" json:"branch_info,omitempty"` + Dependencies []int64 `thrift:"dependencies,7" db:"dependencies" json:"dependencies,omitempty"` +} + +func NewPlanNodeDescription() *PlanNodeDescription { + return &PlanNodeDescription{} +} + + +func (p *PlanNodeDescription) GetName() []byte { + return p.Name +} + +func (p *PlanNodeDescription) GetId() int64 { + return p.Id +} + +func (p *PlanNodeDescription) GetOutputVar() []byte { + return p.OutputVar +} +var PlanNodeDescription_Description_DEFAULT []*Pair + +func (p *PlanNodeDescription) GetDescription() []*Pair { + return p.Description +} +var PlanNodeDescription_Profiles_DEFAULT []*ProfilingStats + +func (p *PlanNodeDescription) GetProfiles() []*ProfilingStats { + return p.Profiles +} +var PlanNodeDescription_BranchInfo_DEFAULT *PlanNodeBranchInfo +func (p *PlanNodeDescription) GetBranchInfo() *PlanNodeBranchInfo { + if !p.IsSetBranchInfo() { + return PlanNodeDescription_BranchInfo_DEFAULT + } +return p.BranchInfo +} +var PlanNodeDescription_Dependencies_DEFAULT []int64 + +func (p *PlanNodeDescription) GetDependencies() []int64 { + return p.Dependencies +} +func (p *PlanNodeDescription) IsSetDescription() bool { + return p.Description != nil +} + +func (p *PlanNodeDescription) IsSetProfiles() bool { + return p.Profiles != nil +} + +func (p *PlanNodeDescription) IsSetBranchInfo() bool { + return p.BranchInfo != nil +} + +func (p *PlanNodeDescription) IsSetDependencies() bool { + return p.Dependencies != nil +} + +func (p *PlanNodeDescription) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + var issetName bool = false; + var issetId bool = false; + var issetOutputVar bool = false; + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + issetName = true + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + issetId = true + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + issetOutputVar = true + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + case 5: + if err := p.ReadField5(iprot); err != nil { + return err + } + case 6: + if err := p.ReadField6(iprot); err != nil { + return err + } + case 7: + if err := p.ReadField7(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + if !issetName{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Name is not set")); + } + if !issetId{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Id is not set")); + } + if !issetOutputVar{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field OutputVar is not set")); + } + return nil +} + +func (p *PlanNodeDescription) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + p.Name = v +} + return nil +} + +func (p *PlanNodeDescription) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + p.Id = v +} + return nil +} + +func (p *PlanNodeDescription) ReadField3(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 3: ", err) +} else { + p.OutputVar = v +} + return nil +} + +func (p *PlanNodeDescription) ReadField4(iprot thrift.Protocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return thrift.PrependError("error reading list begin: ", err) + } + tSlice := make([]*Pair, 0, size) + p.Description = tSlice + for i := 0; i < size; i ++ { + _elem3 := NewPair() + if err := _elem3.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem3), err) + } + p.Description = append(p.Description, _elem3) + } + if err := iprot.ReadListEnd(); err != nil { + return thrift.PrependError("error reading list end: ", err) + } + return nil +} + +func (p *PlanNodeDescription) ReadField5(iprot thrift.Protocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return thrift.PrependError("error reading list begin: ", err) + } + tSlice := make([]*ProfilingStats, 0, size) + p.Profiles = tSlice + for i := 0; i < size; i ++ { + _elem4 := NewProfilingStats() + if err := _elem4.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem4), err) + } + p.Profiles = append(p.Profiles, _elem4) + } + if err := iprot.ReadListEnd(); err != nil { + return thrift.PrependError("error reading list end: ", err) + } + return nil +} + +func (p *PlanNodeDescription) ReadField6(iprot thrift.Protocol) error { + p.BranchInfo = NewPlanNodeBranchInfo() + if err := p.BranchInfo.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.BranchInfo), err) + } + return nil +} + +func (p *PlanNodeDescription) ReadField7(iprot thrift.Protocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return thrift.PrependError("error reading list begin: ", err) + } + tSlice := make([]int64, 0, size) + p.Dependencies = tSlice + for i := 0; i < size; i ++ { +var _elem5 int64 + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 0: ", err) +} else { + _elem5 = v +} + p.Dependencies = append(p.Dependencies, _elem5) + } + if err := iprot.ReadListEnd(); err != nil { + return thrift.PrependError("error reading list end: ", err) + } + return nil +} + +func (p *PlanNodeDescription) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("PlanNodeDescription"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := p.writeField3(oprot); err != nil { return err } + if err := p.writeField4(oprot); err != nil { return err } + if err := p.writeField5(oprot); err != nil { return err } + if err := p.writeField6(oprot); err != nil { return err } + if err := p.writeField7(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *PlanNodeDescription) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("name", thrift.STRING, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:name: ", p), err) } + if err := oprot.WriteBinary(p.Name); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.name (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:name: ", p), err) } + return err +} + +func (p *PlanNodeDescription) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("id", thrift.I64, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:id: ", p), err) } + if err := oprot.WriteI64(int64(p.Id)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.id (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:id: ", p), err) } + return err +} + +func (p *PlanNodeDescription) writeField3(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("output_var", thrift.STRING, 3); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:output_var: ", p), err) } + if err := oprot.WriteBinary(p.OutputVar); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.output_var (3) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 3:output_var: ", p), err) } + return err +} + +func (p *PlanNodeDescription) writeField4(oprot thrift.Protocol) (err error) { + if p.IsSetDescription() { + if err := oprot.WriteFieldBegin("description", thrift.LIST, 4); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:description: ", p), err) } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Description)); err != nil { + return thrift.PrependError("error writing list begin: ", err) + } + for _, v := range p.Description { + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return thrift.PrependError("error writing list end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 4:description: ", p), err) } + } + return err +} + +func (p *PlanNodeDescription) writeField5(oprot thrift.Protocol) (err error) { + if p.IsSetProfiles() { + if err := oprot.WriteFieldBegin("profiles", thrift.LIST, 5); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 5:profiles: ", p), err) } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Profiles)); err != nil { + return thrift.PrependError("error writing list begin: ", err) + } + for _, v := range p.Profiles { + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return thrift.PrependError("error writing list end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 5:profiles: ", p), err) } + } + return err +} + +func (p *PlanNodeDescription) writeField6(oprot thrift.Protocol) (err error) { + if p.IsSetBranchInfo() { + if err := oprot.WriteFieldBegin("branch_info", thrift.STRUCT, 6); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 6:branch_info: ", p), err) } + if err := p.BranchInfo.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.BranchInfo), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 6:branch_info: ", p), err) } + } + return err +} + +func (p *PlanNodeDescription) writeField7(oprot thrift.Protocol) (err error) { + if p.IsSetDependencies() { + if err := oprot.WriteFieldBegin("dependencies", thrift.LIST, 7); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 7:dependencies: ", p), err) } + if err := oprot.WriteListBegin(thrift.I64, len(p.Dependencies)); err != nil { + return thrift.PrependError("error writing list begin: ", err) + } + for _, v := range p.Dependencies { + if err := oprot.WriteI64(int64(v)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err) } + } + if err := oprot.WriteListEnd(); err != nil { + return thrift.PrependError("error writing list end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 7:dependencies: ", p), err) } + } + return err +} + +func (p *PlanNodeDescription) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("PlanNodeDescription(%+v)", *p) +} + +// Attributes: +// - PlanNodeDescs +// - NodeIndexMap +// - Format +// - OptimizeTimeInUs +type PlanDescription struct { + PlanNodeDescs []*PlanNodeDescription `thrift:"plan_node_descs,1,required" db:"plan_node_descs" json:"plan_node_descs"` + NodeIndexMap map[int64]int64 `thrift:"node_index_map,2,required" db:"node_index_map" json:"node_index_map"` + Format []byte `thrift:"format,3,required" db:"format" json:"format"` + OptimizeTimeInUs int32 `thrift:"optimize_time_in_us,4,required" db:"optimize_time_in_us" json:"optimize_time_in_us"` +} + +func NewPlanDescription() *PlanDescription { + return &PlanDescription{} +} + + +func (p *PlanDescription) GetPlanNodeDescs() []*PlanNodeDescription { + return p.PlanNodeDescs +} + +func (p *PlanDescription) GetNodeIndexMap() map[int64]int64 { + return p.NodeIndexMap +} + +func (p *PlanDescription) GetFormat() []byte { + return p.Format +} + +func (p *PlanDescription) GetOptimizeTimeInUs() int32 { + return p.OptimizeTimeInUs +} +func (p *PlanDescription) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + var issetPlanNodeDescs bool = false; + var issetNodeIndexMap bool = false; + var issetFormat bool = false; + var issetOptimizeTimeInUs bool = false; + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + issetPlanNodeDescs = true + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + issetNodeIndexMap = true + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + issetFormat = true + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + issetOptimizeTimeInUs = true + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + if !issetPlanNodeDescs{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field PlanNodeDescs is not set")); + } + if !issetNodeIndexMap{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field NodeIndexMap is not set")); + } + if !issetFormat{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Format is not set")); + } + if !issetOptimizeTimeInUs{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field OptimizeTimeInUs is not set")); + } + return nil +} + +func (p *PlanDescription) ReadField1(iprot thrift.Protocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return thrift.PrependError("error reading list begin: ", err) + } + tSlice := make([]*PlanNodeDescription, 0, size) + p.PlanNodeDescs = tSlice + for i := 0; i < size; i ++ { + _elem6 := NewPlanNodeDescription() + if err := _elem6.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem6), err) + } + p.PlanNodeDescs = append(p.PlanNodeDescs, _elem6) + } + if err := iprot.ReadListEnd(); err != nil { + return thrift.PrependError("error reading list end: ", err) + } + return nil +} + +func (p *PlanDescription) ReadField2(iprot thrift.Protocol) error { + _, _, size, err := iprot.ReadMapBegin() + if err != nil { + return thrift.PrependError("error reading map begin: ", err) + } + tMap := make(map[int64]int64, size) + p.NodeIndexMap = tMap + for i := 0; i < size; i ++ { +var _key7 int64 + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 0: ", err) +} else { + _key7 = v +} +var _val8 int64 + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 0: ", err) +} else { + _val8 = v +} + p.NodeIndexMap[_key7] = _val8 + } + if err := iprot.ReadMapEnd(); err != nil { + return thrift.PrependError("error reading map end: ", err) + } + return nil +} + +func (p *PlanDescription) ReadField3(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 3: ", err) +} else { + p.Format = v +} + return nil +} + +func (p *PlanDescription) ReadField4(iprot thrift.Protocol) error { + if v, err := iprot.ReadI32(); err != nil { + return thrift.PrependError("error reading field 4: ", err) +} else { + p.OptimizeTimeInUs = v +} + return nil +} + +func (p *PlanDescription) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("PlanDescription"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := p.writeField3(oprot); err != nil { return err } + if err := p.writeField4(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *PlanDescription) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("plan_node_descs", thrift.LIST, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:plan_node_descs: ", p), err) } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.PlanNodeDescs)); err != nil { + return thrift.PrependError("error writing list begin: ", err) + } + for _, v := range p.PlanNodeDescs { + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return thrift.PrependError("error writing list end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:plan_node_descs: ", p), err) } + return err +} + +func (p *PlanDescription) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("node_index_map", thrift.MAP, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:node_index_map: ", p), err) } + if err := oprot.WriteMapBegin(thrift.I64, thrift.I64, len(p.NodeIndexMap)); err != nil { + return thrift.PrependError("error writing map begin: ", err) + } + for k, v := range p.NodeIndexMap { + if err := oprot.WriteI64(int64(k)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err) } + if err := oprot.WriteI64(int64(v)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err) } + } + if err := oprot.WriteMapEnd(); err != nil { + return thrift.PrependError("error writing map end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:node_index_map: ", p), err) } + return err +} + +func (p *PlanDescription) writeField3(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("format", thrift.STRING, 3); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:format: ", p), err) } + if err := oprot.WriteBinary(p.Format); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.format (3) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 3:format: ", p), err) } + return err +} + +func (p *PlanDescription) writeField4(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("optimize_time_in_us", thrift.I32, 4); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:optimize_time_in_us: ", p), err) } + if err := oprot.WriteI32(int32(p.OptimizeTimeInUs)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.optimize_time_in_us (4) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 4:optimize_time_in_us: ", p), err) } + return err +} + +func (p *PlanDescription) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("PlanDescription(%+v)", *p) +} + +// Attributes: +// - ErrorCode +// - LatencyInUs +// - Data +// - SpaceName +// - ErrorMsg +// - PlanDesc +// - Comment +type ExecutionResponse struct { + ErrorCode ErrorCode `thrift:"error_code,1,required" db:"error_code" json:"error_code"` + LatencyInUs int32 `thrift:"latency_in_us,2,required" db:"latency_in_us" json:"latency_in_us"` + Data *nebula0.DataSet `thrift:"data,3" db:"data" json:"data,omitempty"` + SpaceName []byte `thrift:"space_name,4" db:"space_name" json:"space_name,omitempty"` + ErrorMsg []byte `thrift:"error_msg,5" db:"error_msg" json:"error_msg,omitempty"` + PlanDesc *PlanDescription `thrift:"plan_desc,6" db:"plan_desc" json:"plan_desc,omitempty"` + Comment []byte `thrift:"comment,7" db:"comment" json:"comment,omitempty"` +} + +func NewExecutionResponse() *ExecutionResponse { + return &ExecutionResponse{} +} + + +func (p *ExecutionResponse) GetErrorCode() ErrorCode { + return p.ErrorCode +} + +func (p *ExecutionResponse) GetLatencyInUs() int32 { + return p.LatencyInUs +} +var ExecutionResponse_Data_DEFAULT *nebula0.DataSet +func (p *ExecutionResponse) GetData() *nebula0.DataSet { + if !p.IsSetData() { + return ExecutionResponse_Data_DEFAULT + } +return p.Data +} +var ExecutionResponse_SpaceName_DEFAULT []byte + +func (p *ExecutionResponse) GetSpaceName() []byte { + return p.SpaceName +} +var ExecutionResponse_ErrorMsg_DEFAULT []byte + +func (p *ExecutionResponse) GetErrorMsg() []byte { + return p.ErrorMsg +} +var ExecutionResponse_PlanDesc_DEFAULT *PlanDescription +func (p *ExecutionResponse) GetPlanDesc() *PlanDescription { + if !p.IsSetPlanDesc() { + return ExecutionResponse_PlanDesc_DEFAULT + } +return p.PlanDesc +} +var ExecutionResponse_Comment_DEFAULT []byte + +func (p *ExecutionResponse) GetComment() []byte { + return p.Comment +} +func (p *ExecutionResponse) IsSetData() bool { + return p.Data != nil +} + +func (p *ExecutionResponse) IsSetSpaceName() bool { + return p.SpaceName != nil +} + +func (p *ExecutionResponse) IsSetErrorMsg() bool { + return p.ErrorMsg != nil +} + +func (p *ExecutionResponse) IsSetPlanDesc() bool { + return p.PlanDesc != nil +} + +func (p *ExecutionResponse) IsSetComment() bool { + return p.Comment != nil +} + +func (p *ExecutionResponse) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + var issetErrorCode bool = false; + var issetLatencyInUs bool = false; + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + issetErrorCode = true + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + issetLatencyInUs = true + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + case 5: + if err := p.ReadField5(iprot); err != nil { + return err + } + case 6: + if err := p.ReadField6(iprot); err != nil { + return err + } + case 7: + if err := p.ReadField7(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + if !issetErrorCode{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field ErrorCode is not set")); + } + if !issetLatencyInUs{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field LatencyInUs is not set")); + } + return nil +} + +func (p *ExecutionResponse) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadI32(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + temp := ErrorCode(v) + p.ErrorCode = temp +} + return nil +} + +func (p *ExecutionResponse) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadI32(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + p.LatencyInUs = v +} + return nil +} + +func (p *ExecutionResponse) ReadField3(iprot thrift.Protocol) error { + p.Data = nebula0.NewDataSet() + if err := p.Data.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Data), err) + } + return nil +} + +func (p *ExecutionResponse) ReadField4(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 4: ", err) +} else { + p.SpaceName = v +} + return nil +} + +func (p *ExecutionResponse) ReadField5(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 5: ", err) +} else { + p.ErrorMsg = v +} + return nil +} + +func (p *ExecutionResponse) ReadField6(iprot thrift.Protocol) error { + p.PlanDesc = NewPlanDescription() + if err := p.PlanDesc.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.PlanDesc), err) + } + return nil +} + +func (p *ExecutionResponse) ReadField7(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 7: ", err) +} else { + p.Comment = v +} + return nil +} + +func (p *ExecutionResponse) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("ExecutionResponse"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := p.writeField3(oprot); err != nil { return err } + if err := p.writeField4(oprot); err != nil { return err } + if err := p.writeField5(oprot); err != nil { return err } + if err := p.writeField6(oprot); err != nil { return err } + if err := p.writeField7(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *ExecutionResponse) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("error_code", thrift.I32, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:error_code: ", p), err) } + if err := oprot.WriteI32(int32(p.ErrorCode)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.error_code (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:error_code: ", p), err) } + return err +} + +func (p *ExecutionResponse) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("latency_in_us", thrift.I32, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:latency_in_us: ", p), err) } + if err := oprot.WriteI32(int32(p.LatencyInUs)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.latency_in_us (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:latency_in_us: ", p), err) } + return err +} + +func (p *ExecutionResponse) writeField3(oprot thrift.Protocol) (err error) { + if p.IsSetData() { + if err := oprot.WriteFieldBegin("data", thrift.STRUCT, 3); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:data: ", p), err) } + if err := p.Data.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Data), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 3:data: ", p), err) } + } + return err +} + +func (p *ExecutionResponse) writeField4(oprot thrift.Protocol) (err error) { + if p.IsSetSpaceName() { + if err := oprot.WriteFieldBegin("space_name", thrift.STRING, 4); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:space_name: ", p), err) } + if err := oprot.WriteBinary(p.SpaceName); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.space_name (4) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 4:space_name: ", p), err) } + } + return err +} + +func (p *ExecutionResponse) writeField5(oprot thrift.Protocol) (err error) { + if p.IsSetErrorMsg() { + if err := oprot.WriteFieldBegin("error_msg", thrift.STRING, 5); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 5:error_msg: ", p), err) } + if err := oprot.WriteBinary(p.ErrorMsg); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.error_msg (5) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 5:error_msg: ", p), err) } + } + return err +} + +func (p *ExecutionResponse) writeField6(oprot thrift.Protocol) (err error) { + if p.IsSetPlanDesc() { + if err := oprot.WriteFieldBegin("plan_desc", thrift.STRUCT, 6); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 6:plan_desc: ", p), err) } + if err := p.PlanDesc.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.PlanDesc), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 6:plan_desc: ", p), err) } + } + return err +} + +func (p *ExecutionResponse) writeField7(oprot thrift.Protocol) (err error) { + if p.IsSetComment() { + if err := oprot.WriteFieldBegin("comment", thrift.STRING, 7); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 7:comment: ", p), err) } + if err := oprot.WriteBinary(p.Comment); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.comment (7) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 7:comment: ", p), err) } + } + return err +} + +func (p *ExecutionResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("ExecutionResponse(%+v)", *p) +} + +// Attributes: +// - ErrorCode +// - ErrorMsg +// - SessionID +type AuthResponse struct { + ErrorCode ErrorCode `thrift:"error_code,1,required" db:"error_code" json:"error_code"` + ErrorMsg []byte `thrift:"error_msg,2" db:"error_msg" json:"error_msg,omitempty"` + SessionID *int64 `thrift:"session_id,3" db:"session_id" json:"session_id,omitempty"` +} + +func NewAuthResponse() *AuthResponse { + return &AuthResponse{} +} + + +func (p *AuthResponse) GetErrorCode() ErrorCode { + return p.ErrorCode +} +var AuthResponse_ErrorMsg_DEFAULT []byte + +func (p *AuthResponse) GetErrorMsg() []byte { + return p.ErrorMsg +} +var AuthResponse_SessionID_DEFAULT int64 +func (p *AuthResponse) GetSessionID() int64 { + if !p.IsSetSessionID() { + return AuthResponse_SessionID_DEFAULT + } +return *p.SessionID +} +func (p *AuthResponse) IsSetErrorMsg() bool { + return p.ErrorMsg != nil +} + +func (p *AuthResponse) IsSetSessionID() bool { + return p.SessionID != nil +} + +func (p *AuthResponse) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + var issetErrorCode bool = false; + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + issetErrorCode = true + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + if !issetErrorCode{ + return thrift.NewProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field ErrorCode is not set")); + } + return nil +} + +func (p *AuthResponse) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadI32(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + temp := ErrorCode(v) + p.ErrorCode = temp +} + return nil +} + +func (p *AuthResponse) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + p.ErrorMsg = v +} + return nil +} + +func (p *AuthResponse) ReadField3(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 3: ", err) +} else { + p.SessionID = &v +} + return nil +} + +func (p *AuthResponse) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("AuthResponse"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := p.writeField3(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *AuthResponse) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("error_code", thrift.I32, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:error_code: ", p), err) } + if err := oprot.WriteI32(int32(p.ErrorCode)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.error_code (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:error_code: ", p), err) } + return err +} + +func (p *AuthResponse) writeField2(oprot thrift.Protocol) (err error) { + if p.IsSetErrorMsg() { + if err := oprot.WriteFieldBegin("error_msg", thrift.STRING, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:error_msg: ", p), err) } + if err := oprot.WriteBinary(p.ErrorMsg); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.error_msg (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:error_msg: ", p), err) } + } + return err +} + +func (p *AuthResponse) writeField3(oprot thrift.Protocol) (err error) { + if p.IsSetSessionID() { + if err := oprot.WriteFieldBegin("session_id", thrift.I64, 3); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:session_id: ", p), err) } + if err := oprot.WriteI64(int64(*p.SessionID)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.session_id (3) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 3:session_id: ", p), err) } + } + return err +} + +func (p *AuthResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("AuthResponse(%+v)", *p) +} + diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/ttypes.go b/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/ttypes.go new file mode 100644 index 000000000..d39386986 --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/nebula/ttypes.go @@ -0,0 +1,3365 @@ +// Autogenerated by Thrift Compiler (facebook) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +// @generated + +package nebula + +import ( + "bytes" + "sync" + "fmt" + thrift "github.com/facebook/fbthrift/thrift/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = sync.Mutex{} +var _ = bytes.Equal + +var GoUnusedProtection__ int; + +type NullType int64 +const ( + NullType___NULL__ NullType = 0 + NullType_NaN NullType = 1 + NullType_BAD_DATA NullType = 2 + NullType_BAD_TYPE NullType = 3 + NullType_ERR_OVERFLOW NullType = 4 + NullType_UNKNOWN_PROP NullType = 5 + NullType_DIV_BY_ZERO NullType = 6 + NullType_OUT_OF_RANGE NullType = 7 +) + +var NullTypeToName = map[NullType]string { + NullType___NULL__: "__NULL__", + NullType_NaN: "NaN", + NullType_BAD_DATA: "BAD_DATA", + NullType_BAD_TYPE: "BAD_TYPE", + NullType_ERR_OVERFLOW: "ERR_OVERFLOW", + NullType_UNKNOWN_PROP: "UNKNOWN_PROP", + NullType_DIV_BY_ZERO: "DIV_BY_ZERO", + NullType_OUT_OF_RANGE: "OUT_OF_RANGE", +} + +var NullTypeToValue = map[string]NullType { + "__NULL__": NullType___NULL__, + "NaN": NullType_NaN, + "BAD_DATA": NullType_BAD_DATA, + "BAD_TYPE": NullType_BAD_TYPE, + "ERR_OVERFLOW": NullType_ERR_OVERFLOW, + "UNKNOWN_PROP": NullType_UNKNOWN_PROP, + "DIV_BY_ZERO": NullType_DIV_BY_ZERO, + "OUT_OF_RANGE": NullType_OUT_OF_RANGE, +} + +func (p NullType) String() string { + if v, ok := NullTypeToName[p]; ok { + return v + } + return "" +} + +func NullTypeFromString(s string) (NullType, error) { + if v, ok := NullTypeToValue[s]; ok { + return v, nil + } + return NullType(0), fmt.Errorf("not a valid NullType string") +} + +func NullTypePtr(v NullType) *NullType { return &v } + +type GraphSpaceID int32 + +func GraphSpaceIDPtr(v GraphSpaceID) *GraphSpaceID { return &v } + +type PartitionID int32 + +func PartitionIDPtr(v PartitionID) *PartitionID { return &v } + +type TagID int32 + +func TagIDPtr(v TagID) *TagID { return &v } + +type EdgeType int32 + +func EdgeTypePtr(v EdgeType) *EdgeType { return &v } + +type EdgeRanking int64 + +func EdgeRankingPtr(v EdgeRanking) *EdgeRanking { return &v } + +type LogID int64 + +func LogIDPtr(v LogID) *LogID { return &v } + +type TermID int64 + +func TermIDPtr(v TermID) *TermID { return &v } + +type Timestamp int64 + +func TimestampPtr(v Timestamp) *Timestamp { return &v } + +type IndexID int32 + +func IndexIDPtr(v IndexID) *IndexID { return &v } + +type Port int32 + +func PortPtr(v Port) *Port { return &v } + +type SessionID int64 + +func SessionIDPtr(v SessionID) *SessionID { return &v } + +// Attributes: +// - Year +// - Month +// - Day +type Date struct { + Year int16 `thrift:"year,1" db:"year" json:"year"` + Month int8 `thrift:"month,2" db:"month" json:"month"` + Day int8 `thrift:"day,3" db:"day" json:"day"` +} + +func NewDate() *Date { + return &Date{} +} + + +func (p *Date) GetYear() int16 { + return p.Year +} + +func (p *Date) GetMonth() int8 { + return p.Month +} + +func (p *Date) GetDay() int8 { + return p.Day +} +func (p *Date) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *Date) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadI16(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + p.Year = v +} + return nil +} + +func (p *Date) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadByte(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + temp := int8(v) + p.Month = temp +} + return nil +} + +func (p *Date) ReadField3(iprot thrift.Protocol) error { + if v, err := iprot.ReadByte(); err != nil { + return thrift.PrependError("error reading field 3: ", err) +} else { + temp := int8(v) + p.Day = temp +} + return nil +} + +func (p *Date) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("Date"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := p.writeField3(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *Date) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("year", thrift.I16, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:year: ", p), err) } + if err := oprot.WriteI16(int16(p.Year)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.year (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:year: ", p), err) } + return err +} + +func (p *Date) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("month", thrift.BYTE, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:month: ", p), err) } + if err := oprot.WriteByte(byte(p.Month)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.month (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:month: ", p), err) } + return err +} + +func (p *Date) writeField3(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("day", thrift.BYTE, 3); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:day: ", p), err) } + if err := oprot.WriteByte(byte(p.Day)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.day (3) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 3:day: ", p), err) } + return err +} + +func (p *Date) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Date(%+v)", *p) +} + +// Attributes: +// - Hour +// - Minute +// - Sec +// - Microsec +type Time struct { + Hour int8 `thrift:"hour,1" db:"hour" json:"hour"` + Minute int8 `thrift:"minute,2" db:"minute" json:"minute"` + Sec int8 `thrift:"sec,3" db:"sec" json:"sec"` + Microsec int32 `thrift:"microsec,4" db:"microsec" json:"microsec"` +} + +func NewTime() *Time { + return &Time{} +} + + +func (p *Time) GetHour() int8 { + return p.Hour +} + +func (p *Time) GetMinute() int8 { + return p.Minute +} + +func (p *Time) GetSec() int8 { + return p.Sec +} + +func (p *Time) GetMicrosec() int32 { + return p.Microsec +} +func (p *Time) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *Time) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadByte(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + temp := int8(v) + p.Hour = temp +} + return nil +} + +func (p *Time) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadByte(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + temp := int8(v) + p.Minute = temp +} + return nil +} + +func (p *Time) ReadField3(iprot thrift.Protocol) error { + if v, err := iprot.ReadByte(); err != nil { + return thrift.PrependError("error reading field 3: ", err) +} else { + temp := int8(v) + p.Sec = temp +} + return nil +} + +func (p *Time) ReadField4(iprot thrift.Protocol) error { + if v, err := iprot.ReadI32(); err != nil { + return thrift.PrependError("error reading field 4: ", err) +} else { + p.Microsec = v +} + return nil +} + +func (p *Time) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("Time"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := p.writeField3(oprot); err != nil { return err } + if err := p.writeField4(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *Time) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("hour", thrift.BYTE, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:hour: ", p), err) } + if err := oprot.WriteByte(byte(p.Hour)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.hour (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:hour: ", p), err) } + return err +} + +func (p *Time) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("minute", thrift.BYTE, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:minute: ", p), err) } + if err := oprot.WriteByte(byte(p.Minute)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.minute (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:minute: ", p), err) } + return err +} + +func (p *Time) writeField3(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("sec", thrift.BYTE, 3); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:sec: ", p), err) } + if err := oprot.WriteByte(byte(p.Sec)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.sec (3) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 3:sec: ", p), err) } + return err +} + +func (p *Time) writeField4(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("microsec", thrift.I32, 4); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:microsec: ", p), err) } + if err := oprot.WriteI32(int32(p.Microsec)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.microsec (4) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 4:microsec: ", p), err) } + return err +} + +func (p *Time) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Time(%+v)", *p) +} + +// Attributes: +// - Year +// - Month +// - Day +// - Hour +// - Minute +// - Sec +// - Microsec +type DateTime struct { + Year int16 `thrift:"year,1" db:"year" json:"year"` + Month int8 `thrift:"month,2" db:"month" json:"month"` + Day int8 `thrift:"day,3" db:"day" json:"day"` + Hour int8 `thrift:"hour,4" db:"hour" json:"hour"` + Minute int8 `thrift:"minute,5" db:"minute" json:"minute"` + Sec int8 `thrift:"sec,6" db:"sec" json:"sec"` + Microsec int32 `thrift:"microsec,7" db:"microsec" json:"microsec"` +} + +func NewDateTime() *DateTime { + return &DateTime{} +} + + +func (p *DateTime) GetYear() int16 { + return p.Year +} + +func (p *DateTime) GetMonth() int8 { + return p.Month +} + +func (p *DateTime) GetDay() int8 { + return p.Day +} + +func (p *DateTime) GetHour() int8 { + return p.Hour +} + +func (p *DateTime) GetMinute() int8 { + return p.Minute +} + +func (p *DateTime) GetSec() int8 { + return p.Sec +} + +func (p *DateTime) GetMicrosec() int32 { + return p.Microsec +} +func (p *DateTime) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + case 5: + if err := p.ReadField5(iprot); err != nil { + return err + } + case 6: + if err := p.ReadField6(iprot); err != nil { + return err + } + case 7: + if err := p.ReadField7(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *DateTime) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadI16(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + p.Year = v +} + return nil +} + +func (p *DateTime) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadByte(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + temp := int8(v) + p.Month = temp +} + return nil +} + +func (p *DateTime) ReadField3(iprot thrift.Protocol) error { + if v, err := iprot.ReadByte(); err != nil { + return thrift.PrependError("error reading field 3: ", err) +} else { + temp := int8(v) + p.Day = temp +} + return nil +} + +func (p *DateTime) ReadField4(iprot thrift.Protocol) error { + if v, err := iprot.ReadByte(); err != nil { + return thrift.PrependError("error reading field 4: ", err) +} else { + temp := int8(v) + p.Hour = temp +} + return nil +} + +func (p *DateTime) ReadField5(iprot thrift.Protocol) error { + if v, err := iprot.ReadByte(); err != nil { + return thrift.PrependError("error reading field 5: ", err) +} else { + temp := int8(v) + p.Minute = temp +} + return nil +} + +func (p *DateTime) ReadField6(iprot thrift.Protocol) error { + if v, err := iprot.ReadByte(); err != nil { + return thrift.PrependError("error reading field 6: ", err) +} else { + temp := int8(v) + p.Sec = temp +} + return nil +} + +func (p *DateTime) ReadField7(iprot thrift.Protocol) error { + if v, err := iprot.ReadI32(); err != nil { + return thrift.PrependError("error reading field 7: ", err) +} else { + p.Microsec = v +} + return nil +} + +func (p *DateTime) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("DateTime"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := p.writeField3(oprot); err != nil { return err } + if err := p.writeField4(oprot); err != nil { return err } + if err := p.writeField5(oprot); err != nil { return err } + if err := p.writeField6(oprot); err != nil { return err } + if err := p.writeField7(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *DateTime) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("year", thrift.I16, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:year: ", p), err) } + if err := oprot.WriteI16(int16(p.Year)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.year (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:year: ", p), err) } + return err +} + +func (p *DateTime) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("month", thrift.BYTE, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:month: ", p), err) } + if err := oprot.WriteByte(byte(p.Month)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.month (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:month: ", p), err) } + return err +} + +func (p *DateTime) writeField3(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("day", thrift.BYTE, 3); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:day: ", p), err) } + if err := oprot.WriteByte(byte(p.Day)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.day (3) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 3:day: ", p), err) } + return err +} + +func (p *DateTime) writeField4(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("hour", thrift.BYTE, 4); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:hour: ", p), err) } + if err := oprot.WriteByte(byte(p.Hour)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.hour (4) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 4:hour: ", p), err) } + return err +} + +func (p *DateTime) writeField5(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("minute", thrift.BYTE, 5); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 5:minute: ", p), err) } + if err := oprot.WriteByte(byte(p.Minute)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.minute (5) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 5:minute: ", p), err) } + return err +} + +func (p *DateTime) writeField6(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("sec", thrift.BYTE, 6); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 6:sec: ", p), err) } + if err := oprot.WriteByte(byte(p.Sec)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.sec (6) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 6:sec: ", p), err) } + return err +} + +func (p *DateTime) writeField7(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("microsec", thrift.I32, 7); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 7:microsec: ", p), err) } + if err := oprot.WriteI32(int32(p.Microsec)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.microsec (7) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 7:microsec: ", p), err) } + return err +} + +func (p *DateTime) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("DateTime(%+v)", *p) +} + +// Attributes: +// - NVal +// - BVal +// - IVal +// - FVal +// - SVal +// - DVal +// - TVal +// - DtVal +// - VVal +// - EVal +// - PVal +// - LVal +// - MVal +// - UVal +// - GVal +type Value struct { + NVal *NullType `thrift:"nVal,1" db:"nVal" json:"nVal,omitempty"` + BVal *bool `thrift:"bVal,2" db:"bVal" json:"bVal,omitempty"` + IVal *int64 `thrift:"iVal,3" db:"iVal" json:"iVal,omitempty"` + FVal *float64 `thrift:"fVal,4" db:"fVal" json:"fVal,omitempty"` + SVal []byte `thrift:"sVal,5" db:"sVal" json:"sVal,omitempty"` + DVal *Date `thrift:"dVal,6" db:"dVal" json:"dVal,omitempty"` + TVal *Time `thrift:"tVal,7" db:"tVal" json:"tVal,omitempty"` + DtVal *DateTime `thrift:"dtVal,8" db:"dtVal" json:"dtVal,omitempty"` + VVal *Vertex `thrift:"vVal,9" db:"vVal" json:"vVal,omitempty"` + EVal *Edge `thrift:"eVal,10" db:"eVal" json:"eVal,omitempty"` + PVal *Path `thrift:"pVal,11" db:"pVal" json:"pVal,omitempty"` + LVal *NList `thrift:"lVal,12" db:"lVal" json:"lVal,omitempty"` + MVal *NMap `thrift:"mVal,13" db:"mVal" json:"mVal,omitempty"` + UVal *NSet `thrift:"uVal,14" db:"uVal" json:"uVal,omitempty"` + GVal *DataSet `thrift:"gVal,15" db:"gVal" json:"gVal,omitempty"` +} + +func NewValue() *Value { + return &Value{} +} + +var Value_NVal_DEFAULT NullType +func (p *Value) GetNVal() NullType { + if !p.IsSetNVal() { + return Value_NVal_DEFAULT + } +return *p.NVal +} +var Value_BVal_DEFAULT bool +func (p *Value) GetBVal() bool { + if !p.IsSetBVal() { + return Value_BVal_DEFAULT + } +return *p.BVal +} +var Value_IVal_DEFAULT int64 +func (p *Value) GetIVal() int64 { + if !p.IsSetIVal() { + return Value_IVal_DEFAULT + } +return *p.IVal +} +var Value_FVal_DEFAULT float64 +func (p *Value) GetFVal() float64 { + if !p.IsSetFVal() { + return Value_FVal_DEFAULT + } +return *p.FVal +} +var Value_SVal_DEFAULT []byte + +func (p *Value) GetSVal() []byte { + return p.SVal +} +var Value_DVal_DEFAULT *Date +func (p *Value) GetDVal() *Date { + if !p.IsSetDVal() { + return Value_DVal_DEFAULT + } +return p.DVal +} +var Value_TVal_DEFAULT *Time +func (p *Value) GetTVal() *Time { + if !p.IsSetTVal() { + return Value_TVal_DEFAULT + } +return p.TVal +} +var Value_DtVal_DEFAULT *DateTime +func (p *Value) GetDtVal() *DateTime { + if !p.IsSetDtVal() { + return Value_DtVal_DEFAULT + } +return p.DtVal +} +var Value_VVal_DEFAULT *Vertex +func (p *Value) GetVVal() *Vertex { + if !p.IsSetVVal() { + return Value_VVal_DEFAULT + } +return p.VVal +} +var Value_EVal_DEFAULT *Edge +func (p *Value) GetEVal() *Edge { + if !p.IsSetEVal() { + return Value_EVal_DEFAULT + } +return p.EVal +} +var Value_PVal_DEFAULT *Path +func (p *Value) GetPVal() *Path { + if !p.IsSetPVal() { + return Value_PVal_DEFAULT + } +return p.PVal +} +var Value_LVal_DEFAULT *NList +func (p *Value) GetLVal() *NList { + if !p.IsSetLVal() { + return Value_LVal_DEFAULT + } +return p.LVal +} +var Value_MVal_DEFAULT *NMap +func (p *Value) GetMVal() *NMap { + if !p.IsSetMVal() { + return Value_MVal_DEFAULT + } +return p.MVal +} +var Value_UVal_DEFAULT *NSet +func (p *Value) GetUVal() *NSet { + if !p.IsSetUVal() { + return Value_UVal_DEFAULT + } +return p.UVal +} +var Value_GVal_DEFAULT *DataSet +func (p *Value) GetGVal() *DataSet { + if !p.IsSetGVal() { + return Value_GVal_DEFAULT + } +return p.GVal +} +func (p *Value) CountSetFieldsValue() int { + count := 0 + if (p.IsSetNVal()) { + count++ + } + if (p.IsSetBVal()) { + count++ + } + if (p.IsSetIVal()) { + count++ + } + if (p.IsSetFVal()) { + count++ + } + if (p.IsSetDVal()) { + count++ + } + if (p.IsSetTVal()) { + count++ + } + if (p.IsSetDtVal()) { + count++ + } + if (p.IsSetVVal()) { + count++ + } + if (p.IsSetEVal()) { + count++ + } + if (p.IsSetPVal()) { + count++ + } + if (p.IsSetLVal()) { + count++ + } + if (p.IsSetMVal()) { + count++ + } + if (p.IsSetUVal()) { + count++ + } + if (p.IsSetGVal()) { + count++ + } + return count + +} + +func (p *Value) IsSetNVal() bool { + return p.NVal != nil +} + +func (p *Value) IsSetBVal() bool { + return p.BVal != nil +} + +func (p *Value) IsSetIVal() bool { + return p.IVal != nil +} + +func (p *Value) IsSetFVal() bool { + return p.FVal != nil +} + +func (p *Value) IsSetSVal() bool { + return p.SVal != nil +} + +func (p *Value) IsSetDVal() bool { + return p.DVal != nil +} + +func (p *Value) IsSetTVal() bool { + return p.TVal != nil +} + +func (p *Value) IsSetDtVal() bool { + return p.DtVal != nil +} + +func (p *Value) IsSetVVal() bool { + return p.VVal != nil +} + +func (p *Value) IsSetEVal() bool { + return p.EVal != nil +} + +func (p *Value) IsSetPVal() bool { + return p.PVal != nil +} + +func (p *Value) IsSetLVal() bool { + return p.LVal != nil +} + +func (p *Value) IsSetMVal() bool { + return p.MVal != nil +} + +func (p *Value) IsSetUVal() bool { + return p.UVal != nil +} + +func (p *Value) IsSetGVal() bool { + return p.GVal != nil +} + +func (p *Value) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + case 5: + if err := p.ReadField5(iprot); err != nil { + return err + } + case 6: + if err := p.ReadField6(iprot); err != nil { + return err + } + case 7: + if err := p.ReadField7(iprot); err != nil { + return err + } + case 8: + if err := p.ReadField8(iprot); err != nil { + return err + } + case 9: + if err := p.ReadField9(iprot); err != nil { + return err + } + case 10: + if err := p.ReadField10(iprot); err != nil { + return err + } + case 11: + if err := p.ReadField11(iprot); err != nil { + return err + } + case 12: + if err := p.ReadField12(iprot); err != nil { + return err + } + case 13: + if err := p.ReadField13(iprot); err != nil { + return err + } + case 14: + if err := p.ReadField14(iprot); err != nil { + return err + } + case 15: + if err := p.ReadField15(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *Value) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadI32(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + temp := NullType(v) + p.NVal = &temp +} + return nil +} + +func (p *Value) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadBool(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + p.BVal = &v +} + return nil +} + +func (p *Value) ReadField3(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 3: ", err) +} else { + p.IVal = &v +} + return nil +} + +func (p *Value) ReadField4(iprot thrift.Protocol) error { + if v, err := iprot.ReadDouble(); err != nil { + return thrift.PrependError("error reading field 4: ", err) +} else { + p.FVal = &v +} + return nil +} + +func (p *Value) ReadField5(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 5: ", err) +} else { + p.SVal = v +} + return nil +} + +func (p *Value) ReadField6(iprot thrift.Protocol) error { + p.DVal = NewDate() + if err := p.DVal.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.DVal), err) + } + return nil +} + +func (p *Value) ReadField7(iprot thrift.Protocol) error { + p.TVal = NewTime() + if err := p.TVal.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.TVal), err) + } + return nil +} + +func (p *Value) ReadField8(iprot thrift.Protocol) error { + p.DtVal = NewDateTime() + if err := p.DtVal.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.DtVal), err) + } + return nil +} + +func (p *Value) ReadField9(iprot thrift.Protocol) error { + p.VVal = NewVertex() + if err := p.VVal.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.VVal), err) + } + return nil +} + +func (p *Value) ReadField10(iprot thrift.Protocol) error { + p.EVal = NewEdge() + if err := p.EVal.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.EVal), err) + } + return nil +} + +func (p *Value) ReadField11(iprot thrift.Protocol) error { + p.PVal = NewPath() + if err := p.PVal.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.PVal), err) + } + return nil +} + +func (p *Value) ReadField12(iprot thrift.Protocol) error { + p.LVal = NewNList() + if err := p.LVal.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.LVal), err) + } + return nil +} + +func (p *Value) ReadField13(iprot thrift.Protocol) error { + p.MVal = NewNMap() + if err := p.MVal.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.MVal), err) + } + return nil +} + +func (p *Value) ReadField14(iprot thrift.Protocol) error { + p.UVal = NewNSet() + if err := p.UVal.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.UVal), err) + } + return nil +} + +func (p *Value) ReadField15(iprot thrift.Protocol) error { + p.GVal = NewDataSet() + if err := p.GVal.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.GVal), err) + } + return nil +} + +func (p *Value) Write(oprot thrift.Protocol) error { + if c := p.CountSetFieldsValue(); c != 1 { + return fmt.Errorf("%T write union: exactly one field must be set (%d set).", p, c) + } + if err := oprot.WriteStructBegin("Value"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := p.writeField3(oprot); err != nil { return err } + if err := p.writeField4(oprot); err != nil { return err } + if err := p.writeField5(oprot); err != nil { return err } + if err := p.writeField6(oprot); err != nil { return err } + if err := p.writeField7(oprot); err != nil { return err } + if err := p.writeField8(oprot); err != nil { return err } + if err := p.writeField9(oprot); err != nil { return err } + if err := p.writeField10(oprot); err != nil { return err } + if err := p.writeField11(oprot); err != nil { return err } + if err := p.writeField12(oprot); err != nil { return err } + if err := p.writeField13(oprot); err != nil { return err } + if err := p.writeField14(oprot); err != nil { return err } + if err := p.writeField15(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *Value) writeField1(oprot thrift.Protocol) (err error) { + if p.IsSetNVal() { + if err := oprot.WriteFieldBegin("nVal", thrift.I32, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:nVal: ", p), err) } + if err := oprot.WriteI32(int32(*p.NVal)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.nVal (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:nVal: ", p), err) } + } + return err +} + +func (p *Value) writeField2(oprot thrift.Protocol) (err error) { + if p.IsSetBVal() { + if err := oprot.WriteFieldBegin("bVal", thrift.BOOL, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:bVal: ", p), err) } + if err := oprot.WriteBool(bool(*p.BVal)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.bVal (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:bVal: ", p), err) } + } + return err +} + +func (p *Value) writeField3(oprot thrift.Protocol) (err error) { + if p.IsSetIVal() { + if err := oprot.WriteFieldBegin("iVal", thrift.I64, 3); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:iVal: ", p), err) } + if err := oprot.WriteI64(int64(*p.IVal)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.iVal (3) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 3:iVal: ", p), err) } + } + return err +} + +func (p *Value) writeField4(oprot thrift.Protocol) (err error) { + if p.IsSetFVal() { + if err := oprot.WriteFieldBegin("fVal", thrift.DOUBLE, 4); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:fVal: ", p), err) } + if err := oprot.WriteDouble(float64(*p.FVal)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.fVal (4) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 4:fVal: ", p), err) } + } + return err +} + +func (p *Value) writeField5(oprot thrift.Protocol) (err error) { + if p.IsSetSVal() { + if err := oprot.WriteFieldBegin("sVal", thrift.STRING, 5); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 5:sVal: ", p), err) } + if err := oprot.WriteBinary(p.SVal); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.sVal (5) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 5:sVal: ", p), err) } + } + return err +} + +func (p *Value) writeField6(oprot thrift.Protocol) (err error) { + if p.IsSetDVal() { + if err := oprot.WriteFieldBegin("dVal", thrift.STRUCT, 6); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 6:dVal: ", p), err) } + if err := p.DVal.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.DVal), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 6:dVal: ", p), err) } + } + return err +} + +func (p *Value) writeField7(oprot thrift.Protocol) (err error) { + if p.IsSetTVal() { + if err := oprot.WriteFieldBegin("tVal", thrift.STRUCT, 7); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 7:tVal: ", p), err) } + if err := p.TVal.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.TVal), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 7:tVal: ", p), err) } + } + return err +} + +func (p *Value) writeField8(oprot thrift.Protocol) (err error) { + if p.IsSetDtVal() { + if err := oprot.WriteFieldBegin("dtVal", thrift.STRUCT, 8); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 8:dtVal: ", p), err) } + if err := p.DtVal.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.DtVal), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 8:dtVal: ", p), err) } + } + return err +} + +func (p *Value) writeField9(oprot thrift.Protocol) (err error) { + if p.IsSetVVal() { + if err := oprot.WriteFieldBegin("vVal", thrift.STRUCT, 9); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 9:vVal: ", p), err) } + if err := p.VVal.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.VVal), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 9:vVal: ", p), err) } + } + return err +} + +func (p *Value) writeField10(oprot thrift.Protocol) (err error) { + if p.IsSetEVal() { + if err := oprot.WriteFieldBegin("eVal", thrift.STRUCT, 10); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 10:eVal: ", p), err) } + if err := p.EVal.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.EVal), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 10:eVal: ", p), err) } + } + return err +} + +func (p *Value) writeField11(oprot thrift.Protocol) (err error) { + if p.IsSetPVal() { + if err := oprot.WriteFieldBegin("pVal", thrift.STRUCT, 11); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 11:pVal: ", p), err) } + if err := p.PVal.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.PVal), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 11:pVal: ", p), err) } + } + return err +} + +func (p *Value) writeField12(oprot thrift.Protocol) (err error) { + if p.IsSetLVal() { + if err := oprot.WriteFieldBegin("lVal", thrift.STRUCT, 12); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 12:lVal: ", p), err) } + if err := p.LVal.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.LVal), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 12:lVal: ", p), err) } + } + return err +} + +func (p *Value) writeField13(oprot thrift.Protocol) (err error) { + if p.IsSetMVal() { + if err := oprot.WriteFieldBegin("mVal", thrift.STRUCT, 13); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 13:mVal: ", p), err) } + if err := p.MVal.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.MVal), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 13:mVal: ", p), err) } + } + return err +} + +func (p *Value) writeField14(oprot thrift.Protocol) (err error) { + if p.IsSetUVal() { + if err := oprot.WriteFieldBegin("uVal", thrift.STRUCT, 14); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 14:uVal: ", p), err) } + if err := p.UVal.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.UVal), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 14:uVal: ", p), err) } + } + return err +} + +func (p *Value) writeField15(oprot thrift.Protocol) (err error) { + if p.IsSetGVal() { + if err := oprot.WriteFieldBegin("gVal", thrift.STRUCT, 15); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 15:gVal: ", p), err) } + if err := p.GVal.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.GVal), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 15:gVal: ", p), err) } + } + return err +} + +func (p *Value) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Value(%+v)", *p) +} + +// Attributes: +// - Values +type NList struct { + Values []*Value `thrift:"values,1" db:"values" json:"values"` +} + +func NewNList() *NList { + return &NList{} +} + + +func (p *NList) GetValues() []*Value { + return p.Values +} +func (p *NList) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *NList) ReadField1(iprot thrift.Protocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return thrift.PrependError("error reading list begin: ", err) + } + tSlice := make([]*Value, 0, size) + p.Values = tSlice + for i := 0; i < size; i ++ { + _elem0 := NewValue() + if err := _elem0.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem0), err) + } + p.Values = append(p.Values, _elem0) + } + if err := iprot.ReadListEnd(); err != nil { + return thrift.PrependError("error reading list end: ", err) + } + return nil +} + +func (p *NList) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("NList"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *NList) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("values", thrift.LIST, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:values: ", p), err) } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Values)); err != nil { + return thrift.PrependError("error writing list begin: ", err) + } + for _, v := range p.Values { + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return thrift.PrependError("error writing list end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:values: ", p), err) } + return err +} + +func (p *NList) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("NList(%+v)", *p) +} + +// Attributes: +// - Kvs +type NMap struct { + Kvs map[string]*Value `thrift:"kvs,1" db:"kvs" json:"kvs"` +} + +func NewNMap() *NMap { + return &NMap{} +} + + +func (p *NMap) GetKvs() map[string]*Value { + return p.Kvs +} +func (p *NMap) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *NMap) ReadField1(iprot thrift.Protocol) error { + _, _, size, err := iprot.ReadMapBegin() + if err != nil { + return thrift.PrependError("error reading map begin: ", err) + } + tMap := make(map[string]*Value, size) + p.Kvs = tMap + for i := 0; i < size; i ++ { +var _key1 string + if v, err := iprot.ReadString(); err != nil { + return thrift.PrependError("error reading field 0: ", err) +} else { + _key1 = v +} + _val2 := NewValue() + if err := _val2.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _val2), err) + } + p.Kvs[_key1] = _val2 + } + if err := iprot.ReadMapEnd(); err != nil { + return thrift.PrependError("error reading map end: ", err) + } + return nil +} + +func (p *NMap) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("NMap"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *NMap) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("kvs", thrift.MAP, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:kvs: ", p), err) } + if err := oprot.WriteMapBegin(thrift.STRING, thrift.STRUCT, len(p.Kvs)); err != nil { + return thrift.PrependError("error writing map begin: ", err) + } + for k, v := range p.Kvs { + if err := oprot.WriteString(string(k)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err) } + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteMapEnd(); err != nil { + return thrift.PrependError("error writing map end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:kvs: ", p), err) } + return err +} + +func (p *NMap) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("NMap(%+v)", *p) +} + +// Attributes: +// - Values +type NSet struct { + Values []*Value `thrift:"values,1" db:"values" json:"values"` +} + +func NewNSet() *NSet { + return &NSet{} +} + + +func (p *NSet) GetValues() []*Value { + return p.Values +} +func (p *NSet) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *NSet) ReadField1(iprot thrift.Protocol) error { + _, size, err := iprot.ReadSetBegin() + if err != nil { + return thrift.PrependError("error reading set begin: ", err) + } + tSet := make([]*Value, 0, size) + p.Values = tSet + for i := 0; i < size; i ++ { + _elem3 := NewValue() + if err := _elem3.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem3), err) + } + p.Values = append(p.Values, _elem3) + } + if err := iprot.ReadSetEnd(); err != nil { + return thrift.PrependError("error reading set end: ", err) + } + return nil +} + +func (p *NSet) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("NSet"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *NSet) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("values", thrift.SET, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:values: ", p), err) } + if err := oprot.WriteSetBegin(thrift.STRUCT, len(p.Values)); err != nil { + return thrift.PrependError("error writing set begin: ", err) + } + set := make(map[*Value]bool, len(p.Values)) + for _, v := range p.Values { + if ok := set[v]; ok { + return thrift.PrependError("", fmt.Errorf("%T error writing set field: slice is not unique", v)) + } + set[v] = true + } + for _, v := range p.Values { + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteSetEnd(); err != nil { + return thrift.PrependError("error writing set end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:values: ", p), err) } + return err +} + +func (p *NSet) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("NSet(%+v)", *p) +} + +// Attributes: +// - Values +type Row struct { + Values []*Value `thrift:"values,1" db:"values" json:"values"` +} + +func NewRow() *Row { + return &Row{} +} + + +func (p *Row) GetValues() []*Value { + return p.Values +} +func (p *Row) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *Row) ReadField1(iprot thrift.Protocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return thrift.PrependError("error reading list begin: ", err) + } + tSlice := make([]*Value, 0, size) + p.Values = tSlice + for i := 0; i < size; i ++ { + _elem4 := NewValue() + if err := _elem4.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem4), err) + } + p.Values = append(p.Values, _elem4) + } + if err := iprot.ReadListEnd(); err != nil { + return thrift.PrependError("error reading list end: ", err) + } + return nil +} + +func (p *Row) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("Row"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *Row) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("values", thrift.LIST, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:values: ", p), err) } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Values)); err != nil { + return thrift.PrependError("error writing list begin: ", err) + } + for _, v := range p.Values { + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return thrift.PrependError("error writing list end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:values: ", p), err) } + return err +} + +func (p *Row) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Row(%+v)", *p) +} + +// Attributes: +// - ColumnNames +// - Rows +type DataSet struct { + ColumnNames [][]byte `thrift:"column_names,1" db:"column_names" json:"column_names"` + Rows []*Row `thrift:"rows,2" db:"rows" json:"rows"` +} + +func NewDataSet() *DataSet { + return &DataSet{} +} + + +func (p *DataSet) GetColumnNames() [][]byte { + return p.ColumnNames +} + +func (p *DataSet) GetRows() []*Row { + return p.Rows +} +func (p *DataSet) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *DataSet) ReadField1(iprot thrift.Protocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return thrift.PrependError("error reading list begin: ", err) + } + tSlice := make([][]byte, 0, size) + p.ColumnNames = tSlice + for i := 0; i < size; i ++ { +var _elem5 []byte + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 0: ", err) +} else { + _elem5 = v +} + p.ColumnNames = append(p.ColumnNames, _elem5) + } + if err := iprot.ReadListEnd(); err != nil { + return thrift.PrependError("error reading list end: ", err) + } + return nil +} + +func (p *DataSet) ReadField2(iprot thrift.Protocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return thrift.PrependError("error reading list begin: ", err) + } + tSlice := make([]*Row, 0, size) + p.Rows = tSlice + for i := 0; i < size; i ++ { + _elem6 := NewRow() + if err := _elem6.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem6), err) + } + p.Rows = append(p.Rows, _elem6) + } + if err := iprot.ReadListEnd(); err != nil { + return thrift.PrependError("error reading list end: ", err) + } + return nil +} + +func (p *DataSet) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("DataSet"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *DataSet) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("column_names", thrift.LIST, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:column_names: ", p), err) } + if err := oprot.WriteListBegin(thrift.STRING, len(p.ColumnNames)); err != nil { + return thrift.PrependError("error writing list begin: ", err) + } + for _, v := range p.ColumnNames { + if err := oprot.WriteBinary(v); err != nil { + return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err) } + } + if err := oprot.WriteListEnd(); err != nil { + return thrift.PrependError("error writing list end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:column_names: ", p), err) } + return err +} + +func (p *DataSet) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("rows", thrift.LIST, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:rows: ", p), err) } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Rows)); err != nil { + return thrift.PrependError("error writing list begin: ", err) + } + for _, v := range p.Rows { + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return thrift.PrependError("error writing list end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:rows: ", p), err) } + return err +} + +func (p *DataSet) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("DataSet(%+v)", *p) +} + +// Attributes: +// - Name +// - Props +type Tag struct { + Name []byte `thrift:"name,1" db:"name" json:"name"` + Props map[string]*Value `thrift:"props,2" db:"props" json:"props"` +} + +func NewTag() *Tag { + return &Tag{} +} + + +func (p *Tag) GetName() []byte { + return p.Name +} + +func (p *Tag) GetProps() map[string]*Value { + return p.Props +} +func (p *Tag) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *Tag) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + p.Name = v +} + return nil +} + +func (p *Tag) ReadField2(iprot thrift.Protocol) error { + _, _, size, err := iprot.ReadMapBegin() + if err != nil { + return thrift.PrependError("error reading map begin: ", err) + } + tMap := make(map[string]*Value, size) + p.Props = tMap + for i := 0; i < size; i ++ { +var _key7 string + if v, err := iprot.ReadString(); err != nil { + return thrift.PrependError("error reading field 0: ", err) +} else { + _key7 = v +} + _val8 := NewValue() + if err := _val8.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _val8), err) + } + p.Props[_key7] = _val8 + } + if err := iprot.ReadMapEnd(); err != nil { + return thrift.PrependError("error reading map end: ", err) + } + return nil +} + +func (p *Tag) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("Tag"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *Tag) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("name", thrift.STRING, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:name: ", p), err) } + if err := oprot.WriteBinary(p.Name); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.name (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:name: ", p), err) } + return err +} + +func (p *Tag) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("props", thrift.MAP, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:props: ", p), err) } + if err := oprot.WriteMapBegin(thrift.STRING, thrift.STRUCT, len(p.Props)); err != nil { + return thrift.PrependError("error writing map begin: ", err) + } + for k, v := range p.Props { + if err := oprot.WriteString(string(k)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err) } + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteMapEnd(); err != nil { + return thrift.PrependError("error writing map end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:props: ", p), err) } + return err +} + +func (p *Tag) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Tag(%+v)", *p) +} + +// Attributes: +// - Vid +// - Tags +type Vertex struct { + Vid *Value `thrift:"vid,1" db:"vid" json:"vid"` + Tags []*Tag `thrift:"tags,2" db:"tags" json:"tags"` +} + +func NewVertex() *Vertex { + return &Vertex{} +} + +var Vertex_Vid_DEFAULT *Value +func (p *Vertex) GetVid() *Value { + if !p.IsSetVid() { + return Vertex_Vid_DEFAULT + } +return p.Vid +} + +func (p *Vertex) GetTags() []*Tag { + return p.Tags +} +func (p *Vertex) IsSetVid() bool { + return p.Vid != nil +} + +func (p *Vertex) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *Vertex) ReadField1(iprot thrift.Protocol) error { + p.Vid = NewValue() + if err := p.Vid.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Vid), err) + } + return nil +} + +func (p *Vertex) ReadField2(iprot thrift.Protocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return thrift.PrependError("error reading list begin: ", err) + } + tSlice := make([]*Tag, 0, size) + p.Tags = tSlice + for i := 0; i < size; i ++ { + _elem9 := NewTag() + if err := _elem9.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem9), err) + } + p.Tags = append(p.Tags, _elem9) + } + if err := iprot.ReadListEnd(); err != nil { + return thrift.PrependError("error reading list end: ", err) + } + return nil +} + +func (p *Vertex) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("Vertex"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *Vertex) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("vid", thrift.STRUCT, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:vid: ", p), err) } + if err := p.Vid.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Vid), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:vid: ", p), err) } + return err +} + +func (p *Vertex) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("tags", thrift.LIST, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:tags: ", p), err) } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Tags)); err != nil { + return thrift.PrependError("error writing list begin: ", err) + } + for _, v := range p.Tags { + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return thrift.PrependError("error writing list end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:tags: ", p), err) } + return err +} + +func (p *Vertex) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Vertex(%+v)", *p) +} + +// Attributes: +// - Src +// - Dst +// - Type +// - Name +// - Ranking +// - Props +type Edge struct { + Src *Value `thrift:"src,1" db:"src" json:"src"` + Dst *Value `thrift:"dst,2" db:"dst" json:"dst"` + Type EdgeType `thrift:"type,3" db:"type" json:"type"` + Name []byte `thrift:"name,4" db:"name" json:"name"` + Ranking EdgeRanking `thrift:"ranking,5" db:"ranking" json:"ranking"` + Props map[string]*Value `thrift:"props,6" db:"props" json:"props"` +} + +func NewEdge() *Edge { + return &Edge{} +} + +var Edge_Src_DEFAULT *Value +func (p *Edge) GetSrc() *Value { + if !p.IsSetSrc() { + return Edge_Src_DEFAULT + } +return p.Src +} +var Edge_Dst_DEFAULT *Value +func (p *Edge) GetDst() *Value { + if !p.IsSetDst() { + return Edge_Dst_DEFAULT + } +return p.Dst +} + +func (p *Edge) GetType() EdgeType { + return p.Type +} + +func (p *Edge) GetName() []byte { + return p.Name +} + +func (p *Edge) GetRanking() EdgeRanking { + return p.Ranking +} + +func (p *Edge) GetProps() map[string]*Value { + return p.Props +} +func (p *Edge) IsSetSrc() bool { + return p.Src != nil +} + +func (p *Edge) IsSetDst() bool { + return p.Dst != nil +} + +func (p *Edge) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + case 5: + if err := p.ReadField5(iprot); err != nil { + return err + } + case 6: + if err := p.ReadField6(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *Edge) ReadField1(iprot thrift.Protocol) error { + p.Src = NewValue() + if err := p.Src.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Src), err) + } + return nil +} + +func (p *Edge) ReadField2(iprot thrift.Protocol) error { + p.Dst = NewValue() + if err := p.Dst.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Dst), err) + } + return nil +} + +func (p *Edge) ReadField3(iprot thrift.Protocol) error { + if v, err := iprot.ReadI32(); err != nil { + return thrift.PrependError("error reading field 3: ", err) +} else { + temp := EdgeType(v) + p.Type = temp +} + return nil +} + +func (p *Edge) ReadField4(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 4: ", err) +} else { + p.Name = v +} + return nil +} + +func (p *Edge) ReadField5(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 5: ", err) +} else { + temp := EdgeRanking(v) + p.Ranking = temp +} + return nil +} + +func (p *Edge) ReadField6(iprot thrift.Protocol) error { + _, _, size, err := iprot.ReadMapBegin() + if err != nil { + return thrift.PrependError("error reading map begin: ", err) + } + tMap := make(map[string]*Value, size) + p.Props = tMap + for i := 0; i < size; i ++ { +var _key10 string + if v, err := iprot.ReadString(); err != nil { + return thrift.PrependError("error reading field 0: ", err) +} else { + _key10 = v +} + _val11 := NewValue() + if err := _val11.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _val11), err) + } + p.Props[_key10] = _val11 + } + if err := iprot.ReadMapEnd(); err != nil { + return thrift.PrependError("error reading map end: ", err) + } + return nil +} + +func (p *Edge) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("Edge"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := p.writeField3(oprot); err != nil { return err } + if err := p.writeField4(oprot); err != nil { return err } + if err := p.writeField5(oprot); err != nil { return err } + if err := p.writeField6(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *Edge) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("src", thrift.STRUCT, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:src: ", p), err) } + if err := p.Src.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Src), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:src: ", p), err) } + return err +} + +func (p *Edge) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("dst", thrift.STRUCT, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:dst: ", p), err) } + if err := p.Dst.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Dst), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:dst: ", p), err) } + return err +} + +func (p *Edge) writeField3(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("type", thrift.I32, 3); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:type: ", p), err) } + if err := oprot.WriteI32(int32(p.Type)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.type (3) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 3:type: ", p), err) } + return err +} + +func (p *Edge) writeField4(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("name", thrift.STRING, 4); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:name: ", p), err) } + if err := oprot.WriteBinary(p.Name); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.name (4) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 4:name: ", p), err) } + return err +} + +func (p *Edge) writeField5(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("ranking", thrift.I64, 5); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 5:ranking: ", p), err) } + if err := oprot.WriteI64(int64(p.Ranking)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.ranking (5) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 5:ranking: ", p), err) } + return err +} + +func (p *Edge) writeField6(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("props", thrift.MAP, 6); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 6:props: ", p), err) } + if err := oprot.WriteMapBegin(thrift.STRING, thrift.STRUCT, len(p.Props)); err != nil { + return thrift.PrependError("error writing map begin: ", err) + } + for k, v := range p.Props { + if err := oprot.WriteString(string(k)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err) } + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteMapEnd(); err != nil { + return thrift.PrependError("error writing map end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 6:props: ", p), err) } + return err +} + +func (p *Edge) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Edge(%+v)", *p) +} + +// Attributes: +// - Dst +// - Type +// - Name +// - Ranking +// - Props +type Step struct { + Dst *Vertex `thrift:"dst,1" db:"dst" json:"dst"` + Type EdgeType `thrift:"type,2" db:"type" json:"type"` + Name []byte `thrift:"name,3" db:"name" json:"name"` + Ranking EdgeRanking `thrift:"ranking,4" db:"ranking" json:"ranking"` + Props map[string]*Value `thrift:"props,5" db:"props" json:"props"` +} + +func NewStep() *Step { + return &Step{} +} + +var Step_Dst_DEFAULT *Vertex +func (p *Step) GetDst() *Vertex { + if !p.IsSetDst() { + return Step_Dst_DEFAULT + } +return p.Dst +} + +func (p *Step) GetType() EdgeType { + return p.Type +} + +func (p *Step) GetName() []byte { + return p.Name +} + +func (p *Step) GetRanking() EdgeRanking { + return p.Ranking +} + +func (p *Step) GetProps() map[string]*Value { + return p.Props +} +func (p *Step) IsSetDst() bool { + return p.Dst != nil +} + +func (p *Step) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + case 5: + if err := p.ReadField5(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *Step) ReadField1(iprot thrift.Protocol) error { + p.Dst = NewVertex() + if err := p.Dst.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Dst), err) + } + return nil +} + +func (p *Step) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadI32(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + temp := EdgeType(v) + p.Type = temp +} + return nil +} + +func (p *Step) ReadField3(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 3: ", err) +} else { + p.Name = v +} + return nil +} + +func (p *Step) ReadField4(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 4: ", err) +} else { + temp := EdgeRanking(v) + p.Ranking = temp +} + return nil +} + +func (p *Step) ReadField5(iprot thrift.Protocol) error { + _, _, size, err := iprot.ReadMapBegin() + if err != nil { + return thrift.PrependError("error reading map begin: ", err) + } + tMap := make(map[string]*Value, size) + p.Props = tMap + for i := 0; i < size; i ++ { +var _key12 string + if v, err := iprot.ReadString(); err != nil { + return thrift.PrependError("error reading field 0: ", err) +} else { + _key12 = v +} + _val13 := NewValue() + if err := _val13.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _val13), err) + } + p.Props[_key12] = _val13 + } + if err := iprot.ReadMapEnd(); err != nil { + return thrift.PrependError("error reading map end: ", err) + } + return nil +} + +func (p *Step) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("Step"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := p.writeField3(oprot); err != nil { return err } + if err := p.writeField4(oprot); err != nil { return err } + if err := p.writeField5(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *Step) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("dst", thrift.STRUCT, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:dst: ", p), err) } + if err := p.Dst.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Dst), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:dst: ", p), err) } + return err +} + +func (p *Step) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("type", thrift.I32, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:type: ", p), err) } + if err := oprot.WriteI32(int32(p.Type)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.type (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:type: ", p), err) } + return err +} + +func (p *Step) writeField3(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("name", thrift.STRING, 3); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:name: ", p), err) } + if err := oprot.WriteBinary(p.Name); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.name (3) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 3:name: ", p), err) } + return err +} + +func (p *Step) writeField4(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("ranking", thrift.I64, 4); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:ranking: ", p), err) } + if err := oprot.WriteI64(int64(p.Ranking)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.ranking (4) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 4:ranking: ", p), err) } + return err +} + +func (p *Step) writeField5(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("props", thrift.MAP, 5); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 5:props: ", p), err) } + if err := oprot.WriteMapBegin(thrift.STRING, thrift.STRUCT, len(p.Props)); err != nil { + return thrift.PrependError("error writing map begin: ", err) + } + for k, v := range p.Props { + if err := oprot.WriteString(string(k)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err) } + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteMapEnd(); err != nil { + return thrift.PrependError("error writing map end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 5:props: ", p), err) } + return err +} + +func (p *Step) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Step(%+v)", *p) +} + +// Attributes: +// - Src +// - Steps +type Path struct { + Src *Vertex `thrift:"src,1" db:"src" json:"src"` + Steps []*Step `thrift:"steps,2" db:"steps" json:"steps"` +} + +func NewPath() *Path { + return &Path{} +} + +var Path_Src_DEFAULT *Vertex +func (p *Path) GetSrc() *Vertex { + if !p.IsSetSrc() { + return Path_Src_DEFAULT + } +return p.Src +} + +func (p *Path) GetSteps() []*Step { + return p.Steps +} +func (p *Path) IsSetSrc() bool { + return p.Src != nil +} + +func (p *Path) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *Path) ReadField1(iprot thrift.Protocol) error { + p.Src = NewVertex() + if err := p.Src.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Src), err) + } + return nil +} + +func (p *Path) ReadField2(iprot thrift.Protocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return thrift.PrependError("error reading list begin: ", err) + } + tSlice := make([]*Step, 0, size) + p.Steps = tSlice + for i := 0; i < size; i ++ { + _elem14 := NewStep() + if err := _elem14.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem14), err) + } + p.Steps = append(p.Steps, _elem14) + } + if err := iprot.ReadListEnd(); err != nil { + return thrift.PrependError("error reading list end: ", err) + } + return nil +} + +func (p *Path) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("Path"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *Path) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("src", thrift.STRUCT, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:src: ", p), err) } + if err := p.Src.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Src), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:src: ", p), err) } + return err +} + +func (p *Path) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("steps", thrift.LIST, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:steps: ", p), err) } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Steps)); err != nil { + return thrift.PrependError("error writing list begin: ", err) + } + for _, v := range p.Steps { + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return thrift.PrependError("error writing list end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:steps: ", p), err) } + return err +} + +func (p *Path) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Path(%+v)", *p) +} + +// Attributes: +// - Host +// - Port +type HostAddr struct { + Host string `thrift:"host,1" db:"host" json:"host"` + Port Port `thrift:"port,2" db:"port" json:"port"` +} + +func NewHostAddr() *HostAddr { + return &HostAddr{} +} + + +func (p *HostAddr) GetHost() string { + return p.Host +} + +func (p *HostAddr) GetPort() Port { + return p.Port +} +func (p *HostAddr) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *HostAddr) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadString(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + p.Host = v +} + return nil +} + +func (p *HostAddr) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadI32(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + temp := Port(v) + p.Port = temp +} + return nil +} + +func (p *HostAddr) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("HostAddr"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *HostAddr) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("host", thrift.STRING, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:host: ", p), err) } + if err := oprot.WriteString(string(p.Host)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.host (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:host: ", p), err) } + return err +} + +func (p *HostAddr) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("port", thrift.I32, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:port: ", p), err) } + if err := oprot.WriteI32(int32(p.Port)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.port (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:port: ", p), err) } + return err +} + +func (p *HostAddr) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("HostAddr(%+v)", *p) +} + +// Attributes: +// - Key +// - Value +type KeyValue struct { + Key []byte `thrift:"key,1" db:"key" json:"key"` + Value []byte `thrift:"value,2" db:"value" json:"value"` +} + +func NewKeyValue() *KeyValue { + return &KeyValue{} +} + + +func (p *KeyValue) GetKey() []byte { + return p.Key +} + +func (p *KeyValue) GetValue() []byte { + return p.Value +} +func (p *KeyValue) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *KeyValue) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + p.Key = v +} + return nil +} + +func (p *KeyValue) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + p.Value = v +} + return nil +} + +func (p *KeyValue) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("KeyValue"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *KeyValue) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("key", thrift.STRING, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:key: ", p), err) } + if err := oprot.WriteBinary(p.Key); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.key (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:key: ", p), err) } + return err +} + +func (p *KeyValue) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("value", thrift.STRING, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:value: ", p), err) } + if err := oprot.WriteBinary(p.Value); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.value (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:value: ", p), err) } + return err +} + +func (p *KeyValue) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("KeyValue(%+v)", *p) +} + +// Attributes: +// - LogID +// - TermID +type LogInfo struct { + LogID LogID `thrift:"log_id,1" db:"log_id" json:"log_id"` + TermID TermID `thrift:"term_id,2" db:"term_id" json:"term_id"` +} + +func NewLogInfo() *LogInfo { + return &LogInfo{} +} + + +func (p *LogInfo) GetLogID() LogID { + return p.LogID +} + +func (p *LogInfo) GetTermID() TermID { + return p.TermID +} +func (p *LogInfo) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *LogInfo) ReadField1(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 1: ", err) +} else { + temp := LogID(v) + p.LogID = temp +} + return nil +} + +func (p *LogInfo) ReadField2(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 2: ", err) +} else { + temp := TermID(v) + p.TermID = temp +} + return nil +} + +func (p *LogInfo) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("LogInfo"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := p.writeField2(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *LogInfo) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("log_id", thrift.I64, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:log_id: ", p), err) } + if err := oprot.WriteI64(int64(p.LogID)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.log_id (1) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:log_id: ", p), err) } + return err +} + +func (p *LogInfo) writeField2(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("term_id", thrift.I64, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:term_id: ", p), err) } + if err := oprot.WriteI64(int64(p.TermID)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.term_id (2) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:term_id: ", p), err) } + return err +} + +func (p *LogInfo) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("LogInfo(%+v)", *p) +} + +// Attributes: +// - Info +type PartitionBackupInfo struct { + Info map[PartitionID]*LogInfo `thrift:"info,1" db:"info" json:"info"` +} + +func NewPartitionBackupInfo() *PartitionBackupInfo { + return &PartitionBackupInfo{} +} + + +func (p *PartitionBackupInfo) GetInfo() map[PartitionID]*LogInfo { + return p.Info +} +func (p *PartitionBackupInfo) Read(iprot thrift.Protocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { break; } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *PartitionBackupInfo) ReadField1(iprot thrift.Protocol) error { + _, _, size, err := iprot.ReadMapBegin() + if err != nil { + return thrift.PrependError("error reading map begin: ", err) + } + tMap := make(map[PartitionID]*LogInfo, size) + p.Info = tMap + for i := 0; i < size; i ++ { +var _key15 PartitionID + if v, err := iprot.ReadI32(); err != nil { + return thrift.PrependError("error reading field 0: ", err) +} else { + temp := PartitionID(v) + _key15 = temp +} + _val16 := NewLogInfo() + if err := _val16.Read(iprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _val16), err) + } + p.Info[_key15] = _val16 + } + if err := iprot.ReadMapEnd(); err != nil { + return thrift.PrependError("error reading map end: ", err) + } + return nil +} + +func (p *PartitionBackupInfo) Write(oprot thrift.Protocol) error { + if err := oprot.WriteStructBegin("PartitionBackupInfo"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } + if err := p.writeField1(oprot); err != nil { return err } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) } + return nil +} + +func (p *PartitionBackupInfo) writeField1(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("info", thrift.MAP, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:info: ", p), err) } + if err := oprot.WriteMapBegin(thrift.I32, thrift.STRUCT, len(p.Info)); err != nil { + return thrift.PrependError("error writing map begin: ", err) + } + for k, v := range p.Info { + if err := oprot.WriteI32(int32(k)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err) } + if err := v.Write(oprot); err != nil { + return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err) + } + } + if err := oprot.WriteMapEnd(); err != nil { + return thrift.PrependError("error writing map end: ", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:info: ", p), err) } + return err +} + +func (p *PartitionBackupInfo) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("PartitionBackupInfo(%+v)", *p) +} + diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/result_set.go b/vendor/github.com/vesoft-inc/nebula-go/v2/result_set.go new file mode 100644 index 000000000..5ab85ebaa --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/result_set.go @@ -0,0 +1,992 @@ +/* Copyright (c) 2020 vesoft inc. All rights reserved. +* +* This source code is licensed under Apache 2.0 License, +* attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +package nebula_go + +import ( + "bytes" + "encoding/json" + "fmt" + "sort" + "strings" + + "github.com/vesoft-inc/nebula-go/v2/nebula" + "github.com/vesoft-inc/nebula-go/v2/nebula/graph" +) + +type ResultSet struct { + resp *graph.ExecutionResponse + columnNames []string + colNameIndexMap map[string]int +} + +type Record struct { + columnNames *[]string + _record []*ValueWrapper + colNameIndexMap *map[string]int +} + +type Node struct { + vertex *nebula.Vertex + tags []string // tag name + tagNameIndexMap map[string]int +} + +type Relationship struct { + edge *nebula.Edge +} + +type segment struct { + startNode *Node + relationship *Relationship + endNode *Node +} + +type PathWrapper struct { + path *nebula.Path + nodeList []*Node + relationshipList []*Relationship + segments []segment +} + +type ErrorCode int64 + +const ( + ErrorCode_SUCCEEDED ErrorCode = ErrorCode(graph.ErrorCode_SUCCEEDED) + ErrorCode_E_DISCONNECTED ErrorCode = ErrorCode(graph.ErrorCode_E_DISCONNECTED) + ErrorCode_E_FAIL_TO_CONNECT ErrorCode = ErrorCode(graph.ErrorCode_E_FAIL_TO_CONNECT) + ErrorCode_E_RPC_FAILURE ErrorCode = ErrorCode(graph.ErrorCode_E_RPC_FAILURE) + ErrorCode_E_BAD_USERNAME_PASSWORD ErrorCode = ErrorCode(graph.ErrorCode_E_BAD_USERNAME_PASSWORD) + ErrorCode_E_SESSION_INVALID ErrorCode = ErrorCode(graph.ErrorCode_E_SESSION_INVALID) + ErrorCode_E_SESSION_TIMEOUT ErrorCode = ErrorCode(graph.ErrorCode_E_SESSION_TIMEOUT) + ErrorCode_E_SYNTAX_ERROR ErrorCode = ErrorCode(graph.ErrorCode_E_SYNTAX_ERROR) + ErrorCode_E_EXECUTION_ERROR ErrorCode = ErrorCode(graph.ErrorCode_E_EXECUTION_ERROR) + ErrorCode_E_STATEMENT_EMPTY ErrorCode = ErrorCode(graph.ErrorCode_E_STATEMENT_EMPTY) + ErrorCode_E_USER_NOT_FOUND ErrorCode = ErrorCode(graph.ErrorCode_E_USER_NOT_FOUND) + ErrorCode_E_BAD_PERMISSION ErrorCode = ErrorCode(graph.ErrorCode_E_BAD_PERMISSION) + ErrorCode_E_SEMANTIC_ERROR ErrorCode = ErrorCode(graph.ErrorCode_E_SEMANTIC_ERROR) + ErrorCode_E_PARTIAL_SUCCEEDED ErrorCode = ErrorCode(graph.ErrorCode_E_PARTIAL_SUCCEEDED) +) + +func genResultSet(resp *graph.ExecutionResponse) *ResultSet { + var colNames []string + var colNameIndexMap = make(map[string]int) + + if resp.Data == nil { // if resp.Data != nil then resp.Data.row and resp.Data.colNames wont be nil + return &ResultSet{ + resp: resp, + columnNames: colNames, + colNameIndexMap: colNameIndexMap, + } + } + for i, name := range resp.Data.ColumnNames { + colNames = append(colNames, string(name)) + colNameIndexMap[string(name)] = i + } + + return &ResultSet{ + resp: resp, + columnNames: colNames, + colNameIndexMap: colNameIndexMap, + } +} + +func genValWarps(row *nebula.Row) ([]*ValueWrapper, error) { + if row == nil { + return nil, fmt.Errorf("Failed to generate valueWrapper: invalid row") + } + var valWraps []*ValueWrapper + for _, val := range row.Values { + if val == nil { + return nil, fmt.Errorf("Failed to generate valueWrapper: value is nil") + } + valWraps = append(valWraps, &ValueWrapper{val}) + } + return valWraps, nil +} + +func genNode(vertex *nebula.Vertex) (*Node, error) { + if vertex == nil { + return nil, fmt.Errorf("Failed to generate Node: invalid vertex") + } + var tags []string + nameIndex := make(map[string]int) + + // Iterate through all tags of the vertex + for i, tag := range vertex.GetTags() { + name := string(tag.Name) + // Get tags + tags = append(tags, name) + nameIndex[name] = i + } + + return &Node{ + vertex: vertex, + tags: tags, + tagNameIndexMap: nameIndex, + }, nil +} + +func genRelationship(edge *nebula.Edge) (*Relationship, error) { + if edge == nil { + return nil, fmt.Errorf("Failed to generate Relationship: invalid edge") + } + return &Relationship{ + edge: edge, + }, nil +} + +func genPathWrapper(path *nebula.Path) (*PathWrapper, error) { + if path == nil { + return nil, fmt.Errorf("Failed to generate Path Wrapper: invalid path") + } + var ( + nodeList []*Node + relationshipList []*Relationship + segList []segment + edge *nebula.Edge + segStartNode *Node + segEndNode *Node + segType nebula.EdgeType + ) + src, err := genNode(path.Src) + if err != nil { + return nil, err + } + nodeList = append(nodeList, src) + + for _, step := range path.Steps { + dst, err := genNode(step.Dst) + if err != nil { + return nil, err + } + nodeList = append(nodeList, dst) + // determine direction + stepType := step.Type + if stepType > 0 { + segStartNode = src + segEndNode = dst + segType = stepType + } else { + segStartNode = dst // switch with src + segEndNode = src + segType = -stepType + } + edge = &nebula.Edge{ + Src: segStartNode.getRawID(), + Dst: segEndNode.getRawID(), + Type: segType, + Name: step.Name, + Ranking: step.Ranking, + Props: step.Props, + } + relationship, err := genRelationship(edge) + if err != nil { + return nil, err + } + relationshipList = append(relationshipList, relationship) + + // Check segments + if len(segList) > 0 { + prevStart := segList[len(segList)-1].startNode.GetID() + prevEnd := segList[len(segList)-1].endNode.GetID() + nextStart := segStartNode.GetID() + nextEnd := segEndNode.GetID() + if prevStart.String() != nextStart.String() && prevStart.String() != nextEnd.String() && + prevEnd.String() != nextStart.String() && prevEnd.String() != nextEnd.String() { + return nil, fmt.Errorf("Failed to generate PathWrapper, Path received is invalid") + } + } + segList = append(segList, segment{ + startNode: segStartNode, + relationship: relationship, + endNode: segEndNode, + }) + src = dst + } + return &PathWrapper{ + path: path, + nodeList: nodeList, + relationshipList: relationshipList, + segments: segList, + }, nil +} + +// Returns ExecutionResponse as a JSON []byte. +// To get the string value in the nested JSON struct, decode with base64 +func (res ResultSet) MarshalJSON() ([]byte, error) { + if res.resp.Data == nil { + return nil, fmt.Errorf("Failed to generate JSON, DataSet is empty") + } + return json.Marshal(res.resp.Data) +} + +// Returns a 2D array of strings representing the query result +// If resultSet.resp.data is nil, returns an empty 2D array +func (res ResultSet) AsStringTable() [][]string { + var resTable [][]string + colNames := res.GetColNames() + resTable = append(resTable, colNames) + rows := res.GetRows() + for _, row := range rows { + var tempRow []string + for _, val := range row.Values { + tempRow = append(tempRow, ValueWrapper{val}.String()) + } + resTable = append(resTable, tempRow) + } + return resTable +} + +// Returns all values in the given column +func (res ResultSet) GetValuesByColName(colName string) ([]*ValueWrapper, error) { + if !res.hasColName(colName) { + return nil, fmt.Errorf("Failed to get values, given column name '%s' does not exist", colName) + } + // Get index + index := res.colNameIndexMap[colName] + var valList []*ValueWrapper + for _, row := range res.resp.Data.Rows { + valList = append(valList, &ValueWrapper{row.Values[index]}) + } + return valList, nil +} + +// Returns all values in the row at given index +func (res ResultSet) GetRowValuesByIndex(index int) (*Record, error) { + if err := checkIndex(index, res.resp.Data.Rows); err != nil { + return nil, err + } + valWrap, err := genValWarps(res.resp.Data.Rows[index]) + if err != nil { + return nil, err + } + return &Record{ + columnNames: &res.columnNames, + _record: valWrap, + colNameIndexMap: &res.colNameIndexMap, + }, nil +} + +// Returns the number of total rows +func (res ResultSet) GetRowSize() int { + if res.resp.Data == nil { + return 0 + } + return len(res.resp.Data.Rows) +} + +// Returns the number of total columns +func (res ResultSet) GetColSize() int { + if res.resp.Data == nil { + return 0 + } + return len(res.resp.Data.ColumnNames) +} + +// Returns all rows +func (res ResultSet) GetRows() []*nebula.Row { + if res.resp.Data == nil { + var empty []*nebula.Row + return empty + } + return res.resp.Data.Rows +} + +func (res ResultSet) GetColNames() []string { + return res.columnNames +} + +// Returns an integer representing an error type +// 0 ErrorCode_SUCCEEDED +// -1 ErrorCode_E_DISCONNECTED +// -2 ErrorCode_E_FAIL_TO_CONNECT +// -3 ErrorCode_E_RPC_FAILURE +// -4 ErrorCode_E_BAD_USERNAME_PASSWORD +// -5 ErrorCode_E_SESSION_INVALID +// -6 ErrorCode_E_SESSION_TIMEOUT +// -7 ErrorCode_E_SYNTAX_ERROR +// -8 ErrorCode_E_EXECUTION_ERROR +// -9 ErrorCode_E_STATEMENT_EMPTY +// -10 ErrorCode_E_USER_NOT_FOUND +// -11 ErrorCode_E_BAD_PERMISSION +// -12 ErrorCode_E_SEMANTIC_ERROR +func (res ResultSet) GetErrorCode() ErrorCode { + return ErrorCode(int64(res.resp.ErrorCode)) +} + +func (res ResultSet) GetLatency() int32 { + return res.resp.LatencyInUs +} + +func (res ResultSet) GetSpaceName() string { + if res.resp.SpaceName == nil { + return "" + } + return string(res.resp.SpaceName) +} + +func (res ResultSet) GetErrorMsg() string { + if res.resp.ErrorMsg == nil { + return "" + } + return string(res.resp.ErrorMsg) +} + +func (res ResultSet) IsSetPlanDesc() bool { + return res.resp.PlanDesc != nil +} + +func (res ResultSet) GetPlanDesc() *graph.PlanDescription { + return res.resp.PlanDesc +} + +func (res ResultSet) IsSetComment() bool { + return res.resp.Comment != nil +} + +func (res ResultSet) GetComment() string { + if res.resp.Comment == nil { + return "" + } + return string(res.resp.Comment) +} + +func (res ResultSet) IsSetData() bool { + return res.resp.Data != nil +} + +func (res ResultSet) IsEmpty() bool { + if !res.IsSetData() || len(res.resp.Data.Rows) == 0 { + return true + } + return false +} + +func (res ResultSet) IsSucceed() bool { + return res.GetErrorCode() == ErrorCode_SUCCEEDED +} + +func (res ResultSet) IsPartialSucceed() bool { + return res.GetErrorCode() == ErrorCode_E_PARTIAL_SUCCEEDED +} + +func (res ResultSet) hasColName(colName string) bool { + if _, ok := res.colNameIndexMap[colName]; ok { + return true + } + return false +} + +// Returns value in the record at given column index +func (record Record) GetValueByIndex(index int) (*ValueWrapper, error) { + if err := checkIndex(index, record._record); err != nil { + return nil, err + } + return record._record[index], nil +} + +// Returns value in the record at given column name +func (record Record) GetValueByColName(colName string) (*ValueWrapper, error) { + if !record.hasColName(colName) { + return nil, fmt.Errorf("Failed to get values, given column name '%s' does not exist", colName) + } + // Get index + index := (*record.colNameIndexMap)[colName] + return record._record[index], nil +} + +func (record Record) String() string { + var strList []string + for _, val := range record._record { + strList = append(strList, val.String()) + } + return strings.Join(strList, ", ") +} + +func (record Record) hasColName(colName string) bool { + if _, ok := (*record.colNameIndexMap)[colName]; ok { + return true + } + return false +} + +// Returns a list of row vid +func (node Node) getRawID() *nebula.Value { + return node.vertex.GetVid() +} + +// Returns a list of vid of node +func (node Node) GetID() ValueWrapper { + return ValueWrapper{node.vertex.GetVid()} +} + +// Returns a list of tag names of node +func (node Node) GetTags() []string { + return node.tags +} + +// Check if node contains given label +func (node Node) HasTag(label string) bool { + if _, ok := node.tagNameIndexMap[label]; ok { + return true + } + return false +} + +// Returns all properties of a tag +func (node Node) Properties(tagName string) (map[string]*ValueWrapper, error) { + kvMap := make(map[string]*ValueWrapper) + // Check if label exists + if !node.HasTag(tagName) { + return nil, fmt.Errorf("Failed to get properties: Tag name %s does not exsist in the Node", tagName) + } + index := node.tagNameIndexMap[tagName] + for k, v := range node.vertex.Tags[index].Props { + kvMap[k] = &ValueWrapper{v} + } + return kvMap, nil +} + +// Returns all prop names of the given tag name +func (node Node) Keys(tagName string) ([]string, error) { + if !node.HasTag(tagName) { + return nil, fmt.Errorf("Failed to get properties: Tag name %s does not exsist in the Node", tagName) + } + var propNameList []string + index := node.tagNameIndexMap[tagName] + for k, _ := range node.vertex.Tags[index].Props { + propNameList = append(propNameList, k) + } + return propNameList, nil +} + +// Returns all prop values of the given tag name +func (node Node) Values(tagName string) ([]*ValueWrapper, error) { + if !node.HasTag(tagName) { + return nil, fmt.Errorf("Failed to get properties: Tag name %s does not exsist in the Node", tagName) + } + var propValList []*ValueWrapper + index := node.tagNameIndexMap[tagName] + for _, v := range node.vertex.Tags[index].Props { + propValList = append(propValList, &ValueWrapper{v}) + } + return propValList, nil +} + +// Node format: ("VertexID" :tag1{k0: v0,k1: v1}:tag2{k2: v2}) +func (node Node) String() string { + var keyList []string + var kvStr []string + var tagStr []string + vertex := node.vertex + vid := vertex.GetVid() + for _, tag := range vertex.GetTags() { + kvs := tag.GetProps() + tagName := tag.GetName() + for k, _ := range kvs { + keyList = append(keyList, k) + } + sort.Strings(keyList) + for _, k := range keyList { + kvTemp := fmt.Sprintf("%s: %s", k, ValueWrapper{kvs[k]}.String()) + kvStr = append(kvStr, kvTemp) + } + tagStr = append(tagStr, fmt.Sprintf("%s{%s}", tagName, strings.Join(kvStr, ", "))) + keyList = nil + kvStr = nil + } + if len(tagStr) == 0 { // No tag + return fmt.Sprintf("(%s)", ValueWrapper{vid}.String()) + } + return fmt.Sprintf("(%s :%s)", ValueWrapper{vid}.String(), strings.Join(tagStr, " :")) +} + +// Returns true if two nodes have same vid +func (n1 Node) IsEqualTo(n2 *Node) bool { + if n1.GetID().IsString() && n2.GetID().IsString() { + s1, _ := n1.GetID().AsString() + s2, _ := n2.GetID().AsString() + return s1 == s2 + } else if n1.GetID().IsInt() && n2.GetID().IsInt() { + s1, _ := n1.GetID().AsInt() + s2, _ := n2.GetID().AsInt() + return s1 == s2 + } + return false +} + +func (relationship Relationship) GetSrcVertexID() ValueWrapper { + if relationship.edge.Type > 0 { + return ValueWrapper{relationship.edge.GetSrc()} + } + return ValueWrapper{relationship.edge.GetDst()} +} + +func (relationship Relationship) GetDstVertexID() ValueWrapper { + if relationship.edge.Type > 0 { + return ValueWrapper{relationship.edge.GetDst()} + } + return ValueWrapper{relationship.edge.GetSrc()} +} + +func (relationship Relationship) GetEdgeName() string { + return string(relationship.edge.Name) +} + +func (relationship Relationship) GetRanking() int64 { + return int64(relationship.edge.Ranking) +} + +func (relationship Relationship) Properties() map[string]*ValueWrapper { + kvMap := make(map[string]*ValueWrapper) + var ( + keyList []string + valueList []*ValueWrapper + ) + for k, v := range relationship.edge.Props { + keyList = append(keyList, k) + valueList = append(valueList, &ValueWrapper{v}) + } + + for i := 0; i < len(keyList); i++ { + kvMap[keyList[i]] = valueList[i] + } + return kvMap +} + +// Returns a list of keys +func (relationship Relationship) Keys() []string { + var keys []string + for key, _ := range relationship.edge.GetProps() { + keys = append(keys, key) + } + return keys +} + +// Returns a list of values wrapped as ValueWrappers +func (relationship Relationship) Values() []*ValueWrapper { + var values []*ValueWrapper + for _, value := range relationship.edge.GetProps() { + values = append(values, &ValueWrapper{value}) + } + return values +} + +// Relationship format: [:edge src->dst @ranking {props}] +func (relationship Relationship) String() string { + edge := relationship.edge + var keyList []string + var kvStr []string + var src string + var dst string + for k, _ := range edge.Props { + keyList = append(keyList, k) + } + sort.Strings(keyList) + for _, k := range keyList { + kvTemp := fmt.Sprintf("%s: %s", k, ValueWrapper{edge.Props[k]}.String()) + kvStr = append(kvStr, kvTemp) + } + if relationship.edge.Type > 0 { + src = ValueWrapper{edge.Src}.String() + dst = ValueWrapper{edge.Dst}.String() + } else { + src = ValueWrapper{edge.Dst}.String() + dst = ValueWrapper{edge.Src}.String() + } + return fmt.Sprintf(`[:%s %s->%s @%d {%s}]`, + string(edge.Name), src, dst, edge.Ranking, fmt.Sprintf("%s", strings.Join(kvStr, ", "))) +} + +func (r1 Relationship) IsEqualTo(r2 *Relationship) bool { + if r1.edge.GetSrc().IsSetSVal() && r2.edge.GetSrc().IsSetSVal() && + r1.edge.GetDst().IsSetSVal() && r2.edge.GetDst().IsSetSVal() { + s1, _ := ValueWrapper{r1.edge.GetSrc()}.AsString() + s2, _ := ValueWrapper{r2.edge.GetSrc()}.AsString() + return s1 == s2 && string(r1.edge.Name) == string(r2.edge.Name) && r1.edge.Ranking == r2.edge.Ranking + } else if r1.edge.GetSrc().IsSetIVal() && r2.edge.GetSrc().IsSetIVal() && + r1.edge.GetDst().IsSetIVal() && r2.edge.GetDst().IsSetIVal() { + s1, _ := ValueWrapper{r1.edge.GetSrc()}.AsInt() + s2, _ := ValueWrapper{r2.edge.GetSrc()}.AsInt() + return s1 == s2 && string(r1.edge.Name) == string(r2.edge.Name) && r1.edge.Ranking == r2.edge.Ranking + } + return false +} + +func (path *PathWrapper) GetPathLength() int { + return len(path.segments) +} + +func (path *PathWrapper) GetNodes() []*Node { + return path.nodeList +} + +func (path *PathWrapper) GetRelationships() []*Relationship { + return path.relationshipList +} + +func (path *PathWrapper) GetSegments() []segment { + return path.segments +} + +func (path *PathWrapper) ContainsNode(node Node) bool { + for _, n := range path.nodeList { + if n.IsEqualTo(&node) { + return true + } + } + return false +} + +func (path *PathWrapper) ContainsRelationship(relationship *Relationship) bool { + for _, r := range path.relationshipList { + if r.IsEqualTo(relationship) { + return true + } + } + return false +} + +func (path *PathWrapper) GetStartNode() (*Node, error) { + if len(path.segments) == 0 { + return nil, fmt.Errorf("Failed to get start node, no node in the path") + } + return path.segments[0].startNode, nil +} + +func (path *PathWrapper) GetEndNode() (*Node, error) { + if len(path.segments) == 0 { + return nil, fmt.Errorf("Failed to get start node, no node in the path") + } + return path.segments[len(path.segments)-1].endNode, nil +} + +// Path format: <("VertexID" :tag1{k0: v0,k1: v1})-[:TypeName@ranking {edgeProps}]->("VertexID2" :tag1{k0: v0,k1: v1} :tag2{k2: v2})-[:TypeName@ranking {edgeProps}]->("VertexID3" :tag1{k0: v0,k1: v1})> +func (pathWrap *PathWrapper) String() string { + path := pathWrap.path + src := path.Src + steps := path.Steps + resStr := ValueWrapper{&nebula.Value{VVal: src}}.String() + for _, step := range steps { + var keyList []string + var kvStr []string + for k, _ := range step.Props { + keyList = append(keyList, k) + } + sort.Strings(keyList) + for _, k := range keyList { + kvTemp := fmt.Sprintf("%s: %s", k, ValueWrapper{step.Props[k]}.String()) + kvStr = append(kvStr, kvTemp) + } + var dirChar1 string + var dirChar2 string + if step.Type > 0 { + dirChar1 = "-" + dirChar2 = "->" + } else { + dirChar1 = "<-" + dirChar2 = "-" + } + resStr = resStr + fmt.Sprintf("%s[:%s@%d {%s}]%s%s", + dirChar1, + string(step.Name), + step.Ranking, + fmt.Sprintf("%s", strings.Join(kvStr, ", ")), + dirChar2, + ValueWrapper{&nebula.Value{VVal: step.Dst}}.String()) + } + return "<" + resStr + ">" +} + +func (p1 *PathWrapper) IsEqualTo(p2 *PathWrapper) bool { + // Check length + if len(p1.nodeList) != len(p2.nodeList) || len(p1.relationshipList) != len(p2.relationshipList) || + len(p1.segments) != len(p2.segments) { + return false + } + // Check nodes + for i := 0; i < len(p1.nodeList); i++ { + if !p1.nodeList[i].IsEqualTo(p2.nodeList[i]) { + return false + } + } + // Check relationships + for i := 0; i < len(p1.relationshipList); i++ { + if !p1.relationshipList[i].IsEqualTo(p2.relationshipList[i]) { + return false + } + } + // Check segments + for i := 0; i < len(p1.segments); i++ { + if !p1.segments[i].startNode.IsEqualTo(p2.segments[i].startNode) || + !p1.segments[i].endNode.IsEqualTo(p2.segments[i].endNode) || + !p1.segments[i].relationship.IsEqualTo(p2.segments[i].relationship) { + return false + } + } + return true +} + +func checkIndex(index int, list interface{}) error { + if _, ok := list.([]*nebula.Row); ok { + if index < 0 || index >= len(list.([]*nebula.Row)) { + return fmt.Errorf("Failed to get Value, the index is out of range") + } + return nil + } else if _, ok := list.([]*ValueWrapper); ok { + if index < 0 || index >= len(list.([]*ValueWrapper)) { + return fmt.Errorf("Failed to get Value, the index is out of range") + } + return nil + } + return fmt.Errorf("Given list type is invalid") +} + +func graphvizString(s string) string { + s = strings.Replace(s, "{", "\\{", -1) + s = strings.Replace(s, "}", "\\}", -1) + s = strings.Replace(s, "\"", "\\\"", -1) + s = strings.Replace(s, "[", "\\[", -1) + s = strings.Replace(s, "]", "\\]", -1) + return s +} + +func prettyFormatJsonString(value []byte) string { + var prettyJson bytes.Buffer + if err := json.Indent(&prettyJson, value, "", " "); err != nil { + return string(value) + } + return prettyJson.String() +} + +func name(planNodeDesc *graph.PlanNodeDescription) string { + return fmt.Sprintf("%s_%d", planNodeDesc.GetName(), planNodeDesc.GetId()) +} + +func condEdgeLabel(condNode *graph.PlanNodeDescription, doBranch bool) string { + name := strings.ToLower(string(condNode.GetName())) + if strings.HasPrefix(name, "select") { + if doBranch { + return "Y" + } + return "N" + } + if strings.HasPrefix(name, "loop") { + if doBranch { + return "Do" + } + } + return "" +} + +func nodeString(planNodeDesc *graph.PlanNodeDescription, planNodeName string) string { + var outputVar = graphvizString(string(planNodeDesc.GetOutputVar())) + var inputVar string + if planNodeDesc.IsSetDescription() { + desc := planNodeDesc.GetDescription() + for _, pair := range desc { + key := string(pair.GetKey()) + if key == "inputVar" { + inputVar = graphvizString(string(pair.GetValue())) + } + } + } + return fmt.Sprintf("\t\"%s\"[label=\"{%s|outputVar: %s|inputVar: %s}\", shape=Mrecord];\n", + planNodeName, planNodeName, outputVar, inputVar) +} + +func edgeString(start, end string) string { + return fmt.Sprintf("\t\"%s\"->\"%s\";\n", start, end) +} + +func conditionalEdgeString(start, end, label string) string { + return fmt.Sprintf("\t\"%s\"->\"%s\"[label=\"%s\", style=dashed];\n", start, end, label) +} + +func conditionalNodeString(name string) string { + return fmt.Sprintf("\t\"%s\"[shape=diamond];\n", name) +} + +func nodeById(p *graph.PlanDescription, nodeId int64) *graph.PlanNodeDescription { + line := p.GetNodeIndexMap()[nodeId] + return p.GetPlanNodeDescs()[line] +} + +func findBranchEndNode(p *graph.PlanDescription, condNodeId int64, isDoBranch bool) int64 { + for _, node := range p.GetPlanNodeDescs() { + if node.IsSetBranchInfo() { + bInfo := node.GetBranchInfo() + if bInfo.GetConditionNodeID() == condNodeId && bInfo.GetIsDoBranch() == isDoBranch { + return node.GetId() + } + } + } + return -1 +} + +func findFirstStartNodeFrom(p *graph.PlanDescription, nodeId int64) int64 { + node := nodeById(p, nodeId) + for { + deps := node.GetDependencies() + if len(deps) == 0 { + if strings.ToLower(string(node.GetName())) != "start" { + return -1 + } + return node.GetId() + } + node = nodeById(p, deps[0]) + } +} + +// explain/profile format="dot" +func (res ResultSet) MakeDotGraph() string { + p := res.GetPlanDesc() + planNodeDescs := p.GetPlanNodeDescs() + var builder strings.Builder + builder.WriteString("digraph exec_plan {\n") + builder.WriteString("\trankdir=BT;\n") + for _, planNodeDesc := range planNodeDescs { + planNodeName := name(planNodeDesc) + switch strings.ToLower(string(planNodeDesc.GetName())) { + case "select": + builder.WriteString(conditionalNodeString(planNodeName)) + dep := nodeById(p, planNodeDesc.GetDependencies()[0]) + // then branch + thenNodeId := findBranchEndNode(p, planNodeDesc.GetId(), true) + builder.WriteString(edgeString(name(nodeById(p, thenNodeId)), name(dep))) + thenStartId := findFirstStartNodeFrom(p, thenNodeId) + builder.WriteString(conditionalEdgeString(name(planNodeDesc), name(nodeById(p, thenStartId)), "Y")) + // else branch + elseNodeId := findBranchEndNode(p, planNodeDesc.GetId(), false) + builder.WriteString(edgeString(name(nodeById(p, elseNodeId)), name(dep))) + elseStartId := findFirstStartNodeFrom(p, elseNodeId) + builder.WriteString(conditionalEdgeString(name(planNodeDesc), name(nodeById(p, elseStartId)), "N")) + // dep + builder.WriteString(edgeString(name(dep), planNodeName)) + case "loop": + builder.WriteString(conditionalNodeString(planNodeName)) + dep := nodeById(p, planNodeDesc.GetDependencies()[0]) + // do branch + doNodeId := findBranchEndNode(p, planNodeDesc.GetId(), true) + builder.WriteString(edgeString(name(nodeById(p, doNodeId)), name(planNodeDesc))) + doStartId := findFirstStartNodeFrom(p, doNodeId) + builder.WriteString(conditionalEdgeString(name(planNodeDesc), name(nodeById(p, doStartId)), "Do")) + // dep + builder.WriteString(edgeString(name(dep), planNodeName)) + default: + builder.WriteString(nodeString(planNodeDesc, planNodeName)) + if planNodeDesc.IsSetDependencies() { + for _, depId := range planNodeDesc.GetDependencies() { + builder.WriteString(edgeString(name(nodeById(p, depId)), planNodeName)) + } + } + } + } + builder.WriteString("}") + return builder.String() +} + +// explain/profile format="dot:struct" +func (res ResultSet) MakeDotGraphByStruct() string { + p := res.GetPlanDesc() + planNodeDescs := p.GetPlanNodeDescs() + var builder strings.Builder + builder.WriteString("digraph exec_plan {\n") + builder.WriteString("\trankdir=BT;\n") + for _, planNodeDesc := range planNodeDescs { + planNodeName := name(planNodeDesc) + switch strings.ToLower(string(planNodeDesc.GetName())) { + case "select": + builder.WriteString(conditionalNodeString(planNodeName)) + case "loop": + builder.WriteString(conditionalNodeString(planNodeName)) + default: + builder.WriteString(nodeString(planNodeDesc, planNodeName)) + } + + if planNodeDesc.IsSetDependencies() { + for _, depId := range planNodeDesc.GetDependencies() { + dep := nodeById(p, depId) + builder.WriteString(edgeString(name(dep), planNodeName)) + } + } + + if planNodeDesc.IsSetBranchInfo() { + branchInfo := planNodeDesc.GetBranchInfo() + condNode := nodeById(p, branchInfo.GetConditionNodeID()) + label := condEdgeLabel(condNode, branchInfo.GetIsDoBranch()) + builder.WriteString(conditionalEdgeString(planNodeName, name(condNode), label)) + } + } + builder.WriteString("}") + return builder.String() +} + +// explain/profile format="row" +func (res ResultSet) MakePlanByRow() [][]interface{} { + p := res.GetPlanDesc() + planNodeDescs := p.GetPlanNodeDescs() + var rows [][]interface{} + for _, planNodeDesc := range planNodeDescs { + var row []interface{} + row = append(row, planNodeDesc.GetId(), string(planNodeDesc.GetName())) + + if planNodeDesc.IsSetDependencies() { + var deps []string + for _, dep := range planNodeDesc.GetDependencies() { + deps = append(deps, fmt.Sprintf("%d", dep)) + } + row = append(row, strings.Join(deps, ",")) + } else { + row = append(row, "") + } + + if planNodeDesc.IsSetProfiles() { + var strArr []string + for i, profile := range planNodeDesc.GetProfiles() { + otherStats := profile.GetOtherStats() + if otherStats != nil { + strArr = append(strArr, "{") + } + s := fmt.Sprintf("ver: %d, rows: %d, execTime: %dus, totalTime: %dus", + i, profile.GetRows(), profile.GetExecDurationInUs(), profile.GetTotalDurationInUs()) + strArr = append(strArr, s) + + for k, v := range otherStats { + strArr = append(strArr, fmt.Sprintf("%s: %s", k, v)) + } + if otherStats != nil { + strArr = append(strArr, "}") + } + } + row = append(row, strings.Join(strArr, "\n")) + } else { + row = append(row, "") + } + + var columnInfo []string + if planNodeDesc.IsSetBranchInfo() { + branchInfo := planNodeDesc.GetBranchInfo() + columnInfo = append(columnInfo, fmt.Sprintf("branch: %t, nodeId: %d\n", + branchInfo.GetIsDoBranch(), branchInfo.GetConditionNodeID())) + } + + outputVar := fmt.Sprintf("outputVar: %s", prettyFormatJsonString(planNodeDesc.GetOutputVar())) + columnInfo = append(columnInfo, outputVar) + + if planNodeDesc.IsSetDescription() { + desc := planNodeDesc.GetDescription() + for _, pair := range desc { + value := prettyFormatJsonString(pair.GetValue()) + columnInfo = append(columnInfo, fmt.Sprintf("%s: %s", string(pair.GetKey()), value)) + } + } + row = append(row, strings.Join(columnInfo, "\n")) + rows = append(rows, row) + } + return rows +} diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/session.go b/vendor/github.com/vesoft-inc/nebula-go/v2/session.go new file mode 100644 index 000000000..47f2a2629 --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/session.go @@ -0,0 +1,95 @@ +/* Copyright (c) 2020 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +package nebula_go + +import ( + "fmt" + + "github.com/facebook/fbthrift/thrift/lib/go/thrift" + graph "github.com/vesoft-inc/nebula-go/v2/nebula/graph" +) + +type Session struct { + sessionID int64 + connection *connection + connPool *ConnectionPool + log Logger +} + +// unsupported +// func (session *Session) ExecuteJson(stmt string) (*graph.ExecutionResponse, error) { +// return session.graph.ExecuteJson(session.sessionID, []byte(stmt)) +// } + +// Execute() returns the result of given query as a ResultSet +func (session *Session) Execute(stmt string) (*ResultSet, error) { + if session.connection == nil { + return nil, fmt.Errorf("Faied to execute: Session has been released") + } + resp, err := session.connection.execute(session.sessionID, stmt) + if err == nil { + return genResultSet(resp), nil + } + // Reconnect only if the tranport is closed + err2, ok := err.(thrift.TransportException) + if !ok { + return nil, err + } + if err2.TypeID() == thrift.END_OF_FILE { + _err := session.reConnect() + if _err != nil { + session.log.Error(fmt.Sprintf("Failed to reconnect, %s", _err.Error())) + return nil, _err + } + session.log.Info(fmt.Sprintf("Successfully reconnect to host: %s, port: %d", + session.connection.severAddress.Host, session.connection.severAddress.Port)) + // Execute with the new connetion + resp, err := session.connection.execute(session.sessionID, stmt) + if err != nil { + return nil, err + } + return genResultSet(resp), nil + } else { // No need to reconnect + session.log.Error(fmt.Sprintf("Error info: %s", err2.Error())) + return nil, err2 + } +} + +func (session *Session) reConnect() error { + newconnection, err := session.connPool.getIdleConn() + if err != nil { + err = fmt.Errorf(err.Error()) + return err + } + + // Release connection to pool + session.connPool.release(session.connection) + session.connection = newconnection + return nil +} + +// Logout and release connetion hold by session +func (session *Session) Release() { + if session == nil { + session.log.Warn("Session is nil, no need to release") + return + } + if session.connection == nil { + session.log.Warn("Session has been released") + return + } + if err := session.connection.signOut(session.sessionID); err != nil { + session.log.Warn(fmt.Sprintf("Sign out failed, %s", err.Error())) + } + // Release connection to pool + session.connPool.release(session.connection) + session.connection = nil +} + +func IsError(resp *graph.ExecutionResponse) bool { + return resp.GetErrorCode() != graph.ErrorCode_SUCCEEDED +} diff --git a/vendor/github.com/vesoft-inc/nebula-go/v2/value_wrapper.go b/vendor/github.com/vesoft-inc/nebula-go/v2/value_wrapper.go new file mode 100644 index 000000000..b0887b28f --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v2/value_wrapper.go @@ -0,0 +1,323 @@ +/* Copyright (c) 2020 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +package nebula_go + +import ( + "fmt" + "sort" + "strconv" + "strings" + + "github.com/vesoft-inc/nebula-go/v2/nebula" +) + +type ValueWrapper struct { + value *nebula.Value +} + +func (valueWrapper ValueWrapper) IsEmpty() bool { + return valueWrapper.GetType() == "empty" +} + +func (valueWrapper ValueWrapper) IsNull() bool { + return valueWrapper.value.IsSetNVal() +} + +func (valueWrapper ValueWrapper) IsBool() bool { + return valueWrapper.value.IsSetBVal() +} + +func (valueWrapper ValueWrapper) IsInt() bool { + return valueWrapper.value.IsSetIVal() +} + +func (valueWrapper ValueWrapper) IsFloat() bool { + return valueWrapper.value.IsSetFVal() +} + +func (valueWrapper ValueWrapper) IsString() bool { + return valueWrapper.value.IsSetSVal() +} + +func (valueWrapper ValueWrapper) IsTime() bool { + return valueWrapper.value.IsSetTVal() +} + +func (valueWrapper ValueWrapper) IsDate() bool { + return valueWrapper.value.IsSetDVal() +} + +func (valueWrapper ValueWrapper) IsDateTime() bool { + return valueWrapper.value.IsSetDtVal() +} + +func (valueWrapper ValueWrapper) IsList() bool { + return valueWrapper.value.IsSetLVal() +} + +func (valueWrapper ValueWrapper) IsSet() bool { + return valueWrapper.value.IsSetUVal() +} + +func (valueWrapper ValueWrapper) IsMap() bool { + return valueWrapper.value.IsSetMVal() +} + +func (valueWrapper ValueWrapper) IsVertex() bool { + return valueWrapper.value.IsSetVVal() +} + +func (valueWrapper ValueWrapper) IsEdge() bool { + return valueWrapper.value.IsSetEVal() +} + +func (valueWrapper ValueWrapper) IsPath() bool { + return valueWrapper.value.IsSetPVal() +} + +func (valueWrapper ValueWrapper) AsNull() (nebula.NullType, error) { + if valueWrapper.value.IsSetNVal() { + return valueWrapper.value.GetNVal(), nil + } + return -1, fmt.Errorf("Failed to convert value %s to Null", valueWrapper.GetType()) +} + +func (valueWrapper ValueWrapper) AsBool() (bool, error) { + if valueWrapper.value.IsSetBVal() { + return valueWrapper.value.GetBVal(), nil + } + return false, fmt.Errorf("Failed to convert value %s to bool", valueWrapper.GetType()) +} + +func (valueWrapper ValueWrapper) AsInt() (int64, error) { + if valueWrapper.value.IsSetIVal() { + return valueWrapper.value.GetIVal(), nil + } + return -1, fmt.Errorf("Failed to convert value %s to int", valueWrapper.GetType()) +} + +func (valueWrapper ValueWrapper) AsFloat() (float64, error) { + if valueWrapper.value.IsSetFVal() { + return valueWrapper.value.GetFVal(), nil + } + return -1, fmt.Errorf("Failed to convert value %s to float", valueWrapper.GetType()) +} + +func (valueWrapper ValueWrapper) AsString() (string, error) { + if valueWrapper.value.IsSetSVal() { + return string(valueWrapper.value.GetSVal()), nil + } + return "", fmt.Errorf("Failed to convert value %s to string", valueWrapper.GetType()) +} + +// TODO: Need to wrap TimeWrapper +func (valueWrapper ValueWrapper) AsTime() (*nebula.Time, error) { + if valueWrapper.value.IsSetTVal() { + return valueWrapper.value.GetTVal(), nil + } + return nil, fmt.Errorf("Failed to convert value %s to Time", valueWrapper.GetType()) +} + +func (valueWrapper ValueWrapper) AsDate() (*nebula.Date, error) { + if valueWrapper.value.IsSetDVal() { + return valueWrapper.value.GetDVal(), nil + } + return nil, fmt.Errorf("Failed to convert value %s to Date", valueWrapper.GetType()) +} + +func (valueWrapper ValueWrapper) AsDateTime() (*nebula.DateTime, error) { + if valueWrapper.value.IsSetDtVal() { + return valueWrapper.value.GetDtVal(), nil + } + return nil, fmt.Errorf("Failed to convert value %s to DateTime", valueWrapper.GetType()) +} + +func (valueWrapper ValueWrapper) AsList() ([]ValueWrapper, error) { + if valueWrapper.value.IsSetLVal() { + var varList []ValueWrapper + vals := valueWrapper.value.GetLVal().Values + for _, val := range vals { + varList = append(varList, ValueWrapper{val}) + } + return varList, nil + } + return nil, fmt.Errorf("Failed to convert value %s to List", valueWrapper.GetType()) +} + +func (valueWrapper ValueWrapper) AsDedupList() ([]ValueWrapper, error) { + if valueWrapper.value.IsSetUVal() { + var varList []ValueWrapper + vals := valueWrapper.value.GetUVal().Values + for _, val := range vals { + varList = append(varList, ValueWrapper{val}) + } + return varList, nil + } + return nil, fmt.Errorf("Failed to convert value %s to set(deduped list)", valueWrapper.GetType()) +} + +func (valueWrapper ValueWrapper) AsMap() (map[string]ValueWrapper, error) { + if valueWrapper.value.IsSetMVal() { + newMap := make(map[string]ValueWrapper) + + kvs := valueWrapper.value.GetMVal().Kvs + for key, val := range kvs { + newMap[key] = ValueWrapper{val} + } + return newMap, nil + } + return nil, fmt.Errorf("Failed to convert value %s to Map", valueWrapper.GetType()) +} + +func (valueWrapper ValueWrapper) AsNode() (*Node, error) { + if !valueWrapper.value.IsSetVVal() { + return nil, fmt.Errorf("Failed to convert value %s to Node, value is not an vertex", valueWrapper.GetType()) + } + vertex := valueWrapper.value.VVal + node, err := genNode(vertex) + if err != nil { + return nil, err + } + return node, nil +} + +func (valueWrapper ValueWrapper) AsRelationship() (*Relationship, error) { + if !valueWrapper.value.IsSetEVal() { + return nil, fmt.Errorf("Failed to convert value %s to Relationship, value is not an edge", valueWrapper.GetType()) + } + edge := valueWrapper.value.EVal + relationship, err := genRelationship(edge) + if err != nil { + return nil, err + } + return relationship, nil +} + +func (valueWrapper ValueWrapper) AsPath() (*PathWrapper, error) { + if !valueWrapper.value.IsSetPVal() { + return nil, fmt.Errorf("Failed to convert value %s to PathWrapper, value is not an edge", valueWrapper.GetType()) + } + path, err := genPathWrapper(valueWrapper.value.PVal) + if err != nil { + return nil, err + } + return path, nil +} + +// Returns the value type of value in the valueWrapper in string +func (valueWrapper ValueWrapper) GetType() string { + if valueWrapper.value.IsSetNVal() { + return "null" + } else if valueWrapper.value.IsSetBVal() { + return "bool" + } else if valueWrapper.value.IsSetIVal() { + return "int" + } else if valueWrapper.value.IsSetFVal() { + return "float" + } else if valueWrapper.value.IsSetSVal() { + return "string" + } else if valueWrapper.value.IsSetDVal() { + return "date" + } else if valueWrapper.value.IsSetTVal() { + return "time" + } else if valueWrapper.value.IsSetDtVal() { + return "datetime" + } else if valueWrapper.value.IsSetVVal() { + return "vertex" + } else if valueWrapper.value.IsSetEVal() { + return "edge" + } else if valueWrapper.value.IsSetPVal() { + return "path" + } else if valueWrapper.value.IsSetLVal() { + return "list" + } else if valueWrapper.value.IsSetMVal() { + return "map" + } else if valueWrapper.value.IsSetUVal() { + return "set" + } + return "empty" +} + +// String() returns the value in the ValueWrapper as a 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) +func (valWarp ValueWrapper) String() string { + value := valWarp.value + if value.IsSetNVal() { + return value.GetNVal().String() + } else if value.IsSetBVal() { + return fmt.Sprintf("%t", value.GetBVal()) + } else if value.IsSetIVal() { + return fmt.Sprintf("%d", value.GetIVal()) + } else if value.IsSetFVal() { + fStr := strconv.FormatFloat(value.GetFVal(), 'f', -1, 64) + if !strings.Contains(fStr, ".") { + fStr = fStr + ".0" + } + return fStr + } else if value.IsSetSVal() { + return `"` + string(value.GetSVal()) + `"` + } else if value.IsSetDVal() { // Date yyyy-mm-dd + date := value.GetDVal() + return fmt.Sprintf("%d-%02d-%02d", date.Year, date.Month, date.Day) + } else if value.IsSetTVal() { // Time HH:MM:SS.MS + time := value.GetTVal() + return fmt.Sprintf("%02d:%02d:%02d.%03d", time.Hour, time.Minute, time.Sec, time.Microsec) + } else if value.IsSetDtVal() { // DateTime yyyy-mm-ddTHH:MM:SS.MS TODO: add time zone + dateTime := value.GetDtVal() + return fmt.Sprintf("%d-%02d-%02dT%02d:%02d:%02d.%03d", + dateTime.Year, dateTime.Month, dateTime.Day, + dateTime.Hour, dateTime.Minute, dateTime.Sec, dateTime.Microsec) + } else if value.IsSetVVal() { // Vertex format: ("VertexID" :tag1{k0: v0,k1: v1}:tag2{k2: v2}) + vertex := value.GetVVal() + node, _ := genNode(vertex) + return node.String() + } else if value.IsSetEVal() { // Edge format: [:edge src->dst @ranking {propKey1: propVal1}] + edge := value.GetEVal() + relationship, _ := genRelationship(edge) + return relationship.String() + } else if value.IsSetPVal() { + // Path format: ("VertexID" :tag1{k0: v0,k1: v1})-[:TypeName@ranking {propKey1: propVal1}]->("VertexID2" :tag1{k0: v0,k1: v1} :tag2{k2: v2})-[:TypeName@ranking {propKey2: propVal2}]->("VertexID3" :tag1{k0: v0,k1: v1}) + path := value.GetPVal() + pathWrap, _ := genPathWrapper(path) + return pathWrap.String() + } else if value.IsSetLVal() { // List + lval := value.GetLVal() + var strs []string + for _, val := range lval.Values { + strs = append(strs, ValueWrapper{val}.String()) + } + return fmt.Sprintf("[%s]", strings.Join(strs, ", ")) + } else if value.IsSetMVal() { // Map + // {k0: v0, k1: v1} + mval := value.GetMVal() + var keyList []string + var output []string + kvs := mval.Kvs + for k := range kvs { + keyList = append(keyList, k) + } + sort.Strings(keyList) + for _, k := range keyList { + output = append(output, fmt.Sprintf("%s: %s", k, ValueWrapper{kvs[k]}.String())) + } + return fmt.Sprintf("{%s}", strings.Join(output, ", ")) + } else if value.IsSetUVal() { + // set to string + uval := value.GetUVal() + var strs []string + for _, val := range uval.Values { + strs = append(strs, ValueWrapper{val}.String()) + } + return fmt.Sprintf("[%s]", strings.Join(strs, ", ")) + } else { // is empty + return "" + } +} diff --git a/vendor/github.com/vesoft-inc/nebula-go/v3/Makefile b/vendor/github.com/vesoft-inc/nebula-go/v3/Makefile index d1a8ffeb7..b70fcb371 100644 --- a/vendor/github.com/vesoft-inc/nebula-go/v3/Makefile +++ b/vendor/github.com/vesoft-inc/nebula-go/v3/Makefile @@ -1,14 +1,16 @@ -.PHONY: build test fmt up up-ssl down ssl-test run-examples +.PHONY: build unit test fmt up up-ssl down ssl-test run-examples default: build build: fmt go mod tidy go build - +unit: + go mod tidy + go test -v -race --covermode=atomic --coverprofile coverage.out test: go mod tidy - go test -v -race + go test -v -race --tags=integration --covermode=atomic --coverprofile coverage.out fmt: go fmt @@ -22,13 +24,14 @@ down: cd ./nebula-docker-compose && docker-compose down -v ssl-test: - ssl_test=true go test -v -run TestSslConnection; + ssl_test=true go test -v --tags=integration -run TestSslConnection; ssl-test-self-signed: - self_signed=true go test -v -run TestSslConnection; + self_signed=true go test -v --tags=integration -run TestSslConnection; run-examples: go run basic_example/graph_client_basic_example.go && \ go run basic_example/parameter_example.go && \ go run gorountines_example/graph_client_goroutines_example.go && \ - go run json_example/parse_json_example.go + go run json_example/parse_json_example.go && \ + go run session_pool_example/session_pool_example.go diff --git a/vendor/github.com/vesoft-inc/nebula-go/v3/README.md b/vendor/github.com/vesoft-inc/nebula-go/v3/README.md index 0abda43d7..b7b48983e 100644 --- a/vendor/github.com/vesoft-inc/nebula-go/v3/README.md +++ b/vendor/github.com/vesoft-inc/nebula-go/v3/README.md @@ -1,13 +1,16 @@ # nebula-go + [![Go Reference](https://pkg.go.dev/badge/github.com/vesoft-inc/nebula-go/v3.svg)](https://pkg.go.dev/github.com/vesoft-inc/nebula-go/v3) +![functional tests](https://github.com/vesoft-inc/nebula-go/actions/workflows/test.yaml/badge.svg) +[![codecov](https://codecov.io/gh/vesoft-inc/nebula-go/branch/master/graph/badge.svg?token=dzUo5KdSux)](https://codecov.io/gh/vesoft-inc/nebula-go) **IMPORTANT: Code of Nebula go client has been transferred from [nebula-clients](https://github.com/vesoft-inc/nebula-clients) to this repository(nebula-go), and new releases in the future will be published in this repository. Please update your go.mod and imports correspondingly.** -Official Nebula Go client which communicates with the server using [fbthrift](https://github.com/facebook/fbthrift/). Currently the latest stable release is **[v3.0.0](https://github.com/vesoft-inc/nebula-go/tree/release-v3.0.0)** +Official Nebula Go client which communicates with the server using [fbthrift](https://github.com/facebook/fbthrift/). Currently the latest stable release is **[v3.3.0](https://github.com/vesoft-inc/nebula-go/tree/release-v3.3)** -The code in **master branch** will be updated to accommodate the nightly changes made in Nebula Graph. -To Use the console with a stable release of Nebula Graph, please check the branches and use the corresponding version. +The code in **master branch** will be updated to accommodate the nightly changes made in NebulaGraph. +To Use the console with a stable release of NebulaGraph, please check the branches and use the corresponding version. | Client version | Nebula Service Version| |:--------------:|:-------------------:| @@ -16,9 +19,11 @@ To Use the console with a stable release of Nebula Graph, please check the branc | **[v2.5.1](https://github.com/vesoft-inc/nebula-go/tree/v2.5.1)** | 2.5.0 | | **[v2.6.0](https://github.com/vesoft-inc/nebula-go/tree/v2.6.0)** | 2.6.0 | | **[v3.0.0](https://github.com/vesoft-inc/nebula-go/tree/v3.0.0)** | 3.0.0 | +| **[v3.1.x](https://github.com/vesoft-inc/nebula-go/tree/v3.1.0)** | 3.1.x | +| **[v3.2.x](https://github.com/vesoft-inc/nebula-go/tree/v3.2.0)** | 3.1.x-3.2.x | +| **[v3.3.x](https://github.com/vesoft-inc/nebula-go/tree/v3.3.0)** | 3.1.x-3.3.x | | **[master](https://github.com/vesoft-inc/nebula-go/tree/master)** | 3.x-nightly | - Please be careful not to modify the files in the nebula directory, these codes were all generated by fbthrift. **NOTE** Installing Nebula Go v2.5.0 could cause **checksum mismatch**, use v2.5.1 instead. @@ -28,18 +33,22 @@ Please be careful not to modify the files in the nebula directory, these codes w ```shell $ go get -u -v github.com/vesoft-inc/nebula-go/v3@master ``` + You can specify the version of Nebula-go by substituting `` in `$ go get -u -v github.com/vesoft-inc/nebula-go@`. -For example: - - for v3: `$ go get -u -v github.com/vesoft-inc/nebula-go/v3@v3.0.0` - for v2: `$ go get -u -v github.com/vesoft-inc/nebula-go/v2@v2.6.0` +For example: + + for v3: `$ go get -u -v github.com/vesoft-inc/nebula-go/v3@v3.3.0` + + for v2: `$ go get -u -v github.com/vesoft-inc/nebula-go/v2@v2.6.0` **Note**: You will get a message like this if you don't specify a tag: -> ``` + +> ```shell > $ go get -u -v github.com/vesoft-inc/nebula-go/v2@master > go: github.com/vesoft-inc/nebula-go/v2 master => v2.0.0-20210506025434-97d4168c5c4d > ``` -> Here the ` 20210506025434-97d4168c5c4d` is a version tag auto-generated by Github using commit date and SHA. +> +> Here the `20210506025434-97d4168c5c4d` is a version tag auto-generated by Github using commit date and SHA. > This should match the latest commit in the master branch. ## Usage example @@ -48,6 +57,14 @@ For example: [Code Example with Gorountines](https://github.com/vesoft-inc/nebula-go/tree/master/gorountines_example/graph_client_goroutines_example.go) +[Session Pool Example](https://github.com/vesoft-inc/nebula-go/blob/master/session_pool_example/session_pool_example.go) + +There are some limitations while using the session pool: +1. There MUST be an existing space in the DB before initializing the session pool. +2. Each session pool is corresponding to a single USER and a single Space. This is to ensure that the user's access control is consistent. i.g. The same user may have different access privileges in different spaces. If you need to run queries in different spaces, you may have multiple session pools. +3. Every time when sessinPool.execute() is called, the session will execute the query in the space set in the session pool config. +4. Commands that alter passwords or drop users should NOT be executed via session pool. + ## Licensing **Nebula GO** is under [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) license, so you can freely download, modify, and deploy the source code to meet your needs. You can also freely deploy **Nebula GO** as a back-end service to support your SaaS deployment. diff --git a/vendor/github.com/vesoft-inc/nebula-go/v3/configs.go b/vendor/github.com/vesoft-inc/nebula-go/v3/configs.go index f9e8aea62..6263e89eb 100644 --- a/vendor/github.com/vesoft-inc/nebula-go/v3/configs.go +++ b/vendor/github.com/vesoft-inc/nebula-go/v3/configs.go @@ -105,3 +105,126 @@ func openAndReadFile(path string) ([]byte, error) { } return b, nil } + +// SessionPoolConf is the configs of a session pool +// Note that the space name is bound to the session pool for its lifetime +type SessionPoolConf struct { + username string // username for authentication + password string // password for authentication + serviceAddrs []HostAddress // service addresses for session pool + hostIndex int // index of the host in ServiceAddrs that the next new session will connect to + spaceName string // The space name that all sessions in the pool are bound to + sslConfig *tls.Config // Optional SSL config for the connection + + // Basic pool configs + // Socket timeout and Socket connection timeout, unit: seconds + timeOut time.Duration + // The idleTime of the connection, unit: seconds + // If connection's idle time is longer than idleTime, it will be delete + // 0 value means the connection will not expire + idleTime time.Duration + // The max sessions in pool for all addresses + maxSize int + // The min sessions in pool for all addresses + minSize int +} + +type SessionPoolConfOption func(*SessionPoolConf) + +// NewSessionPoolConfOpt creates a new NewSessionPoolConf with the provided options +func NewSessionPoolConf( + username, password string, + serviceAddrs []HostAddress, + spaceName string, opts ...SessionPoolConfOption) (*SessionPoolConf, error) { + // Set default values for basic pool configs + newPoolConf := SessionPoolConf{ + username: username, + password: password, + serviceAddrs: serviceAddrs, + spaceName: spaceName, + timeOut: 0 * time.Millisecond, + idleTime: 0 * time.Millisecond, + maxSize: 30, + minSize: 1, + hostIndex: 0, + } + + // Iterate the given options and apply them to the config. + for _, overwrite := range opts { + overwrite(&newPoolConf) + } + + if err := newPoolConf.checkMandatoryFields(); err != nil { + return nil, err + } + return &newPoolConf, nil +} + +func WithSSLConfig(sslConfig *tls.Config) SessionPoolConfOption { + return func(conf *SessionPoolConf) { + conf.sslConfig = sslConfig + } +} + +func WithTimeOut(timeOut time.Duration) SessionPoolConfOption { + return func(conf *SessionPoolConf) { + conf.timeOut = timeOut + } +} + +func WithIdleTime(idleTime time.Duration) SessionPoolConfOption { + return func(conf *SessionPoolConf) { + conf.idleTime = idleTime + } +} + +func WithMaxSize(maxSize int) SessionPoolConfOption { + return func(conf *SessionPoolConf) { + conf.maxSize = maxSize + } +} + +func WithMinSize(minSize int) SessionPoolConfOption { + return func(conf *SessionPoolConf) { + conf.minSize = minSize + } +} + +func (conf *SessionPoolConf) checkMandatoryFields() error { + // Check mandatory fields + if conf.username == "" { + return fmt.Errorf("invalid session pool config: Username is empty") + } + if conf.password == "" { + return fmt.Errorf("invalid session pool config: Password is empty") + } + if len(conf.serviceAddrs) == 0 { + return fmt.Errorf("invalid session pool config: Service address is empty") + } + if conf.spaceName == "" { + return fmt.Errorf("invalid session pool config: Space name is empty") + } + return nil +} + +// checkBasicFields checks the basic fields of the config and +// sets a default value if the given field value is invalid +func (conf *SessionPoolConf) checkBasicFields(log Logger) { + // Check pool related fields, use default value if the given value is invalid + if conf.timeOut < 0 { + conf.timeOut = 0 * time.Millisecond + log.Warn("Illegal Timeout value, the default value of 0 second has been applied") + } + if conf.idleTime < 0 { + conf.idleTime = 0 * time.Millisecond + log.Warn("Invalid IdleTime value, the default value of 0 second has been applied") + } + if conf.maxSize < 1 { + conf.maxSize = 10 + log.Warn("Invalid MaxSize value, the default value of 10 has been applied") + } + if conf.minSize < 0 { + conf.minSize = 0 + log.Warn("Invalid MinSize value, the default value of 0 has been applied") + } +} diff --git a/vendor/github.com/vesoft-inc/nebula-go/v3/connection.go b/vendor/github.com/vesoft-inc/nebula-go/v3/connection.go index 28e1c6c34..bf09a6cd3 100644 --- a/vendor/github.com/vesoft-inc/nebula-go/v3/connection.go +++ b/vendor/github.com/vesoft-inc/nebula-go/v3/connection.go @@ -12,6 +12,8 @@ import ( "crypto/tls" "fmt" "math" + "net" + "strconv" "time" "github.com/facebook/fbthrift/thrift/lib/go/thrift" @@ -42,7 +44,7 @@ func newConnection(severAddress HostAddress) *connection { func (cn *connection) open(hostAddress HostAddress, timeout time.Duration, sslConfig *tls.Config) error { ip := hostAddress.Host port := hostAddress.Port - newAdd := fmt.Sprintf("%s:%d", ip, port) + newAdd := net.JoinHostPort(ip, strconv.Itoa(port)) cn.timeout = timeout bufferSize := 128 << 10 frameMaxLength := uint32(math.MaxUint32) @@ -104,17 +106,16 @@ func (cn *connection) authenticate(username, password string) (*graph.AuthRespon } return nil, err } - if resp.ErrorCode != nebula.ErrorCode_SUCCEEDED { - return nil, fmt.Errorf("fail to authenticate, error: %s", resp.ErrorMsg) - } - return resp, err + + return resp, nil } func (cn *connection) execute(sessionID int64, stmt string) (*graph.ExecutionResponse, error) { return cn.executeWithParameter(sessionID, stmt, map[string]*nebula.Value{}) } -func (cn *connection) executeWithParameter(sessionID int64, stmt string, params map[string]*nebula.Value) (*graph.ExecutionResponse, error) { +func (cn *connection) executeWithParameter(sessionID int64, stmt string, + params map[string]*nebula.Value) (*graph.ExecutionResponse, error) { resp, err := cn.graph.ExecuteWithParameter(sessionID, []byte(stmt), params) if err != nil { // reopen the connection if timeout @@ -160,13 +161,7 @@ func (cn *connection) ping() bool { return err == nil } -// Check connection to host address -func (cn *connection) pingWithParameter() bool { - _, err := cn.executeWithParameter(0, "YIELD 1", nil) - return err == nil -} - -// Sign out and release seesin ID +// Sign out and release session ID func (cn *connection) signOut(sessionID int64) error { // Release session ID to graphd return cn.graph.Signout(sessionID) diff --git a/vendor/github.com/vesoft-inc/nebula-go/v3/connection_pool.go b/vendor/github.com/vesoft-inc/nebula-go/v3/connection_pool.go index cf1cb63b0..54cc3fccf 100644 --- a/vendor/github.com/vesoft-inc/nebula-go/v3/connection_pool.go +++ b/vendor/github.com/vesoft-inc/nebula-go/v3/connection_pool.go @@ -70,7 +70,7 @@ func NewSslConnectionPool(addresses []HostAddress, conf PoolConfig, sslConfig *t // initPool initializes the connection pool func (pool *ConnectionPool) initPool() error { - if err := pool.checkAddresses(); err != nil { + if err := checkAddresses(pool.conf.TimeOut, pool.addresses, pool.sslConfig); err != nil { return fmt.Errorf("failed to open connection, error: %s ", err.Error()) } @@ -112,7 +112,7 @@ func (pool *ConnectionPool) GetSession(username, password string) (*Session, err } // Authenticate resp, err := conn.authenticate(username, password) - if err != nil || resp.GetErrorCode() != nebula.ErrorCode_SUCCEEDED { + if err != nil { // if authentication failed, put connection back pool.rwLock.Lock() defer pool.rwLock.Unlock() @@ -121,6 +121,12 @@ func (pool *ConnectionPool) GetSession(username, password string) (*Session, err return nil, err } + // Check auth response + if resp.GetErrorCode() != nebula.ErrorCode_SUCCEEDED { + return nil, fmt.Errorf("failed to authenticate, error code: %d, error msg: %s", + resp.GetErrorCode(), resp.GetErrorMsg()) + } + sessID := resp.GetSessionID() timezoneOffset := resp.GetTimeZoneOffsetSeconds() timezoneName := resp.GetTimeZoneName() @@ -129,6 +135,7 @@ func (pool *ConnectionPool) GetSession(username, password string) (*Session, err sessionID: sessID, connection: conn, connPool: pool, + sessPool: nil, log: pool.log, timezoneInfo: timezoneInfo{timezoneOffset, timezoneName}, } @@ -144,12 +151,17 @@ func (pool *ConnectionPool) getIdleConn() (*connection, error) { if pool.idleConnectionQueue.Len() > 0 { var newConn *connection = nil var newEle *list.Element = nil - for ele := pool.idleConnectionQueue.Front(); ele != nil; ele = ele.Next() { + var tmpNextEle *list.Element = nil + for ele := pool.idleConnectionQueue.Front(); ele != nil; ele = tmpNextEle { // Check if connection is valid if res := ele.Value.(*connection).ping(); res { newConn = ele.Value.(*connection) newEle = ele break + } else { + tmpNextEle = ele.Next() + pool.idleConnectionQueue.Remove(ele) + ele.Value.(*connection).close() } } if newConn == nil { @@ -163,7 +175,7 @@ func (pool *ConnectionPool) getIdleConn() (*connection, error) { // Create a new connection if there is no idle connection and total connection < pool max size newConn, err := pool.createConnection() - // TODO: If no idle avaliable, wait for timeout and reconnect + // TODO: If no idle available, wait for timeout and reconnect return newConn, err } @@ -177,21 +189,17 @@ func (pool *ConnectionPool) release(conn *connection) { pool.idleConnectionQueue.PushBack(conn) } -// Ping checks avaliability of host +// Ping checks availability of host func (pool *ConnectionPool) Ping(host HostAddress, timeout time.Duration) error { - newConn := newConnection(host) - // Open connection to host - if err := newConn.open(newConn.severAddress, timeout, pool.sslConfig); err != nil { - return err - } - newConn.close() - return nil + return pingAddress(host, timeout, pool.sslConfig) } // Close closes all connection func (pool *ConnectionPool) Close() { pool.rwLock.Lock() defer pool.rwLock.Unlock() + + //TODO(Aiee) merge 2 lists and close all connections idleLen := pool.idleConnectionQueue.Len() activeLen := pool.activeConnectionQueue.Len() @@ -255,7 +263,7 @@ func removeFromList(l *list.List, conn *connection) { // Compare total connection number with pool max size and return a connection if capable func (pool *ConnectionPool) createConnection() (*connection, error) { totalConn := pool.idleConnectionQueue.Len() + pool.activeConnectionQueue.Len() - // If no idle avaliable and the number of total connection reaches the max pool size, return error/wait for timeout + // If no idle available and the number of total connection reaches the max pool size, return error/wait for timeout if totalConn >= pool.conf.MaxConnPoolSize { return nil, fmt.Errorf("failed to get connection: No valid connection" + " in the idle queue and connection number has reached the pool capacity") @@ -338,15 +346,28 @@ func (pool *ConnectionPool) timeoutConnectionList() (closing []*connection) { return } -func (pool *ConnectionPool) checkAddresses() error { +// checkAddresses checks addresses availability +// It opens a temporary connection to each address and closes it immediately. +// If no error is returned, the addresses are available. +func checkAddresses(confTimeout time.Duration, addresses []HostAddress, sslConfig *tls.Config) error { var timeout = 3 * time.Second - if pool.conf.TimeOut != 0 && pool.conf.TimeOut < timeout { - timeout = pool.conf.TimeOut + if confTimeout != 0 && confTimeout < timeout { + timeout = confTimeout } - for _, address := range pool.addresses { - if err := pool.Ping(address, timeout); err != nil { + for _, address := range addresses { + if err := pingAddress(address, timeout, sslConfig); err != nil { return err } } return nil } + +func pingAddress(address HostAddress, timeout time.Duration, sslConfig *tls.Config) error { + newConn := newConnection(address) + defer newConn.close() + // Open connection to host + if err := newConn.open(newConn.severAddress, timeout, sslConfig); err != nil { + return err + } + return nil +} diff --git a/vendor/github.com/vesoft-inc/nebula-go/v3/nebula/ttypes.go b/vendor/github.com/vesoft-inc/nebula-go/v3/nebula/ttypes.go index 83259c100..81c630029 100644 --- a/vendor/github.com/vesoft-inc/nebula-go/v3/nebula/ttypes.go +++ b/vendor/github.com/vesoft-inc/nebula-go/v3/nebula/ttypes.go @@ -262,6 +262,9 @@ const ( ErrorCode_E_WRONGCLUSTER ErrorCode = -2010 ErrorCode_E_ZONE_NOT_ENOUGH ErrorCode = -2011 ErrorCode_E_ZONE_IS_EMPTY ErrorCode = -2012 + ErrorCode_E_SCHEMA_NAME_EXISTS ErrorCode = -2013 + ErrorCode_E_RELATED_INDEX_EXISTS ErrorCode = -2014 + ErrorCode_E_RELATED_SPACE_EXISTS ErrorCode = -2015 ErrorCode_E_STORE_FAILURE ErrorCode = -2021 ErrorCode_E_STORE_SEGMENT_ILLEGAL ErrorCode = -2022 ErrorCode_E_BAD_BALANCE_PLAN ErrorCode = -2023 @@ -287,6 +290,11 @@ const ( ErrorCode_E_JOB_NOT_FINISHED ErrorCode = -2048 ErrorCode_E_TASK_REPORT_OUT_DATE ErrorCode = -2049 ErrorCode_E_JOB_NOT_IN_SPACE ErrorCode = -2050 + ErrorCode_E_JOB_NEED_RECOVER ErrorCode = -2051 + ErrorCode_E_JOB_ALREADY_FINISH ErrorCode = -2052 + ErrorCode_E_JOB_SUBMITTED ErrorCode = -2053 + ErrorCode_E_JOB_NOT_STOPPABLE ErrorCode = -2054 + ErrorCode_E_JOB_HAS_NO_TARGET_STORAGE ErrorCode = -2055 ErrorCode_E_INVALID_JOB ErrorCode = -2065 ErrorCode_E_BACKUP_BUILDING_INDEX ErrorCode = -2066 ErrorCode_E_BACKUP_SPACE_NOT_FOUND ErrorCode = -2067 @@ -335,11 +343,12 @@ const ( ErrorCode_E_OUTDATED_EDGE ErrorCode = -3072 ErrorCode_E_WRITE_WRITE_CONFLICT ErrorCode = -3073 ErrorCode_E_CLIENT_SERVER_INCOMPATIBLE ErrorCode = -3061 - ErrorCode_E_WORKER_ID_FAILED ErrorCode = -3062 + ErrorCode_E_ID_FAILED ErrorCode = -3062 ErrorCode_E_RAFT_UNKNOWN_PART ErrorCode = -3500 ErrorCode_E_RAFT_LOG_GAP ErrorCode = -3501 ErrorCode_E_RAFT_LOG_STALE ErrorCode = -3502 ErrorCode_E_RAFT_TERM_OUT_OF_DATE ErrorCode = -3503 + ErrorCode_E_RAFT_UNKNOWN_APPEND_LOG ErrorCode = -3504 ErrorCode_E_RAFT_WAITING_SNAPSHOT ErrorCode = -3511 ErrorCode_E_RAFT_SENDING_SNAPSHOT ErrorCode = -3512 ErrorCode_E_RAFT_INVALID_PEER ErrorCode = -3513 @@ -356,6 +365,7 @@ const ( ErrorCode_E_RAFT_WRITE_BLOCKED ErrorCode = -3528 ErrorCode_E_RAFT_BUFFER_OVERFLOW ErrorCode = -3529 ErrorCode_E_RAFT_ATOMIC_OP_FAILED ErrorCode = -3530 + ErrorCode_E_LEADER_LEASE_FAILED ErrorCode = -3531 ErrorCode_E_UNKNOWN ErrorCode = -8000 ) @@ -410,6 +420,9 @@ var ErrorCodeToName = map[ErrorCode]string { ErrorCode_E_WRONGCLUSTER: "E_WRONGCLUSTER", ErrorCode_E_ZONE_NOT_ENOUGH: "E_ZONE_NOT_ENOUGH", ErrorCode_E_ZONE_IS_EMPTY: "E_ZONE_IS_EMPTY", + ErrorCode_E_SCHEMA_NAME_EXISTS: "E_SCHEMA_NAME_EXISTS", + ErrorCode_E_RELATED_INDEX_EXISTS: "E_RELATED_INDEX_EXISTS", + ErrorCode_E_RELATED_SPACE_EXISTS: "E_RELATED_SPACE_EXISTS", ErrorCode_E_STORE_FAILURE: "E_STORE_FAILURE", ErrorCode_E_STORE_SEGMENT_ILLEGAL: "E_STORE_SEGMENT_ILLEGAL", ErrorCode_E_BAD_BALANCE_PLAN: "E_BAD_BALANCE_PLAN", @@ -435,6 +448,11 @@ var ErrorCodeToName = map[ErrorCode]string { ErrorCode_E_JOB_NOT_FINISHED: "E_JOB_NOT_FINISHED", ErrorCode_E_TASK_REPORT_OUT_DATE: "E_TASK_REPORT_OUT_DATE", ErrorCode_E_JOB_NOT_IN_SPACE: "E_JOB_NOT_IN_SPACE", + ErrorCode_E_JOB_NEED_RECOVER: "E_JOB_NEED_RECOVER", + ErrorCode_E_JOB_ALREADY_FINISH: "E_JOB_ALREADY_FINISH", + ErrorCode_E_JOB_SUBMITTED: "E_JOB_SUBMITTED", + ErrorCode_E_JOB_NOT_STOPPABLE: "E_JOB_NOT_STOPPABLE", + ErrorCode_E_JOB_HAS_NO_TARGET_STORAGE: "E_JOB_HAS_NO_TARGET_STORAGE", ErrorCode_E_INVALID_JOB: "E_INVALID_JOB", ErrorCode_E_BACKUP_BUILDING_INDEX: "E_BACKUP_BUILDING_INDEX", ErrorCode_E_BACKUP_SPACE_NOT_FOUND: "E_BACKUP_SPACE_NOT_FOUND", @@ -483,11 +501,12 @@ var ErrorCodeToName = map[ErrorCode]string { ErrorCode_E_OUTDATED_EDGE: "E_OUTDATED_EDGE", ErrorCode_E_WRITE_WRITE_CONFLICT: "E_WRITE_WRITE_CONFLICT", ErrorCode_E_CLIENT_SERVER_INCOMPATIBLE: "E_CLIENT_SERVER_INCOMPATIBLE", - ErrorCode_E_WORKER_ID_FAILED: "E_WORKER_ID_FAILED", + ErrorCode_E_ID_FAILED: "E_ID_FAILED", ErrorCode_E_RAFT_UNKNOWN_PART: "E_RAFT_UNKNOWN_PART", ErrorCode_E_RAFT_LOG_GAP: "E_RAFT_LOG_GAP", ErrorCode_E_RAFT_LOG_STALE: "E_RAFT_LOG_STALE", ErrorCode_E_RAFT_TERM_OUT_OF_DATE: "E_RAFT_TERM_OUT_OF_DATE", + ErrorCode_E_RAFT_UNKNOWN_APPEND_LOG: "E_RAFT_UNKNOWN_APPEND_LOG", ErrorCode_E_RAFT_WAITING_SNAPSHOT: "E_RAFT_WAITING_SNAPSHOT", ErrorCode_E_RAFT_SENDING_SNAPSHOT: "E_RAFT_SENDING_SNAPSHOT", ErrorCode_E_RAFT_INVALID_PEER: "E_RAFT_INVALID_PEER", @@ -504,6 +523,7 @@ var ErrorCodeToName = map[ErrorCode]string { ErrorCode_E_RAFT_WRITE_BLOCKED: "E_RAFT_WRITE_BLOCKED", ErrorCode_E_RAFT_BUFFER_OVERFLOW: "E_RAFT_BUFFER_OVERFLOW", ErrorCode_E_RAFT_ATOMIC_OP_FAILED: "E_RAFT_ATOMIC_OP_FAILED", + ErrorCode_E_LEADER_LEASE_FAILED: "E_LEADER_LEASE_FAILED", ErrorCode_E_UNKNOWN: "E_UNKNOWN", } @@ -558,6 +578,9 @@ var ErrorCodeToValue = map[string]ErrorCode { "E_WRONGCLUSTER": ErrorCode_E_WRONGCLUSTER, "E_ZONE_NOT_ENOUGH": ErrorCode_E_ZONE_NOT_ENOUGH, "E_ZONE_IS_EMPTY": ErrorCode_E_ZONE_IS_EMPTY, + "E_SCHEMA_NAME_EXISTS": ErrorCode_E_SCHEMA_NAME_EXISTS, + "E_RELATED_INDEX_EXISTS": ErrorCode_E_RELATED_INDEX_EXISTS, + "E_RELATED_SPACE_EXISTS": ErrorCode_E_RELATED_SPACE_EXISTS, "E_STORE_FAILURE": ErrorCode_E_STORE_FAILURE, "E_STORE_SEGMENT_ILLEGAL": ErrorCode_E_STORE_SEGMENT_ILLEGAL, "E_BAD_BALANCE_PLAN": ErrorCode_E_BAD_BALANCE_PLAN, @@ -583,6 +606,11 @@ var ErrorCodeToValue = map[string]ErrorCode { "E_JOB_NOT_FINISHED": ErrorCode_E_JOB_NOT_FINISHED, "E_TASK_REPORT_OUT_DATE": ErrorCode_E_TASK_REPORT_OUT_DATE, "E_JOB_NOT_IN_SPACE": ErrorCode_E_JOB_NOT_IN_SPACE, + "E_JOB_NEED_RECOVER": ErrorCode_E_JOB_NEED_RECOVER, + "E_JOB_ALREADY_FINISH": ErrorCode_E_JOB_ALREADY_FINISH, + "E_JOB_SUBMITTED": ErrorCode_E_JOB_SUBMITTED, + "E_JOB_NOT_STOPPABLE": ErrorCode_E_JOB_NOT_STOPPABLE, + "E_JOB_HAS_NO_TARGET_STORAGE": ErrorCode_E_JOB_HAS_NO_TARGET_STORAGE, "E_INVALID_JOB": ErrorCode_E_INVALID_JOB, "E_BACKUP_BUILDING_INDEX": ErrorCode_E_BACKUP_BUILDING_INDEX, "E_BACKUP_SPACE_NOT_FOUND": ErrorCode_E_BACKUP_SPACE_NOT_FOUND, @@ -631,11 +659,12 @@ var ErrorCodeToValue = map[string]ErrorCode { "E_OUTDATED_EDGE": ErrorCode_E_OUTDATED_EDGE, "E_WRITE_WRITE_CONFLICT": ErrorCode_E_WRITE_WRITE_CONFLICT, "E_CLIENT_SERVER_INCOMPATIBLE": ErrorCode_E_CLIENT_SERVER_INCOMPATIBLE, - "E_WORKER_ID_FAILED": ErrorCode_E_WORKER_ID_FAILED, + "E_ID_FAILED": ErrorCode_E_ID_FAILED, "E_RAFT_UNKNOWN_PART": ErrorCode_E_RAFT_UNKNOWN_PART, "E_RAFT_LOG_GAP": ErrorCode_E_RAFT_LOG_GAP, "E_RAFT_LOG_STALE": ErrorCode_E_RAFT_LOG_STALE, "E_RAFT_TERM_OUT_OF_DATE": ErrorCode_E_RAFT_TERM_OUT_OF_DATE, + "E_RAFT_UNKNOWN_APPEND_LOG": ErrorCode_E_RAFT_UNKNOWN_APPEND_LOG, "E_RAFT_WAITING_SNAPSHOT": ErrorCode_E_RAFT_WAITING_SNAPSHOT, "E_RAFT_SENDING_SNAPSHOT": ErrorCode_E_RAFT_SENDING_SNAPSHOT, "E_RAFT_INVALID_PEER": ErrorCode_E_RAFT_INVALID_PEER, @@ -652,6 +681,7 @@ var ErrorCodeToValue = map[string]ErrorCode { "E_RAFT_WRITE_BLOCKED": ErrorCode_E_RAFT_WRITE_BLOCKED, "E_RAFT_BUFFER_OVERFLOW": ErrorCode_E_RAFT_BUFFER_OVERFLOW, "E_RAFT_ATOMIC_OP_FAILED": ErrorCode_E_RAFT_ATOMIC_OP_FAILED, + "E_LEADER_LEASE_FAILED": ErrorCode_E_LEADER_LEASE_FAILED, "E_UNKNOWN": ErrorCode_E_UNKNOWN, } @@ -706,6 +736,9 @@ var ErrorCodeNames = []string { "E_WRONGCLUSTER", "E_ZONE_NOT_ENOUGH", "E_ZONE_IS_EMPTY", + "E_SCHEMA_NAME_EXISTS", + "E_RELATED_INDEX_EXISTS", + "E_RELATED_SPACE_EXISTS", "E_STORE_FAILURE", "E_STORE_SEGMENT_ILLEGAL", "E_BAD_BALANCE_PLAN", @@ -731,6 +764,11 @@ var ErrorCodeNames = []string { "E_JOB_NOT_FINISHED", "E_TASK_REPORT_OUT_DATE", "E_JOB_NOT_IN_SPACE", + "E_JOB_NEED_RECOVER", + "E_JOB_ALREADY_FINISH", + "E_JOB_SUBMITTED", + "E_JOB_NOT_STOPPABLE", + "E_JOB_HAS_NO_TARGET_STORAGE", "E_INVALID_JOB", "E_BACKUP_BUILDING_INDEX", "E_BACKUP_SPACE_NOT_FOUND", @@ -779,11 +817,12 @@ var ErrorCodeNames = []string { "E_OUTDATED_EDGE", "E_WRITE_WRITE_CONFLICT", "E_CLIENT_SERVER_INCOMPATIBLE", - "E_WORKER_ID_FAILED", + "E_ID_FAILED", "E_RAFT_UNKNOWN_PART", "E_RAFT_LOG_GAP", "E_RAFT_LOG_STALE", "E_RAFT_TERM_OUT_OF_DATE", + "E_RAFT_UNKNOWN_APPEND_LOG", "E_RAFT_WAITING_SNAPSHOT", "E_RAFT_SENDING_SNAPSHOT", "E_RAFT_INVALID_PEER", @@ -800,6 +839,7 @@ var ErrorCodeNames = []string { "E_RAFT_WRITE_BLOCKED", "E_RAFT_BUFFER_OVERFLOW", "E_RAFT_ATOMIC_OP_FAILED", + "E_LEADER_LEASE_FAILED", "E_UNKNOWN", } @@ -854,6 +894,9 @@ var ErrorCodeValues = []ErrorCode { ErrorCode_E_WRONGCLUSTER, ErrorCode_E_ZONE_NOT_ENOUGH, ErrorCode_E_ZONE_IS_EMPTY, + ErrorCode_E_SCHEMA_NAME_EXISTS, + ErrorCode_E_RELATED_INDEX_EXISTS, + ErrorCode_E_RELATED_SPACE_EXISTS, ErrorCode_E_STORE_FAILURE, ErrorCode_E_STORE_SEGMENT_ILLEGAL, ErrorCode_E_BAD_BALANCE_PLAN, @@ -879,6 +922,11 @@ var ErrorCodeValues = []ErrorCode { ErrorCode_E_JOB_NOT_FINISHED, ErrorCode_E_TASK_REPORT_OUT_DATE, ErrorCode_E_JOB_NOT_IN_SPACE, + ErrorCode_E_JOB_NEED_RECOVER, + ErrorCode_E_JOB_ALREADY_FINISH, + ErrorCode_E_JOB_SUBMITTED, + ErrorCode_E_JOB_NOT_STOPPABLE, + ErrorCode_E_JOB_HAS_NO_TARGET_STORAGE, ErrorCode_E_INVALID_JOB, ErrorCode_E_BACKUP_BUILDING_INDEX, ErrorCode_E_BACKUP_SPACE_NOT_FOUND, @@ -927,11 +975,12 @@ var ErrorCodeValues = []ErrorCode { ErrorCode_E_OUTDATED_EDGE, ErrorCode_E_WRITE_WRITE_CONFLICT, ErrorCode_E_CLIENT_SERVER_INCOMPATIBLE, - ErrorCode_E_WORKER_ID_FAILED, + ErrorCode_E_ID_FAILED, ErrorCode_E_RAFT_UNKNOWN_PART, ErrorCode_E_RAFT_LOG_GAP, ErrorCode_E_RAFT_LOG_STALE, ErrorCode_E_RAFT_TERM_OUT_OF_DATE, + ErrorCode_E_RAFT_UNKNOWN_APPEND_LOG, ErrorCode_E_RAFT_WAITING_SNAPSHOT, ErrorCode_E_RAFT_SENDING_SNAPSHOT, ErrorCode_E_RAFT_INVALID_PEER, @@ -948,6 +997,7 @@ var ErrorCodeValues = []ErrorCode { ErrorCode_E_RAFT_WRITE_BLOCKED, ErrorCode_E_RAFT_BUFFER_OVERFLOW, ErrorCode_E_RAFT_ATOMIC_OP_FAILED, + ErrorCode_E_LEADER_LEASE_FAILED, ErrorCode_E_UNKNOWN, } @@ -6401,9 +6451,13 @@ func (p *Duration) String() string { // Attributes: // - LogID // - TermID +// - CommitLogID +// - CheckpointPath type LogInfo struct { LogID LogID `thrift:"log_id,1" db:"log_id" json:"log_id"` TermID TermID `thrift:"term_id,2" db:"term_id" json:"term_id"` + CommitLogID LogID `thrift:"commit_log_id,3" db:"commit_log_id" json:"commit_log_id"` + CheckpointPath []byte `thrift:"checkpoint_path,4" db:"checkpoint_path" json:"checkpoint_path"` } func NewLogInfo() *LogInfo { @@ -6418,6 +6472,14 @@ func (p *LogInfo) GetLogID() LogID { func (p *LogInfo) GetTermID() TermID { return p.TermID } + +func (p *LogInfo) GetCommitLogID() LogID { + return p.CommitLogID +} + +func (p *LogInfo) GetCheckpointPath() []byte { + return p.CheckpointPath +} type LogInfoBuilder struct { obj *LogInfo } @@ -6432,6 +6494,8 @@ func (p LogInfoBuilder) Emit() *LogInfo{ return &LogInfo{ LogID: p.obj.LogID, TermID: p.obj.TermID, + CommitLogID: p.obj.CommitLogID, + CheckpointPath: p.obj.CheckpointPath, } } @@ -6445,6 +6509,16 @@ func (l *LogInfoBuilder) TermID(termID TermID) *LogInfoBuilder { return l } +func (l *LogInfoBuilder) CommitLogID(commitLogID LogID) *LogInfoBuilder { + l.obj.CommitLogID = commitLogID + return l +} + +func (l *LogInfoBuilder) CheckpointPath(checkpointPath []byte) *LogInfoBuilder { + l.obj.CheckpointPath = checkpointPath + return l +} + func (l *LogInfo) SetLogID(logID LogID) *LogInfo { l.LogID = logID return l @@ -6455,6 +6529,16 @@ func (l *LogInfo) SetTermID(termID TermID) *LogInfo { return l } +func (l *LogInfo) SetCommitLogID(commitLogID LogID) *LogInfo { + l.CommitLogID = commitLogID + return l +} + +func (l *LogInfo) SetCheckpointPath(checkpointPath []byte) *LogInfo { + l.CheckpointPath = checkpointPath + return l +} + func (p *LogInfo) Read(iprot thrift.Protocol) error { if _, err := iprot.ReadStructBegin(); err != nil { return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) @@ -6476,6 +6560,14 @@ func (p *LogInfo) Read(iprot thrift.Protocol) error { if err := p.ReadField2(iprot); err != nil { return err } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } default: if err := iprot.Skip(fieldTypeId); err != nil { return err @@ -6511,11 +6603,32 @@ func (p *LogInfo) ReadField2(iprot thrift.Protocol) error { return nil } +func (p *LogInfo) ReadField3(iprot thrift.Protocol) error { + if v, err := iprot.ReadI64(); err != nil { + return thrift.PrependError("error reading field 3: ", err) + } else { + temp := LogID(v) + p.CommitLogID = temp + } + return nil +} + +func (p *LogInfo) ReadField4(iprot thrift.Protocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 4: ", err) + } else { + p.CheckpointPath = v + } + return nil +} + func (p *LogInfo) Write(oprot thrift.Protocol) error { if err := oprot.WriteStructBegin("LogInfo"); err != nil { return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) } if err := p.writeField1(oprot); err != nil { return err } if err := p.writeField2(oprot); err != nil { return err } + if err := p.writeField3(oprot); err != nil { return err } + if err := p.writeField4(oprot); err != nil { return err } if err := oprot.WriteFieldStop(); err != nil { return thrift.PrependError("write field stop error: ", err) } if err := oprot.WriteStructEnd(); err != nil { @@ -6543,6 +6656,26 @@ func (p *LogInfo) writeField2(oprot thrift.Protocol) (err error) { return err } +func (p *LogInfo) writeField3(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("commit_log_id", thrift.I64, 3); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:commit_log_id: ", p), err) } + if err := oprot.WriteI64(int64(p.CommitLogID)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.commit_log_id (3) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 3:commit_log_id: ", p), err) } + return err +} + +func (p *LogInfo) writeField4(oprot thrift.Protocol) (err error) { + if err := oprot.WriteFieldBegin("checkpoint_path", thrift.STRING, 4); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:checkpoint_path: ", p), err) } + if err := oprot.WriteBinary(p.CheckpointPath); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.checkpoint_path (4) field write error: ", p), err) } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 4:checkpoint_path: ", p), err) } + return err +} + func (p *LogInfo) String() string { if p == nil { return "" @@ -6550,7 +6683,9 @@ func (p *LogInfo) String() string { logIDVal := fmt.Sprintf("%v", p.LogID) termIDVal := fmt.Sprintf("%v", p.TermID) - return fmt.Sprintf("LogInfo({LogID:%s TermID:%s})", logIDVal, termIDVal) + commitLogIDVal := fmt.Sprintf("%v", p.CommitLogID) + checkpointPathVal := fmt.Sprintf("%v", p.CheckpointPath) + return fmt.Sprintf("LogInfo({LogID:%s TermID:%s CommitLogID:%s CheckpointPath:%s})", logIDVal, termIDVal, commitLogIDVal, checkpointPathVal) } // Attributes: @@ -6730,11 +6865,11 @@ func (p *DirInfo) String() string { // Attributes: // - SpaceID // - Parts -// - Path +// - DataPath type CheckpointInfo struct { SpaceID GraphSpaceID `thrift:"space_id,1" db:"space_id" json:"space_id"` Parts map[PartitionID]*LogInfo `thrift:"parts,2" db:"parts" json:"parts"` - Path []byte `thrift:"path,3" db:"path" json:"path"` + DataPath []byte `thrift:"data_path,3" db:"data_path" json:"data_path"` } func NewCheckpointInfo() *CheckpointInfo { @@ -6750,8 +6885,8 @@ func (p *CheckpointInfo) GetParts() map[PartitionID]*LogInfo { return p.Parts } -func (p *CheckpointInfo) GetPath() []byte { - return p.Path +func (p *CheckpointInfo) GetDataPath() []byte { + return p.DataPath } type CheckpointInfoBuilder struct { obj *CheckpointInfo @@ -6767,7 +6902,7 @@ func (p CheckpointInfoBuilder) Emit() *CheckpointInfo{ return &CheckpointInfo{ SpaceID: p.obj.SpaceID, Parts: p.obj.Parts, - Path: p.obj.Path, + DataPath: p.obj.DataPath, } } @@ -6781,8 +6916,8 @@ func (c *CheckpointInfoBuilder) Parts(parts map[PartitionID]*LogInfo) *Checkpoin return c } -func (c *CheckpointInfoBuilder) Path(path []byte) *CheckpointInfoBuilder { - c.obj.Path = path +func (c *CheckpointInfoBuilder) DataPath(dataPath []byte) *CheckpointInfoBuilder { + c.obj.DataPath = dataPath return c } @@ -6796,8 +6931,8 @@ func (c *CheckpointInfo) SetParts(parts map[PartitionID]*LogInfo) *CheckpointInf return c } -func (c *CheckpointInfo) SetPath(path []byte) *CheckpointInfo { - c.Path = path +func (c *CheckpointInfo) SetDataPath(dataPath []byte) *CheckpointInfo { + c.DataPath = dataPath return c } @@ -6882,7 +7017,7 @@ func (p *CheckpointInfo) ReadField3(iprot thrift.Protocol) error { if v, err := iprot.ReadBinary(); err != nil { return thrift.PrependError("error reading field 3: ", err) } else { - p.Path = v + p.DataPath = v } return nil } @@ -6932,12 +7067,12 @@ func (p *CheckpointInfo) writeField2(oprot thrift.Protocol) (err error) { } func (p *CheckpointInfo) writeField3(oprot thrift.Protocol) (err error) { - if err := oprot.WriteFieldBegin("path", thrift.STRING, 3); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:path: ", p), err) } - if err := oprot.WriteBinary(p.Path); err != nil { - return thrift.PrependError(fmt.Sprintf("%T.path (3) field write error: ", p), err) } + if err := oprot.WriteFieldBegin("data_path", thrift.STRING, 3); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:data_path: ", p), err) } + if err := oprot.WriteBinary(p.DataPath); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.data_path (3) field write error: ", p), err) } if err := oprot.WriteFieldEnd(); err != nil { - return thrift.PrependError(fmt.Sprintf("%T write field end error 3:path: ", p), err) } + return thrift.PrependError(fmt.Sprintf("%T write field end error 3:data_path: ", p), err) } return err } @@ -6948,8 +7083,8 @@ func (p *CheckpointInfo) String() string { spaceIDVal := fmt.Sprintf("%v", p.SpaceID) partsVal := fmt.Sprintf("%v", p.Parts) - pathVal := fmt.Sprintf("%v", p.Path) - return fmt.Sprintf("CheckpointInfo({SpaceID:%s Parts:%s Path:%s})", spaceIDVal, partsVal, pathVal) + dataPathVal := fmt.Sprintf("%v", p.DataPath) + return fmt.Sprintf("CheckpointInfo({SpaceID:%s Parts:%s DataPath:%s})", spaceIDVal, partsVal, dataPathVal) } // Attributes: diff --git a/vendor/github.com/vesoft-inc/nebula-go/v3/result_set.go b/vendor/github.com/vesoft-inc/nebula-go/v3/result_set.go index 34ea8e901..a3eae91b0 100644 --- a/vendor/github.com/vesoft-inc/nebula-go/v3/result_set.go +++ b/vendor/github.com/vesoft-inc/nebula-go/v3/result_set.go @@ -12,6 +12,7 @@ import ( "bytes" "encoding/json" "fmt" + "regexp" "sort" "strings" "time" @@ -1072,6 +1073,10 @@ func graphvizString(s string) string { s = strings.Replace(s, "\"", "\\\"", -1) s = strings.Replace(s, "[", "\\[", -1) s = strings.Replace(s, "]", "\\]", -1) + s = strings.Replace(s, "(", "\\(", -1) + s = strings.Replace(s, ")", "\\)", -1) + s = strings.Replace(s, "<", "\\<", -1) + s = strings.Replace(s, ">", "\\>", -1) return s } @@ -1266,24 +1271,36 @@ func (res ResultSet) MakePlanByRow() [][]interface{} { } if planNodeDesc.IsSetProfiles() { - var strArr []string + var profileArr []string for i, profile := range planNodeDesc.GetProfiles() { - otherStats := profile.GetOtherStats() - if otherStats != nil { - strArr = append(strArr, "{") - } - s := fmt.Sprintf("ver: %d, rows: %d, execTime: %dus, totalTime: %dus", - i, profile.GetRows(), profile.GetExecDurationInUs(), profile.GetTotalDurationInUs()) - strArr = append(strArr, s) - - for k, v := range otherStats { - strArr = append(strArr, fmt.Sprintf("%s: %s", k, v)) - } - if otherStats != nil { - strArr = append(strArr, "}") + var statArr []string + statArr = append(statArr, fmt.Sprintf("\"version\":%d", i)) + statArr = append(statArr, fmt.Sprintf("\"rows\":%d", profile.GetRows())) + statArr = append(statArr, fmt.Sprintf("\"execTime\":\"%d(us)\"", profile.GetExecDurationInUs())) + statArr = append(statArr, fmt.Sprintf("\"totalTime\":\"%d(us)\"", profile.GetTotalDurationInUs())) + for k, v := range profile.GetOtherStats() { + s := string(v) + if matched, err := regexp.Match(`^[^{(\[]\w+`, v); err == nil && matched { + if !strings.HasPrefix(s, "\"") { + s = fmt.Sprintf("\"%s", s) + } + if !strings.HasSuffix(s, "\"") { + s = fmt.Sprintf("%s\"", s) + } + } + statArr = append(statArr, fmt.Sprintf("\"%s\": %s", k, s)) } + sort.Strings(statArr) + statStr := fmt.Sprintf("{%s}", strings.Join(statArr, ",\n")) + profileArr = append(profileArr, statStr) + } + allProfiles := strings.Join(profileArr, ",\n") + if len(profileArr) > 1 { + allProfiles = fmt.Sprintf("[%s]", allProfiles) } - row = append(row, strings.Join(strArr, "\n")) + var buffer bytes.Buffer + json.Indent(&buffer, []byte(allProfiles), "", " ") + row = append(row, string(buffer.Bytes())) } else { row = append(row, "") } diff --git a/vendor/github.com/vesoft-inc/nebula-go/v3/session.go b/vendor/github.com/vesoft-inc/nebula-go/v3/session.go index 29c491797..2708aa941 100644 --- a/vendor/github.com/vesoft-inc/nebula-go/v3/session.go +++ b/vendor/github.com/vesoft-inc/nebula-go/v3/session.go @@ -11,6 +11,7 @@ package nebula_go import ( "fmt" "sync" + "time" "github.com/facebook/fbthrift/thrift/lib/go/thrift" "github.com/vesoft-inc/nebula-go/v3/nebula" @@ -25,14 +26,16 @@ type timezoneInfo struct { type Session struct { sessionID int64 connection *connection - connPool *ConnectionPool + connPool *ConnectionPool // the connection pool which the session belongs to. could be nil if the Session is store in the SessionPool + sessPool *SessionPool // the session pool which the session belongs to. could be nil if the Session is store in the ConnectionPool log Logger + returnedAt time.Time // the timestamp that the session was created or returned. mu sync.Mutex timezoneInfo } func (session *Session) reconnectWithExecuteErr(err error) error { - // Reconnect only if the tranport is closed + // Reconnect only if the transport is closed err2, ok := err.(thrift.TransportException) if !ok { return err @@ -56,7 +59,7 @@ func (session *Session) executeWithReconnect(f func() (interface{}, error)) (int if err2 := session.reconnectWithExecuteErr(err); err2 != nil { return nil, err2 } - // Execute with the new connetion + // Execute with the new connection return f() } @@ -68,14 +71,11 @@ func (session *Session) ExecuteWithParameter(stmt string, params map[string]inte if session.connection == nil { return nil, fmt.Errorf("failed to execute: Session has been released") } - paramsMap := make(map[string]*nebula.Value) - for k, v := range params { - nv, er := value2Nvalue(v) - if er != nil { - return nil, er - } - paramsMap[k] = nv + paramsMap, err := parseParams(params) + if err != nil { + return nil, err } + execFunc := func() (interface{}, error) { resp, err := session.connection.executeWithParameter(session.sessionID, stmt, paramsMap) if err != nil { @@ -165,62 +165,7 @@ func (session *Session) 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 -// 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": "" -// } -// ] -// } +// The result is a JSON string in the same format as ExecuteJson() func (session *Session) ExecuteJsonWithParameter(stmt string, params map[string]interface{}) ([]byte, error) { session.mu.Lock() defer session.mu.Unlock() @@ -263,7 +208,7 @@ func (session *Session) reConnect() error { return nil } -// Release logs out and releases connetion hold by session. +// Release logs out and releases connection hold by session. // The connection will be added into the activeConnectionQueue of the connection pool // so that it could be reused. func (session *Session) Release() { @@ -279,8 +224,11 @@ func (session *Session) Release() { if err := session.connection.signOut(session.sessionID); err != nil { session.log.Warn(fmt.Sprintf("Sign out failed, %s", err.Error())) } - // Release connection to pool - session.connPool.release(session.connection) + + // if the session is created from the connection pool, return the connection to the pool + if session.connPool != nil { + session.connPool.release(session.connection) + } session.connection = nil } @@ -288,6 +236,24 @@ func (session *Session) GetSessionID() int64 { return session.sessionID } +// Ping checks if the session is valid +func (session *Session) Ping() error { + if session.connection == nil { + return fmt.Errorf("failed to ping: Session has been released") + } + // send ping request + resp, err := session.Execute(`RETURN "NEBULA GO PING"`) + // check connection level error + if err != nil { + return fmt.Errorf("session ping failed, %s" + err.Error()) + } + // check session level error + if !resp.IsSucceed() { + return fmt.Errorf("session ping failed, %s" + resp.GetErrorMsg()) + } + return nil +} + func IsError(resp *graph.ExecutionResponse) bool { return resp.GetErrorCode() != nebula.ErrorCode_SUCCEEDED } @@ -310,13 +276,9 @@ func slice2Nlist(list []interface{}) (*nebula.NList, error) { // construct map to nebula.NMap func map2Nmap(m map[string]interface{}) (*nebula.NMap, error) { var ret nebula.NMap - kvs := map[string]*nebula.Value{} - for k, v := range m { - nv, err := value2Nvalue(v) - if err != nil { - return nil, err - } - kvs[k] = nv + kvs, err := parseParams(m) + if err != nil { + return nil, err } ret.Kvs = kvs return &ret, nil @@ -375,7 +337,7 @@ func value2Nvalue(any interface{}) (value *nebula.Value, err error) { } else if v, ok := any.(nebula.Geography); ok { value.SetGgVal(&v) } else { - // unsupport other Value type, use this function carefully + // unsupported 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 diff --git a/vendor/github.com/vesoft-inc/nebula-go/v3/session_pool.go b/vendor/github.com/vesoft-inc/nebula-go/v3/session_pool.go new file mode 100644 index 000000000..37fa1c445 --- /dev/null +++ b/vendor/github.com/vesoft-inc/nebula-go/v3/session_pool.go @@ -0,0 +1,514 @@ +/* + * + * Copyright (c) 2022 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + * + */ + +package nebula_go + +import ( + "container/list" + "crypto/tls" + "fmt" + "sync" + "time" + + "github.com/vesoft-inc/nebula-go/v3/nebula" +) + +// SessionPool is a pool that manages sessions internally. +// +// Usage: +// Construct +// sessionPool = newSessionPool(conf) +// +// Initialize +// sessionPool.init() +// +// Execute query +// result = sessionPool.execute("query") +// +// Release: +// sessionPool.close() +// +// Notice that all queries will be executed in the default space specified in the pool config. +type SessionPool struct { + idleSessions list.List + activeSessions list.List + conf SessionPoolConf + tz timezoneInfo + log Logger + closed bool + cleanerChan chan struct{} //notify when pool is close + rwLock sync.RWMutex + sslConfig *tls.Config +} + +// NewSessionPool creates a new session pool with the given configs. +// There must be an existing SPACE in the DB. +func NewSessionPool(conf SessionPoolConf, log Logger) (*SessionPool, error) { + // check the config + conf.checkBasicFields(log) + + newSessionPool := &SessionPool{ + conf: conf, + log: log, + } + + // init the pool + if err := newSessionPool.init(); err != nil { + return nil, fmt.Errorf("failed to create a new session pool, %s", err.Error()) + } + newSessionPool.startCleaner() + return newSessionPool, nil +} + +// init initializes the session pool. +func (pool *SessionPool) init() error { + pool.rwLock.Lock() + defer pool.rwLock.Unlock() + // check the hosts status + if err := checkAddresses(pool.conf.timeOut, pool.conf.serviceAddrs, pool.sslConfig); err != nil { + return fmt.Errorf("failed to initialize the session pool, %s", err.Error()) + } + + // create sessions to fulfill the min pool size + for i := 0; i < pool.conf.minSize; i++ { + session, err := pool.newSession() + if err != nil { + return fmt.Errorf("failed to initialize the session pool, %s", err.Error()) + } + + session.returnedAt = time.Now() + pool.addSessionToList(&pool.idleSessions, session) + } + + return nil +} + +// Execute returns the result of the given query as a ResultSet +// Notice there are some limitations: +// 1. The query should not be a plain space switch statement, e.g. "USE test_space", +// but queries like "use space xxx; match (v) return v" are accepted. +// 2. If the query contains statements like "USE ", the space will be set to the +// one in the pool config after the execution of the query. +// 3. The query should not change the user password nor drop a user. +func (pool *SessionPool) Execute(stmt string) (*ResultSet, error) { + return pool.ExecuteWithParameter(stmt, map[string]interface{}{}) +} + +// ExecuteWithParameter returns the result of the given query as a ResultSet +func (pool *SessionPool) ExecuteWithParameter(stmt string, params map[string]interface{}) (*ResultSet, error) { + // Check if the pool is closed + if pool.closed { + return nil, fmt.Errorf("failed to execute: Session pool has been closed") + } + + // Get a session from the pool + session, err := pool.getIdleSession() + if err != nil { + return nil, err + } + + // Parse params + paramsMap, err := parseParams(params) + if err != nil { + return nil, err + } + + // Execute the query + resp, err := session.connection.executeWithParameter(session.sessionID, stmt, paramsMap) + if err != nil { + return nil, err + } + + resSet, err := genResultSet(resp, session.timezoneInfo) + if err != nil { + return nil, err + } + + // if the space was changed after the execution of the given query, + // change it back to the default space specified in the pool config + if resSet.GetSpaceName() != "" && resSet.GetSpaceName() != pool.conf.spaceName { + err := pool.setSessionSpaceToDefault(session) + if err != nil { + return nil, err + } + } + + // Return the session to the idle list + pool.returnSession(session) + + return resSet, err +} + +// 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": "" +// } +// ] +// } +func (pool *SessionPool) ExecuteJson(stmt string) ([]byte, error) { + return pool.ExecuteJsonWithParameter(stmt, map[string]interface{}{}) +} + +// 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 +func (pool *SessionPool) ExecuteJsonWithParameter(stmt string, params map[string]interface{}) ([]byte, error) { + return nil, fmt.Errorf("not implemented") + + // Get a session from the pool + session, err := pool.getIdleSession() + if err != nil { + return nil, err + } + // check the session is valid + if session.connection == nil { + return nil, fmt.Errorf("failed to execute: Session has been released") + } + // parse params + paramsMap, err := parseParams(params) + if err != nil { + return nil, err + } + + pool.rwLock.Lock() + defer pool.rwLock.Unlock() + resp, err := session.connection.ExecuteJsonWithParameter(session.sessionID, stmt, paramsMap) + if err != nil { + return nil, err + } + + //TODO(Aiee) check the space name + return resp, nil +} + +// Close logs out all sessions and closes bonded connection. +func (pool *SessionPool) Close() { + pool.rwLock.Lock() + defer pool.rwLock.Unlock() + + //TODO(Aiee) append 2 lists + idleLen := pool.idleSessions.Len() + activeLen := pool.activeSessions.Len() + + // iterate all sessions + for i := 0; i < idleLen; i++ { + session := pool.idleSessions.Front().Value.(*Session) + if session.connection == nil { + session.log.Warn("Session has been released") + } else if err := session.connection.signOut(session.sessionID); err != nil { + session.log.Warn(fmt.Sprintf("Sign out failed, %s", err.Error())) + } + // close connection + session.connection.close() + pool.idleSessions.Remove(pool.idleSessions.Front()) + } + for i := 0; i < activeLen; i++ { + session := pool.activeSessions.Front().Value.(*Session) + if session.connection == nil { + session.log.Warn("Session has been released") + } else if err := session.connection.signOut(session.sessionID); err != nil { + session.log.Warn(fmt.Sprintf("Sign out failed, %s", err.Error())) + } + // close connection + session.connection.close() + pool.activeSessions.Remove(pool.activeSessions.Front()) + } + + pool.closed = true + if pool.cleanerChan != nil { + close(pool.cleanerChan) + } +} + +// GetTotalSessionCount returns the total number of sessions in the pool +func (pool *SessionPool) GetTotalSessionCount() int { + pool.rwLock.RLock() + defer pool.rwLock.RUnlock() + return pool.activeSessions.Len() + pool.idleSessions.Len() +} + +// newSession creates a new session and returns it. +// `use ` will be executed so that the new session will be in the default space. +func (pool *SessionPool) newSession() (*Session, error) { + graphAddr := pool.getNextAddr() + cn := connection{ + severAddress: graphAddr, + timeout: 0 * time.Millisecond, + returnedAt: time.Now(), + sslConfig: nil, + graph: nil, + } + + // open a new connection + if err := cn.open(cn.severAddress, pool.conf.timeOut, nil); err != nil { + return nil, fmt.Errorf("failed to create a net.Conn-backed Transport,: %s", err.Error()) + } + + // authenticate with username and password to get a new session + authResp, err := cn.authenticate(pool.conf.username, pool.conf.password) + if err != nil { + return nil, fmt.Errorf("failed to create a new session: %s", err.Error()) + } + + // If the authentication failed, close the session pool because the pool must have a valid user to work + if authResp.GetErrorCode() != 0 { + if authResp.GetErrorCode() == nebula.ErrorCode_E_BAD_USERNAME_PASSWORD || + authResp.GetErrorCode() == nebula.ErrorCode_E_USER_NOT_FOUND { + pool.Close() + return nil, fmt.Errorf( + "failed to authenticate the user, error code: %d, error message: %s, the pool has been closed", + authResp.ErrorCode, authResp.ErrorMsg) + } + return nil, fmt.Errorf("failed to create a new session: %s", authResp.GetErrorMsg()) + } + + sessID := authResp.GetSessionID() + timezoneOffset := authResp.GetTimeZoneOffsetSeconds() + timezoneName := authResp.GetTimeZoneName() + // Create new session + newSession := Session{ + sessionID: sessID, + connection: &cn, + connPool: nil, + sessPool: pool, + log: pool.log, + timezoneInfo: timezoneInfo{timezoneOffset, timezoneName}, + } + + // Switch to the default space + stmt := fmt.Sprintf("USE %s", pool.conf.spaceName) + useSpaceResp, err := newSession.connection.execute(newSession.sessionID, stmt) + if err != nil { + return nil, err + } + + if useSpaceResp.GetErrorCode() != nebula.ErrorCode_SUCCEEDED { + newSession.connection.close() + return nil, fmt.Errorf("failed to use space %s: %s", + pool.conf.spaceName, useSpaceResp.GetErrorMsg()) + } + return &newSession, nil +} + +// getNextAddr returns the next address in the address list using simple round robin approach. +func (pool *SessionPool) getNextAddr() HostAddress { + if pool.conf.hostIndex == len(pool.conf.serviceAddrs) { + pool.conf.hostIndex = 0 + } + host := pool.conf.serviceAddrs[pool.conf.hostIndex] + pool.conf.hostIndex++ + return host +} + +// getSession returns an available session. +// This method should move an available session to the active list and should be MT-safe. +func (pool *SessionPool) getIdleSession() (*Session, error) { + pool.rwLock.Lock() + defer pool.rwLock.Unlock() + // Get a session from the idle queue if possible + if pool.idleSessions.Len() > 0 { + session := pool.idleSessions.Front().Value.(*Session) + pool.removeSessionFromList(&pool.idleSessions, session) + pool.addSessionToList(&pool.activeSessions, session) + return session, nil + } else if pool.activeSessions.Len() < pool.conf.maxSize { + // Create a new session if the total number of sessions is less than the max size + session, err := pool.newSession() + if err != nil { + return nil, err + } + pool.addSessionToList(&pool.activeSessions, session) + return session, nil + } + // There is no available session in the pool and the total session count has reached the limit + return nil, fmt.Errorf("failed to get session: no session available in the" + + " session pool and the total session count has reached the limit") +} + +// startCleaner starts sessionCleaner if idleTime > 0. +func (pool *SessionPool) startCleaner() { + if pool.conf.idleTime > 0 && pool.cleanerChan == nil { + pool.cleanerChan = make(chan struct{}, 1) + go pool.sessionCleaner() + } +} + +func (pool *SessionPool) sessionCleaner() { + const minInterval = time.Minute + + d := pool.conf.idleTime + + if d < minInterval { + d = minInterval + } + t := time.NewTimer(d) + + for { + select { + case <-t.C: + case <-pool.cleanerChan: // pool was closed. + } + + pool.rwLock.Lock() + + if pool.closed { + pool.cleanerChan = nil + pool.rwLock.Unlock() + return + } + + closing := pool.timeoutSessionList() + + //release expired session from the pool + for _, session := range closing { + if session.connection == nil { + session.log.Warn("Session has been released") + return + } + if err := session.connection.signOut(session.sessionID); err != nil { + session.log.Warn(fmt.Sprintf("Sign out failed, %s", err.Error())) + } + // close connection + session.connection.close() + } + pool.rwLock.Unlock() + + t.Reset(d) + } +} + +// timeoutSessionList returns a list of sessions that have been idle for longer than the idle time. +func (pool *SessionPool) timeoutSessionList() (closing []*Session) { + if pool.conf.idleTime > 0 { + expiredSince := time.Now().Add(-pool.conf.idleTime) + var newEle *list.Element = nil + + maxCleanSize := pool.idleSessions.Len() + pool.activeSessions.Len() - pool.conf.minSize + + for ele := pool.idleSessions.Front(); ele != nil; { + if maxCleanSize == 0 { + return + } + + newEle = ele.Next() + // Check Session is expired + if !ele.Value.(*Session).returnedAt.Before(expiredSince) { + return + } + closing = append(closing, ele.Value.(*Session)) + pool.idleSessions.Remove(ele) + ele = newEle + maxCleanSize-- + } + } + return +} + +// parseParams converts the params map to a map of nebula.Value +func parseParams(params map[string]interface{}) (map[string]*nebula.Value, error) { + paramsMap := make(map[string]*nebula.Value) + for k, v := range params { + nv, err := value2Nvalue(v) + if err != nil { + return nil, fmt.Errorf("failed to parse params: %s", err.Error()) + } + paramsMap[k] = nv + } + return paramsMap, nil +} + +// removeSessionFromIdleList Removes a session from list +func (pool *SessionPool) removeSessionFromList(l *list.List, session *Session) { + for ele := l.Front(); ele != nil; ele = ele.Next() { + if ele.Value.(*Session) == session { + l.Remove(ele) + } + } +} + +func (pool *SessionPool) addSessionToList(l *list.List, session *Session) { + l.PushBack(session) +} + +// returnSession returns a session from active list to the idle list. +func (pool *SessionPool) returnSession(session *Session) { + pool.rwLock.Lock() + defer pool.rwLock.Unlock() + pool.removeSessionFromList(&pool.activeSessions, session) + pool.addSessionToList(&pool.idleSessions, session) + session.returnedAt = time.Now() +} + +func (pool *SessionPool) setSessionSpaceToDefault(session *Session) error { + stmt := fmt.Sprintf("USE %s", pool.conf.spaceName) + resp, err := session.connection.execute(session.sessionID, stmt) + if err != nil { + return err + } + // if failed to change back to the default space, send a warning log + // and remove the session from the pool because it is malformed. + if resp.ErrorCode != nebula.ErrorCode_SUCCEEDED { + pool.log.Warn(fmt.Sprintf("failed to reset the space of the session: errorCode: %s, errorMsg: %s, session removed", + resp.ErrorCode, resp.ErrorMsg)) + pool.removeSessionFromList(&pool.activeSessions, session) + } + return nil +} diff --git a/vendor/github.com/zhihu/norm/LICENSE b/vendor/github.com/zhihu/norm/LICENSE new file mode 100644 index 000000000..08cbfdcf6 --- /dev/null +++ b/vendor/github.com/zhihu/norm/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Zhihu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/zhihu/norm/constants/constant.go b/vendor/github.com/zhihu/norm/constants/constant.go new file mode 100644 index 000000000..e9b0ee74e --- /dev/null +++ b/vendor/github.com/zhihu/norm/constants/constant.go @@ -0,0 +1,17 @@ +package constants + +type Direction = string +type Policy int + +const ( + // 反向 + DirectionReversely = "REVERSELY" + // 双向 + DirectionBidirect = "BIDIRECT" + StructTagName = "norm" +) + +const ( + PolicyNothing = iota + PolicyHash +) diff --git a/vendor/github.com/zhihu/norm/dialectors/dialector.go b/vendor/github.com/zhihu/norm/dialectors/dialector.go new file mode 100644 index 000000000..f3588f20b --- /dev/null +++ b/vendor/github.com/zhihu/norm/dialectors/dialector.go @@ -0,0 +1,53 @@ +/** +* package: dialectors +* file: dirlector.go +* author: wuzhensheng +* create: 2021-06-23 11:52:00 +* description: +**/ +package dialectors + +import ( + "time" + + nebula "github.com/vesoft-inc/nebula-go/v2" +) + +const ( + DefaultTimeout = 60 * time.Second + DefaultIdleTime = 10 * time.Minute + DefaultMaxConnPoolSize = 20 +) + +type ( + ResultSet struct { + *nebula.ResultSet + } + // IDialector mock nebula's pool. 取名来自 gorm 的 Dialector. + IDialector interface { + Execute(stmt string) (*ResultSet, error) + Close() + } + DialectorConfig struct { + Username string `json:"username" yaml:"username"` + Password string `json:"password" yaml:"password"` + Space string `json:"space" yaml:"space"` + Timeout time.Duration `json:"timeout" yaml:"timeout"` + IdleTime time.Duration `json:"idle_time" yaml:"idle_time"` + MaxConnPoolSize int `json:"max_conn_pool_size" yaml:"max_conn_pool_size"` + MinConnPoolSize int `json:"min_conn_pool_size" yaml:"min_conn_pool_size"` + Addresses []string `json:"addresses" yaml:"addresses"` + } +) + +func (config *DialectorConfig) LoadDefault() { + if config.Timeout <= 0 { + config.Timeout = DefaultTimeout + } + if config.IdleTime <= 0 { + config.IdleTime = DefaultIdleTime + } + if config.MaxConnPoolSize <= 0 { + config.MaxConnPoolSize = DefaultMaxConnPoolSize + } +} diff --git a/vendor/github.com/zhihu/norm/dialectors/nebula.go b/vendor/github.com/zhihu/norm/dialectors/nebula.go new file mode 100644 index 000000000..f5a8c5a69 --- /dev/null +++ b/vendor/github.com/zhihu/norm/dialectors/nebula.go @@ -0,0 +1,126 @@ +/** +* package: dialectors +* file: dirlector.go +* author: wuzhensheng +* create: 2021-06-23 11:52:00 +* description: +**/ +package dialectors + +import ( + "fmt" + "strconv" + "strings" + + "github.com/pkg/errors" + nebula "github.com/vesoft-inc/nebula-go/v2" +) + +type ( + NebulaDialector struct { + npool *nebula.ConnectionPool + username string + password string + space string + } +) + +var _ IDialector = new(NebulaDialector) + +func NewNebulaDialector(cfg DialectorConfig) (*NebulaDialector, error) { + cfg.LoadDefault() + nAddresses, err := parseAddresses(cfg.Addresses) + if err != nil { + return &NebulaDialector{}, err + } + nConfig := nebula.PoolConfig{ + TimeOut: cfg.Timeout, + IdleTime: cfg.IdleTime, + MaxConnPoolSize: cfg.MaxConnPoolSize, + MinConnPoolSize: cfg.MinConnPoolSize, + } + nPool, err := nebula.NewConnectionPool(nAddresses, nConfig, nebula.DefaultLogger{}) + if err != nil { + return &NebulaDialector{}, errors.Wrap(err, "connect nebula fail") + } + return &NebulaDialector{ + npool: nPool, + username: cfg.Username, + password: cfg.Password, + space: cfg.Space, + }, nil +} + +// MustNewNebulaDialector 语法糖, 必须新建一个 Nebula Dialector +func MustNewNebulaDialector(cfg DialectorConfig) *NebulaDialector { + dialector, err := NewNebulaDialector(cfg) + if err != nil { + panic(err) + } + return dialector +} + +// Execute TODO 可以缓存一个 session pool. +func (d *NebulaDialector) Execute(stmt string) (*ResultSet, error) { + session, err := d.getSession() + if err != nil { + return &ResultSet{}, err + } + defer session.Release() + + // TODO (nebula bug) 除了 root 用户外, nebula 不支持其他用户 ("use %s; %s", space, sql) 这种方式. + // sql = fmt.Sprintf("use %s; %s", space, sql) + _, err = session.Execute("use " + d.space) + if err != nil { + return &ResultSet{}, err + } + + result, err := session.Execute(stmt) + if err != nil { + return &ResultSet{}, err + } + if err = checkResultSet(result); err != nil { + return &ResultSet{}, err + } + + return &ResultSet{result}, nil +} + +func (d *NebulaDialector) getSession() (*nebula.Session, error) { + return d.npool.GetSession(d.username, d.password) +} + +func (d *NebulaDialector) Close() { + d.npool.Close() +} + +// checkResultSet 检查是否成功执行 +func checkResultSet(nSet *nebula.ResultSet) error { + if nSet.GetErrorCode() != nebula.ErrorCode_SUCCEEDED { + return errors.New(fmt.Sprintf("code: %d, msg: %s", + nSet.GetErrorCode(), nSet.GetErrorMsg())) + } + return nil +} + +// parseAddresses 解析传入的 Host 格式为 nebula 需要的格式 +func parseAddresses(addresses []string) ([]nebula.HostAddress, error) { + hostAddresses := make([]nebula.HostAddress, len(addresses)) + for i, addr := range addresses { + list := strings.Split(addr, ":") + if len(list) < 2 { + return []nebula.HostAddress{}, + errors.New(fmt.Sprintf("address %s invalid", addr)) + } + port, err := strconv.ParseInt(list[1], 10, 64) + if err != nil { + return []nebula.HostAddress{}, + errors.New(fmt.Sprintf("address %s invalid", addr)) + } + hostAddresses[i] = nebula.HostAddress{ + Host: list[0], + Port: int(port), + } + } + return hostAddresses, nil +} diff --git a/vendor/github.com/zhihu/norm/internal/converts/insert_edge.go b/vendor/github.com/zhihu/norm/internal/converts/insert_edge.go new file mode 100644 index 000000000..400c9f38a --- /dev/null +++ b/vendor/github.com/zhihu/norm/internal/converts/insert_edge.go @@ -0,0 +1,51 @@ +package converts + +import ( + "errors" + "reflect" + "strings" + "text/template" +) + +type createEdgeStruct struct { + Name string + Src, Dst string + Keys, Values string +} + +var createEdgeTemplate = template.Must(template.New("insert_edge"). + Parse("insert edge {{.Name}}({{.Keys}}) values {{.Src}} -> {{.Dst}}:({{.Values}})")) + +// ConvertToCreateEdgeSql 转换结构体为创建边的 sql +func ConvertToCreateEdgeSql(in interface{}, edgeName string, src, dst string) (string, error) { + switch values := in.(type) { + case map[string]interface{}: + return buildCreateEdgeSql(values, edgeName, src, dst), nil + case *map[string]interface{}: + return buildCreateEdgeSql(*values, edgeName, src, dst), nil + case []map[string]interface{}: + return "", errors.New("batch insert not support now") + case *[]map[string]interface{}: + return "", errors.New("batch insert not support now") + default: + tagMap, err := parseStructToMap(reflect.ValueOf(in), true) + if err != nil { + return "", err + } + return buildCreateEdgeSql(tagMap, edgeName, src, dst), nil + } +} + +func buildCreateEdgeSql(tagMap map[string]interface{}, edgeName string, src, dst string) string { + keysStr, ValuesStr := genInsertKVs(tagMap) + + buf := new(strings.Builder) + createEdgeTemplate.Execute(buf, &createEdgeStruct{ + Name: edgeName, + Src: src, + Dst: dst, + Keys: keysStr, + Values: ValuesStr, + }) + return buf.String() +} diff --git a/vendor/github.com/zhihu/norm/internal/converts/insert_vertex.go b/vendor/github.com/zhihu/norm/internal/converts/insert_vertex.go new file mode 100644 index 000000000..d93311438 --- /dev/null +++ b/vendor/github.com/zhihu/norm/internal/converts/insert_vertex.go @@ -0,0 +1,119 @@ +package converts + +import ( + "errors" + "reflect" + "strings" + "text/template" + + "github.com/zhihu/norm/constants" + "github.com/zhihu/norm/internal/utils" +) + +type createVertexStruct struct { + Name string + Vid string + Keys, Values string +} + +var createVertexTemplate = template.Must(template.New("insert_vertex"). + Parse("insert vertex {{.Name}}({{.Keys}}) values {{.Vid}}:({{.Values}})")) + +// ConvertToCreateVertexSql 转换结构体为创建点的 sql +func ConvertToCreateVertexSql(in interface{}, tagName string, vidWithPolicy string) (string, error) { + switch values := in.(type) { + case map[string]interface{}: + return buildCreateVertexSql(values, tagName, vidWithPolicy), nil + case *map[string]interface{}: + return buildCreateVertexSql(*values, tagName, vidWithPolicy), nil + case []map[string]interface{}: + return "", errors.New("batch insert not support now") + case *[]map[string]interface{}: + return "", errors.New("batch insert not support now") + default: + tagMap, err := parseStructToMap(reflect.ValueOf(in), true) + if err != nil { + return "", err + } + return buildCreateVertexSql(tagMap, tagName, vidWithPolicy), nil + } +} + +func buildCreateVertexSql(tagMap map[string]interface{}, tagName string, vidWithPolicy string) string { + keysStr, ValuesStr := genInsertKVs(tagMap) + + buf := new(strings.Builder) + createVertexTemplate.Execute(buf, &createVertexStruct{ + Name: tagName, + Vid: vidWithPolicy, + Keys: keysStr, + Values: ValuesStr, + }) + return buf.String() +} + +func genInsertKVs(tagMap map[string]interface{}) (string, string) { + keys := make([]string, len(tagMap)) + values := make([]string, len(tagMap)) + i := 0 + for k, v := range tagMap { + keys[i] = k + values[i] = utils.WrapField(v) + i++ + } + keysStr := strings.Join(keys, ",") + ValuesStr := strings.Join(values, ",") + return keysStr, ValuesStr +} + +// parseStructToMap 解析传入的 struct, 取指定 Tag 为key, 生成 map. +// TODO 可以优化为返回 keys, values, 然后考虑支持批量插入 +func parseStructToMap(val reflect.Value, skipZero bool) (result map[string]interface{}, err error) { + if val.Kind() == reflect.Ptr { + return parseStructToMap(val.Elem(), skipZero) + } + + if val.Kind() != reflect.Struct { + return map[string]interface{}{}, errors.New("must be struct") + } + + defer func() { + if r := recover(); r != nil { + if e, ok := r.(error); ok { + err = e + } else { + err = errors.New("unknown exec error") + } + } + }() + + typ := val.Type() + result = make(map[string]interface{}) + for i := 0; i < typ.NumField(); i++ { + tag := typ.Field(i).Tag.Get(constants.StructTagName) + if tag == "" { + continue + } + value := val.Field(i) + if _, ok := supportKind[value.Kind()]; !ok { + continue + } + if skipZero && value.IsZero() { + continue + } + result[tag] = value.Interface() + } + return +} + +var supportKind = map[reflect.Kind]struct{}{ + reflect.Bool: {}, + reflect.Int: {}, + reflect.Int8: {}, + reflect.Int16: {}, + reflect.Int32: {}, + reflect.Int64: {}, + reflect.Float32: {}, + reflect.Float64: {}, + reflect.String: {}, +} diff --git a/vendor/github.com/zhihu/norm/internal/converts/query.go b/vendor/github.com/zhihu/norm/internal/converts/query.go new file mode 100644 index 000000000..31214c64a --- /dev/null +++ b/vendor/github.com/zhihu/norm/internal/converts/query.go @@ -0,0 +1,167 @@ +package converts + +import ( + "reflect" + + "github.com/pkg/errors" + "github.com/zhihu/norm/dialectors" +) + +var ( + NilPointError = errors.New("assignment to entry in nil map") + RecordNotFoundError = errors.New("record not found") +) + +// UnmarshalResultSet 解组 ResultSet 为传入的结构体 +func UnmarshalResultSet(resultSet *dialectors.ResultSet, in interface{}) error { + switch values := in.(type) { + case map[string]interface{}: + return toMap(values, resultSet) + case *map[string]interface{}: + return toMap(*values, resultSet) + case *[]map[string]interface{}: + return toMapSlice(values, resultSet) + default: + val := reflect.ValueOf(values) + switch val.Kind() { + case reflect.Ptr: + val = reflect.Indirect(val) + switch val.Kind() { + case reflect.Struct: + return toStruct(val, resultSet) + case reflect.Slice: + return toStructSlice(val, resultSet) + case reflect.Int8, reflect.Int16, reflect.Int, reflect.Int32, reflect.Int64: + return toInt(val, resultSet) + default: + return errors.Errorf("not support type. type is:%v", val.Kind()) + } + default: + return errors.New("must be ptr") + } + } +} + +func toInt(val reflect.Value, resultSet *dialectors.ResultSet) (err error) { + if val.Interface() == nil { + return NilPointError + } + + if resultSet.GetRowSize() < 1 { + val.SetInt(0) + return nil + } + + defer func() { + if r := recover(); r != nil { + if e, ok := r.(error); ok { + err = e + } else { + err = errors.New("unknown exec error") + } + } + }() + cnt := resultSet.GetRows()[0].GetValues()[0].IVal + val.SetInt(*cnt) + return nil +} + +func toStruct(val reflect.Value, resultSet *dialectors.ResultSet) (err error) { + if val.Interface() == nil { + return NilPointError + } + + if resultSet.GetRowSize() < 1 { + return RecordNotFoundError + } + + defer func() { + if r := recover(); r != nil { + if e, ok := r.(error); ok { + err = e + } else { + err = errors.New("unknown exec error") + } + } + }() + + row := resultSet.GetRows()[0] + fieldTagMap := getStructFieldTagMap(val.Type()) + for j, col := range resultSet.GetColNames() { + fieldPos, ok := fieldTagMap[col] + if !ok { + continue + } + value := row.GetValues()[j] + field := val.Field(fieldPos) + err = setFieldValue(col, field, value) + } + + return +} + +func toStructSlice(val reflect.Value, resultSet *dialectors.ResultSet) (err error) { + if val.Interface() == nil { + return NilPointError + } + if resultSet.GetRowSize() < 1 { + return + } + + defer func() { + if r := recover(); r != nil { + if e, ok := r.(error); ok { + err = e + } else { + err = errors.New("unknown exec error") + } + } + }() + + val.Set(reflect.MakeSlice(val.Type(), resultSet.GetRowSize(), resultSet.GetRowSize())) + fieldTagMap := getStructFieldTagMap(val.Index(0).Type()) + for i, row := range resultSet.GetRows() { + // 这里可以优化 GetColNames, 只循环两个共有的 key + for j, col := range resultSet.GetColNames() { + fieldPos, ok := fieldTagMap[col] + if !ok { + continue + } + nValue := row.GetValues()[j] + field := val.Index(i).Field(fieldPos) + err = setFieldValue(col, field, nValue) + } + } + return +} + +func toMap(values map[string]interface{}, resultSet *dialectors.ResultSet) error { + if values == nil { + return NilPointError + } + if resultSet.GetRowSize() < 1 { + return RecordNotFoundError + } + row := resultSet.GetRows()[0] + for i, col := range resultSet.GetColNames() { + values[col] = nValueToInterface(row.Values[i]) + } + return nil +} + +func toMapSlice(values *[]map[string]interface{}, resultSet *dialectors.ResultSet) error { + if values == nil { + return NilPointError + } + + cols := resultSet.GetColNames() + _values := make([]map[string]interface{}, resultSet.GetRowSize()) + for i, row := range resultSet.GetRows() { + _values[i] = make(map[string]interface{}) + for j, col := range cols { + _values[i][col] = nValueToInterface(row.Values[j]) + } + } + *values = append(*values, _values...) + return nil +} diff --git a/vendor/github.com/zhihu/norm/internal/converts/upsert_edge.go b/vendor/github.com/zhihu/norm/internal/converts/upsert_edge.go new file mode 100644 index 000000000..d18179545 --- /dev/null +++ b/vendor/github.com/zhihu/norm/internal/converts/upsert_edge.go @@ -0,0 +1,43 @@ +package converts + +import ( + "reflect" + "strings" + "text/template" +) + +type upsertEdgeStruct struct { + Name string + Src, Dst string + UpdateProp string +} + +var upsertEdgeTemplate = template.Must(template.New("upsert_edge"). + Parse("upsert edge on {{.Name}} {{.Src}} -> {{.Dst}} set {{.UpdateProp}} ")) + +// ConvertToUpsertEdgeSql 转换结构体为 Upsert 边的 sql +func ConvertToUpsertEdgeSql(in interface{}, edgeName string, src, dst string) (string, error) { + switch values := in.(type) { + case map[string]interface{}: + return buildUpsertEdgeSql(values, edgeName, src, dst), nil + case *map[string]interface{}: + return buildUpsertEdgeSql(*values, edgeName, src, dst), nil + default: + tagMap, err := parseStructToMap(reflect.ValueOf(in), true) + if err != nil { + return "", err + } + return buildUpsertEdgeSql(tagMap, edgeName, src, dst), nil + } +} + +func buildUpsertEdgeSql(tagMap map[string]interface{}, edgeName string, src, dst string) string { + buf := new(strings.Builder) + upsertEdgeTemplate.Execute(buf, &upsertEdgeStruct{ + Name: edgeName, + Src: src, + Dst: dst, + UpdateProp: genUpsertUpdateProp(tagMap), + }) + return buf.String() +} diff --git a/vendor/github.com/zhihu/norm/internal/converts/upsert_vertex.go b/vendor/github.com/zhihu/norm/internal/converts/upsert_vertex.go new file mode 100644 index 000000000..27b949e5b --- /dev/null +++ b/vendor/github.com/zhihu/norm/internal/converts/upsert_vertex.go @@ -0,0 +1,55 @@ +package converts + +import ( + "fmt" + "reflect" + "strings" + "text/template" + + "github.com/zhihu/norm/internal/utils" +) + +type upsertVertexStruct struct { + Name string + Vid string + UpdateProp string +} + +var upsertVertexTemplate = template.Must(template.New("upsert_vertex"). + Parse("upsert vertex on {{.Name}} {{.Vid}}) set {{.UpdateProp}}")) + +// ConvertToUpsertVertexSql 转换结构体为更新点的 sql +func ConvertToUpsertVertexSql(in interface{}, tagName string, vidWithPolicy string) (string, error) { + switch values := in.(type) { + case map[string]interface{}: + return buildUpsertVertexSql(values, tagName, vidWithPolicy), nil + case *map[string]interface{}: + return buildUpsertVertexSql(*values, tagName, vidWithPolicy), nil + default: + tagMap, err := parseStructToMap(reflect.ValueOf(in), true) + if err != nil { + return "", err + } + return buildUpsertVertexSql(tagMap, tagName, vidWithPolicy), nil + } +} + +func buildUpsertVertexSql(tagMap map[string]interface{}, tagName string, vidWithPolicy string) string { + buf := new(strings.Builder) + upsertVertexTemplate.Execute(buf, &upsertVertexStruct{ + Name: tagName, + Vid: vidWithPolicy, + UpdateProp: genUpsertUpdateProp(tagMap), + }) + return buf.String() +} + +func genUpsertUpdateProp(tagMap map[string]interface{}) string { + updateProps := make([]string, len(tagMap)) + i := 0 + for k, v := range tagMap { + updateProps[i] = fmt.Sprintf("%s=%s", k, utils.WrapField(v)) + i++ + } + return strings.Join(updateProps, ",") +} diff --git a/vendor/github.com/zhihu/norm/internal/converts/util.go b/vendor/github.com/zhihu/norm/internal/converts/util.go new file mode 100644 index 000000000..b43d33102 --- /dev/null +++ b/vendor/github.com/zhihu/norm/internal/converts/util.go @@ -0,0 +1,95 @@ +package converts + +import ( + "reflect" + "time" + + nebula_type "github.com/vesoft-inc/nebula-go/v2/nebula" + "github.com/zhihu/norm/constants" +) + +// getStructFieldTagMap 将 struct 中标记为 norm 的 tag 提取出来, 并记录 field 的位置 +func getStructFieldTagMap(typ reflect.Type) map[string]int { + tagMap := make(map[string]int) + for i := 0; i < typ.NumField(); i++ { + tag := typ.Field(i).Tag.Get(constants.StructTagName) + if tag == "" || tag == "-" { + continue + } + tagMap[tag] = i + } + return tagMap +} + +// setFieldValue 将 nvalue 的值设置到 struct.field 上, 并自动转换类型 +func setFieldValue(tag string, field reflect.Value, nValue *nebula_type.Value) error { + switch field.Kind() { + case reflect.Bool: + field.SetBool(nValue.GetBVal()) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + field.SetInt(nValue.GetIVal()) + case reflect.Float32, reflect.Float64: + field.SetFloat(nValue.GetFVal()) + case reflect.String: + field.SetString(string(nValue.GetSVal())) + case reflect.Struct: + switch field.Type().String() { + case "time.Time": + ts := nValue.GetIVal() + field.Set(reflect.ValueOf(time.Unix(ts, 0))) + default: + //fmt.Printf("debug: type[%v] mapping not implement\n", field.Type().String()) + } + default: + //fmt.Printf("debug: type[%v] mapping not implement\n", field.Type().String()) + return nil + } + return nil +} + +// nValueToInterface 将 nvalue 的值转换类型并返回interface +func nValueToInterface(p *nebula_type.Value) interface{} { + if p.IsSetNVal() { + return p.GetNVal() + } + if p.IsSetBVal() { + return p.GetBVal() + } + if p.IsSetIVal() { + return p.GetIVal() + } + if p.IsSetFVal() { + return p.GetFVal() + } + if p.IsSetDVal() { + return p.GetDVal() + } + if p.IsSetTVal() { + return p.GetTVal() + } + if p.IsSetDtVal() { + return p.GetDtVal() + } + if p.IsSetVVal() { + return p.GetVVal() + } + if p.IsSetEVal() { + return p.GetEVal() + } + if p.IsSetPVal() { + return p.GetPVal() + } + if p.IsSetLVal() { + return p.GetLVal() + } + if p.IsSetMVal() { + return p.GetMVal() + } + if p.IsSetUVal() { + return p.GetUVal() + } + if p.IsSetGVal() { + return p.GetGVal() + } + return nil +} diff --git a/vendor/github.com/zhihu/norm/internal/utils/util.go b/vendor/github.com/zhihu/norm/internal/utils/util.go new file mode 100644 index 000000000..59f9b1846 --- /dev/null +++ b/vendor/github.com/zhihu/norm/internal/utils/util.go @@ -0,0 +1,13 @@ +package utils + +import "fmt" + +// WrapField wrap 字段, 使其符合 nebula 插入的习惯. 如给 string 添加引号 +func WrapField(in interface{}) string { + switch value := in.(type) { + case string: + return "'" + value + "'" + default: + return fmt.Sprint(value) + } +} diff --git a/vendor/github.com/zhihu/norm/v3/.gitignore b/vendor/github.com/zhihu/norm/v3/.gitignore new file mode 100644 index 000000000..7c5521c0d --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/.gitignore @@ -0,0 +1,91 @@ +.buildout/ + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +build/ +develop-eggs/ +dist/ +eggs/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.tox/ +.coverage +nosetests.xml +coverage.xml + +# Test log file +*.log + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + + +### /Users/hdd/.gitignore-boilerplates/Global/OSX.gitignore + +.DS_Store +.AppleDouble +.LSOverride + +# Icon must ends with two \r. +Icon + + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + + +### /Users/hdd/.gitignore-boilerplates/Global/PyCharm.gitignore + +# PyCharm +# http://www.jetbrains.com/pycharm/webhelp/project.html +.idea +.iml + + +### /Users/hdd/.gitignore-boilerplates/Global/Vim.gitignore + +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +*.un~ +Session.vim +.netrwhist +*~ + +# ignore doc build file +docs/_build/ + +# docker +nohup.* +*.out + +.vscode/ +.settings/ +.idea/ + +gen-py/ +vendor/ \ No newline at end of file diff --git a/vendor/github.com/zhihu/norm/v3/CODE_OF_CONDUCT.md b/vendor/github.com/zhihu/norm/v3/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..ae596ec11 --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/CODE_OF_CONDUCT.md @@ -0,0 +1,132 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[INSERT CONTACT METHOD]. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available +at [https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations diff --git a/vendor/github.com/zhihu/norm/v3/CODE_OF_CONDUCT_CN.md b/vendor/github.com/zhihu/norm/v3/CODE_OF_CONDUCT_CN.md new file mode 100644 index 000000000..c2b0fa0cd --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/CODE_OF_CONDUCT_CN.md @@ -0,0 +1,87 @@ +# 贡献者公约 + +## 我们的承诺 + +身为项目成员、贡献者、负责人,我们保证参与此社区的每个人都不受骚扰,不论其年龄、体型、身体条件、民族、性征、性别认同与表现、经验水平、教育程度、社会地位、国籍、相貌、种族、宗教信仰及性取向如何。 + +我们承诺致力于建设开放、友善、多元、包容、健康的社区环境。 + +## 我们的准则 + +有助于促进本社区积极环境的行为包括但不限于: + +* 与人为善、推己及人 +* 尊重不同的主张、观点和经历 +* 积极提出、耐心接受有益批评 +* 面对过失,承担责任、认真道歉、从中学习 +* 关注社区共同诉求,而非一己私利 + +不当行为包括但不限于: + +* 发布与性有关的言论或图像,以及任何形式的献殷勤或勾引 +* 挑衅行为、侮辱或贬损的言论、人身及政治攻击 +* 公开或私下骚扰 +* 未获明确授权擅自发布他人的资料,如地址、电子邮箱等 +* 其他有理由认定为违反职业操守的不当行为 + +## 落实之义务 + +社区负责人有责任诠释何谓“妥当行为”,并据此准则,妥善公正地认定与处置不当、威胁、冒犯及有害的行为。 + +社区负责人有权利和义务删除、编辑、拒绝违背本公约的评论(comment)、提交(commit)、代码、维基(wiki)编辑、问题(issue)等贡献。如有必要,需告知采取措施之理由。 + +## 适用范围 + +此行为标准适用于本社区全部场合,以及在其他场合代表本社区的个人。 + +代表本社区的情形包括但不限于:使用官方电子邮件与社交平台、作为指定代表参与在线或线下活动。 + +## 贯彻落实 + +如遇滥用、骚扰等不当行为,请通过[在此输入联系方式]向纪律检查委员举报。 +纪委将迅速审议并调查全部投诉。 + +社区全体负责人有义务保密举报者信息。 + +## 指导方针 + +社区负责人将依据下列方案判断并处置违纪行为: + +### 一、督促 + +**社区影响**:用语不当、举止不符合职业道德或不受社区欢迎。 + +**处理意见**:由社区负责人予以非公开的书面警告,阐明违纪事由、解释举止如何不妥。或将要求公开道歉。 + +### 二、警告 + +**社区影响**:一起或多起事件中的违纪行为。 + +**处理意见**:警告继续违纪之后果、违纪者在特定时间内禁止与当事人往来、不得擅自与社区执法者往来,禁令涵盖社区内外、社交网络在内的一切联络。如有违反,可致封禁乃至开除。 + +### 三、封禁 + +**社区影响**:严重违纪行为,包括屡教不改。 + +**处理意见**:违纪者在特定时间内禁止与社区的任何往来或公开联络,禁止任何与当事人公开或私下往来,不得擅自与社区执法者往来。如有违反,可致开除。 + +### 四、开除 + +**社区影响**:典型违纪行为,例如屡教不改、骚扰某个人、敌对或贬低某个群体。 + +**处理意见**:无限期禁止违纪者与项目社区的一切公开往来。 + +## 来源 + +本行为标准改编自[参与者公约][homepage]2.0版,可在此查阅:[https://www.contributor-covenant.org/zh-cn/version/2/0/code_of_conduct.html][v2.0] + +指导方针借鉴自[Mozilla纪检分级][Mozilla CoC]。 + +此行为标准常见问题请洽:[https://www.contributor-covenant.org/faq][FAQ]。 +另有诸译本:[https://www.contributor-covenant.org/translations][translations]。 + +[homepage]:https://www.contributor-covenant.org +[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations diff --git a/vendor/github.com/zhihu/norm/v3/CONTRIBUTING.md b/vendor/github.com/zhihu/norm/v3/CONTRIBUTING.md new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/github.com/zhihu/norm/v3/LICENSE b/vendor/github.com/zhihu/norm/v3/LICENSE new file mode 100644 index 000000000..08cbfdcf6 --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Zhihu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/zhihu/norm/v3/Makefile b/vendor/github.com/zhihu/norm/v3/Makefile new file mode 100644 index 000000000..31eb0ee6f --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/Makefile @@ -0,0 +1,17 @@ +all: test + +vendor: + go mod vendor + +lint: + $(ENV) golangci-lint run -c .golangci.yml --fix ./... + +test: + go test -coverprofile=coverage.out ./... + +mock: + # go get github.com/golang/mock/gomock + # Source Mode + @mockgen -package=mocks -destination dialectors/mocks/dialector.go -source=dialectors/dialector.go + +.PHONY: test diff --git a/vendor/github.com/zhihu/norm/v3/README.md b/vendor/github.com/zhihu/norm/v3/README.md new file mode 100644 index 000000000..923c5793b --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/README.md @@ -0,0 +1,57 @@ +# norm + +An ORM library support nGQL for Golang. + +[![go report card](https://goreportcard.com/badge/github.com/zhihu/norm "go report card")](https://goreportcard.com/report/github.com/zhihu/norm) +[![Go](https://github.com/zhihu/norm/actions/workflows/go.yml/badge.svg)](https://github.com/zhihu/norm/actions/workflows/go.yml) +[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT) +[![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-blue?logo=go&logoColor=white)](https://pkg.go.dev/github.com/zhihu/norm) + +## Overview + +* Build insert nGQL by struct / map (Support vertex, edge). +* Parse Nebula execute result to struct / map. +* Easy to use. +* Easy mock for Unit Testing. + +**Roadmap** + +1. Session pool. For details, please see [dialector](/docs/dialector.adoc) +2. Support more types in insert/execute function. + * Types: time.Time +3. Support batch insert, query list. +4. Chainable api. For detail please see [chainable api](/docs/chainable_api.adoc) + +**Maybe Support** + +- [ ] Statistic Hooks. Insert/Query count and latency. +- [ ] Fix fields Order when build insert nGQL. (now norm use map store keys, and in go range map is out-of-order.) + +**Need improve** + +- [ ] Benchmark. +- [ ] Unit Testing. +- [ ] Documents. + +## Getting Started + +Install: + +``` +go get github.com/zhihu/norm +``` + +use example: please go [use example](/examples/main.go) + +## Contributing guidelines + +* [code of conduct](/CODE_OF_CONDUCT.md) +* [行为规范 中文版](/CODE_OF_CONDUCT_CN.md) + +## License + +© Zhihu, 2021~time.Now + +Released under the [MIT License](/LICENSE) + +_copy and paste from gorm_ diff --git a/vendor/github.com/zhihu/norm/v3/api_chainable.go b/vendor/github.com/zhihu/norm/v3/api_chainable.go new file mode 100644 index 000000000..f67a053cb --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/api_chainable.go @@ -0,0 +1,94 @@ +package norm + +import ( + "fmt" + "strings" + + "github.com/zhihu/norm/constants" +) + +// Debug will print the nGql when it exec +func (db *DB) Debug() (tx *DB) { + tx = db.getInstance() + tx.debug = true + return +} + +func (db *DB) Go(step int) (tx *DB) { + tx = db.getInstance() + + if step > 1 { + tx.sql += fmt.Sprintf("go %d step ", step) + } + + return +} + +func (db *DB) From(vs ...IVertex) (tx *DB) { + tx = db.getInstance() + + vids := make([]string, len(vs)) + for i, v := range vs { + vids[i] = GetVidWithPolicy(v.GetVid(), v.GetPolicy()) + } + + if tx.sql == "" { + tx.sql += "go " + } + tx.sql += fmt.Sprintf("from %s ", strings.Join(vids, ",")) + + return +} + +func (db *DB) Over(edges ...IEdge) (tx *DB) { + tx = db.getInstance() + names := make([]string, len(edges)) + for i, edge := range edges { + names[i] = edge.EdgeName() + } + sql := strings.Join(names, ",") + tx.sql += fmt.Sprintf("over %s ", sql) + return +} + +// Reversely over egde reversely +func (db *DB) Reversely() (tx *DB) { + tx = db.getInstance() + tx.sql += constants.DirectionReversely + " " + return +} + +// Bidirect over egde bidirect +func (db *DB) Bidirect() (tx *DB) { + tx = db.getInstance() + tx.sql += constants.DirectionBidirect + " " + return +} + +func (db *DB) Limit(limit int) (tx *DB) { + tx = db.getInstance() + tx.sql += fmt.Sprintf("|limit %d ", limit) + return +} + +func (db *DB) Where(sql string) (tx *DB) { + tx = db.getInstance() + tx.sql += fmt.Sprintf("where %s ", sql) + return +} + +func (db *DB) Yield(sql string) (tx *DB) { + tx = db.getInstance() + tx.sql += fmt.Sprintf("yield %s ", sql) + return +} + +func (db *DB) Group(fields ...string) (tx *DB) { + tx = db.getInstance() + for i := range fields { + fields[i] = "$-." + fields[i] + } + sql := strings.Join(fields, ",") + tx.sql += fmt.Sprintf("|group by %s ", sql) + return +} diff --git a/vendor/github.com/zhihu/norm/v3/api_finished.go b/vendor/github.com/zhihu/norm/v3/api_finished.go new file mode 100644 index 000000000..745d05762 --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/api_finished.go @@ -0,0 +1,84 @@ +package norm + +import ( + "github.com/zhihu/norm/dialectors" + "github.com/zhihu/norm/internal/converts" +) + +// Execute 执行某条sql +func (db *DB) Execute(sql string) (*dialectors.ResultSet, error) { + return db.execute(sql) +} + +// ExecuteAndParse 执行某条sql, 然后解析为传入的结构. +// in 可以是 map[string]interface{}, *Strcut, *[]map, *[]struct +func (db *DB) ExecuteAndParse(sql string, in interface{}) error { + nResult, err := db.execute(sql) + if err != nil { + return err + } + return converts.UnmarshalResultSet(nResult, in) +} + +// InsertVertex 解析结构体, 然后插入一个点. +func (db *DB) InsertVertex(in IVertex) error { + vidWithPolicy := GetVidWithPolicy(in.GetVid(), in.GetPolicy()) + sql, err := converts.ConvertToCreateVertexSql(in, in.TagName(), vidWithPolicy) + if err != nil { + return err + } + _, err = db.execute(sql) + return err +} + +// UpsertVertex 解析结构体, 然后 Upsert 一个点. +func (db *DB) UpsertVertex(in IVertex) error { + vidWithPolicy := GetVidWithPolicy(in.GetVid(), in.GetPolicy()) + sql, err := converts.ConvertToUpsertVertexSql(in, in.TagName(), vidWithPolicy) + if err != nil { + return err + } + _, err = db.execute(sql) + return err +} + +// InsertEdge 解析结构体, 然后插入一条边. +func (db *DB) InsertEdge(in IEdge) error { + vidSrcWithPolicy := GetVidWithPolicy(in.GetVidSrc(), in.GetVidSrcPolicy()) + vidDstWithPolicy := GetVidWithPolicy(in.GetVidDst(), in.GetVidDstPolicy()) + sql, err := converts.ConvertToCreateEdgeSql(in, in.EdgeName(), vidSrcWithPolicy, vidDstWithPolicy) + if err != nil { + return err + } + _, err = db.execute(sql) + return err +} + +// UpsertEdge 解析结构体, 然后插入 Upsert 一条边. +func (db *DB) UpsertEdge(in IEdge) error { + vidSrcWithPolicy := GetVidWithPolicy(in.GetVidSrc(), in.GetVidSrcPolicy()) + vidDstWithPolicy := GetVidWithPolicy(in.GetVidDst(), in.GetVidDstPolicy()) + sql, err := converts.ConvertToUpsertEdgeSql(in, in.EdgeName(), vidSrcWithPolicy, vidDstWithPolicy) + if err != nil { + return err + } + _, err = db.execute(sql) + return err +} + +// ReturnRow 返回 nsql 执行的原始结果, 不进行任何加工 +func (db *DB) ReturnRow() (*dialectors.ResultSet, error) { + return db.execute(db.sql) +} + +// Return 返回数据并将结果反序列化到 out 结构体中 +func (db *DB) Return(out interface{}) error { + return db.ExecuteAndParse(db.sql, out) +} + +// Count 计算符合条件的数据数量 +func (db *DB) Count(out interface{}) error { + // 不用 match 的 count 原因是部分情况下有 bug + // 参考 https://github.com/vesoft-inc/nebula/issues/2934 + return db.Yield(" '' as id").Group("id").Yield("count(1)").Return(out) +} diff --git a/vendor/github.com/zhihu/norm/v3/config.go b/vendor/github.com/zhihu/norm/v3/config.go new file mode 100644 index 000000000..3235f9d8f --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/config.go @@ -0,0 +1,20 @@ +package norm + +type Config struct { + DebugMode bool + logger Logger +} + +func (config *Config) LoadDefault() { + if config.logger == nil { + config.logger = &DefaultLogger{} + } +} + +type Option func(c *Config) + +func WithLogger(logger Logger) Option { + return func(c *Config) { + c.logger = logger + } +} diff --git a/vendor/github.com/zhihu/norm/v3/dialectors/dialector.go b/vendor/github.com/zhihu/norm/v3/dialectors/dialector.go new file mode 100644 index 000000000..c82b210c2 --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/dialectors/dialector.go @@ -0,0 +1,53 @@ +/** +* package: dialectors +* file: dirlector.go +* author: wuzhensheng +* create: 2021-06-23 11:52:00 +* description: +**/ +package dialectors + +import ( + "time" + + nebula "github.com/vesoft-inc/nebula-go/v3" +) + +const ( + DefaultTimeout = 60 * time.Second + DefaultIdleTime = 10 * time.Minute + DefaultMaxConnPoolSize = 20 +) + +type ( + ResultSet struct { + *nebula.ResultSet + } + // IDialector mock nebula's pool. 取名来自 gorm 的 Dialector. + IDialector interface { + Execute(stmt string) (*ResultSet, error) + Close() + } + DialectorConfig struct { + Username string `json:"username" yaml:"username"` + Password string `json:"password" yaml:"password"` + Space string `json:"space" yaml:"space"` + Timeout time.Duration `json:"timeout" yaml:"timeout"` + IdleTime time.Duration `json:"idle_time" yaml:"idle_time"` + MaxConnPoolSize int `json:"max_conn_pool_size" yaml:"max_conn_pool_size"` + MinConnPoolSize int `json:"min_conn_pool_size" yaml:"min_conn_pool_size"` + Addresses []string `json:"addresses" yaml:"addresses"` + } +) + +func (config *DialectorConfig) LoadDefault() { + if config.Timeout <= 0 { + config.Timeout = DefaultTimeout + } + if config.IdleTime <= 0 { + config.IdleTime = DefaultIdleTime + } + if config.MaxConnPoolSize <= 0 { + config.MaxConnPoolSize = DefaultMaxConnPoolSize + } +} diff --git a/vendor/github.com/zhihu/norm/v3/dialectors/nebula.go b/vendor/github.com/zhihu/norm/v3/dialectors/nebula.go new file mode 100644 index 000000000..4eb916c50 --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/dialectors/nebula.go @@ -0,0 +1,126 @@ +/** +* package: dialectors +* file: dirlector.go +* author: wuzhensheng +* create: 2021-06-23 11:52:00 +* description: +**/ +package dialectors + +import ( + "fmt" + "strconv" + "strings" + + "github.com/pkg/errors" + nebula "github.com/vesoft-inc/nebula-go/v3" +) + +type ( + NebulaDialector struct { + npool *nebula.ConnectionPool + username string + password string + space string + } +) + +var _ IDialector = new(NebulaDialector) + +func NewNebulaDialector(cfg DialectorConfig) (*NebulaDialector, error) { + cfg.LoadDefault() + nAddresses, err := parseAddresses(cfg.Addresses) + if err != nil { + return &NebulaDialector{}, err + } + nConfig := nebula.PoolConfig{ + TimeOut: cfg.Timeout, + IdleTime: cfg.IdleTime, + MaxConnPoolSize: cfg.MaxConnPoolSize, + MinConnPoolSize: cfg.MinConnPoolSize, + } + nPool, err := nebula.NewConnectionPool(nAddresses, nConfig, nebula.DefaultLogger{}) + if err != nil { + return &NebulaDialector{}, errors.Wrap(err, "connect nebula fail") + } + return &NebulaDialector{ + npool: nPool, + username: cfg.Username, + password: cfg.Password, + space: cfg.Space, + }, nil +} + +// MustNewNebulaDialector 语法糖, 必须新建一个 Nebula Dialector +func MustNewNebulaDialector(cfg DialectorConfig) *NebulaDialector { + dialector, err := NewNebulaDialector(cfg) + if err != nil { + panic(err) + } + return dialector +} + +// Execute TODO 可以缓存一个 session pool. +func (d *NebulaDialector) Execute(stmt string) (*ResultSet, error) { + session, err := d.getSession() + if err != nil { + return &ResultSet{}, err + } + defer session.Release() + + // TODO (nebula bug) 除了 root 用户外, nebula 不支持其他用户 ("use %s; %s", space, sql) 这种方式. + // sql = fmt.Sprintf("use %s; %s", space, sql) + _, err = session.Execute("use " + d.space) + if err != nil { + return &ResultSet{}, err + } + + result, err := session.Execute(stmt) + if err != nil { + return &ResultSet{}, err + } + if err = checkResultSet(result); err != nil { + return &ResultSet{}, err + } + + return &ResultSet{result}, nil +} + +func (d *NebulaDialector) getSession() (*nebula.Session, error) { + return d.npool.GetSession(d.username, d.password) +} + +func (d *NebulaDialector) Close() { + d.npool.Close() +} + +// checkResultSet 检查是否成功执行 +func checkResultSet(nSet *nebula.ResultSet) error { + if nSet.GetErrorCode() != nebula.ErrorCode_SUCCEEDED { + return errors.New(fmt.Sprintf("code: %d, msg: %s", + nSet.GetErrorCode(), nSet.GetErrorMsg())) + } + return nil +} + +// parseAddresses 解析传入的 Host 格式为 nebula 需要的格式 +func parseAddresses(addresses []string) ([]nebula.HostAddress, error) { + hostAddresses := make([]nebula.HostAddress, len(addresses)) + for i, addr := range addresses { + list := strings.Split(addr, ":") + if len(list) < 2 { + return []nebula.HostAddress{}, + errors.New(fmt.Sprintf("address %s invalid", addr)) + } + port, err := strconv.ParseInt(list[1], 10, 64) + if err != nil { + return []nebula.HostAddress{}, + errors.New(fmt.Sprintf("address %s invalid", addr)) + } + hostAddresses[i] = nebula.HostAddress{ + Host: list[0], + Port: int(port), + } + } + return hostAddresses, nil +} diff --git a/vendor/github.com/zhihu/norm/v3/exector.go b/vendor/github.com/zhihu/norm/v3/exector.go new file mode 100644 index 000000000..a08dce091 --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/exector.go @@ -0,0 +1,23 @@ +package norm + +import ( + "github.com/zhihu/norm/dialectors" +) + +// execute 真正执行一个 sql +func (db *DB) execute(sql string) (*dialectors.ResultSet, error) { + tx := db.getInstance() + // 指定 space + tx.sql = sql + if tx.debug { + tx.logger.Info(tx.sql) + } + defer tx.teardown() + + result, err := tx.dialector.Execute(sql) + if err != nil { + return &dialectors.ResultSet{}, err + } + + return result, nil +} diff --git a/vendor/github.com/zhihu/norm/v3/logger.go b/vendor/github.com/zhihu/norm/v3/logger.go new file mode 100644 index 000000000..1818a6fe2 --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/logger.go @@ -0,0 +1,9 @@ +package norm + +import ( + nebula "github.com/vesoft-inc/nebula-go/v3" +) + +type Logger = nebula.Logger + +type DefaultLogger = nebula.DefaultLogger diff --git a/vendor/github.com/zhihu/norm/v3/model.go b/vendor/github.com/zhihu/norm/v3/model.go new file mode 100644 index 000000000..fb2485502 --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/model.go @@ -0,0 +1,94 @@ +package norm + +import ( + "fmt" + + "github.com/zhihu/norm/constants" +) + +type ( + ITag interface { + TagName() string + } + IVertex interface { + ITag + GetVid() interface{} + GetPolicy() constants.Policy + } + // vid is int or string + VModel struct { + Vid interface{} `norm:"-"` + Policy constants.Policy `norm:"-"` + } +) + +var _ IVertex = new(VModel) + +func (v VModel) TagName() string { + // TODO return model name with snake style + panic("") +} + +func (v VModel) GetVid() interface{} { + return v.Vid +} + +func (v VModel) GetPolicy() constants.Policy { + return v.Policy +} + +type ( + IEdge interface { + // 返回边的名称 + EdgeName() string + GetVidSrc() interface{} + GetVidSrcPolicy() constants.Policy + GetVidDst() interface{} + GetVidDstPolicy() constants.Policy + } + EModel struct { + Src interface{} `norm:"-"` + SrcPolicy constants.Policy `norm:"-"` + Dst interface{} `norm:"-"` + DstPolicy constants.Policy `norm:"-"` + } +) + +var _ IEdge = new(EModel) + +func (v EModel) EdgeName() string { + panic("") +} + +func (v EModel) GetVidSrc() interface{} { + return v.Src +} + +func (v EModel) GetVidSrcPolicy() constants.Policy { + return v.SrcPolicy +} + +func (v EModel) GetVidDst() interface{} { + return v.Dst +} + +func (v EModel) GetVidDstPolicy() constants.Policy { + return v.DstPolicy +} + +func GetVidWithPolicy(vid interface{}, policy constants.Policy) string { + vidStr := "" + switch vid := vid.(type) { + case int, int8, int32, int64, float32, float64: + vidStr = fmt.Sprint(vid) + case string: + vidStr = "'" + vid + "'" + default: + vidStr += "'" + fmt.Sprint(vid) + "'" + } + switch policy { + case constants.PolicyHash: + vidStr = "hash(" + vidStr + ")" + } + return vidStr +} diff --git a/vendor/github.com/zhihu/norm/v3/norm.go b/vendor/github.com/zhihu/norm/v3/norm.go new file mode 100644 index 000000000..41ba766b9 --- /dev/null +++ b/vendor/github.com/zhihu/norm/v3/norm.go @@ -0,0 +1,73 @@ +package norm + +import ( + "github.com/pkg/errors" + "github.com/zhihu/norm/dialectors" +) + +var teardown = func() {} + +type DB struct { + dialector dialectors.IDialector + logger Logger + + // 一次查询所需的字段 + parent *DB + debug bool + sql string + + // 一次查询结束后需要执行的操作 + teardown func() +} + +// Open initialize nebula connect pool +func Open(dialector dialectors.IDialector, cfg Config, opts ...Option) (*DB, error) { + if dialector == nil { + return &DB{}, errors.New("must have dialector") + } + for _, opt := range opts { + opt(&cfg) + } + cfg.LoadDefault() + return &DB{ + dialector: dialector, + logger: cfg.logger, + parent: nil, + debug: cfg.DebugMode, + teardown: teardown, + }, nil +} + +// MustOpen 语法糖. 如果 error 则 panic, 适用于强依赖 db 的场景 +func MustOpen(dialector dialectors.IDialector, cfg Config, opts ...Option) *DB { + db, err := Open(dialector, cfg, opts...) + if err != nil { + panic(err) + } + return db +} + +// Close +func (db *DB) Close() { + db.dialector.Close() +} + +// DebugMode 调试模式, 会输出任意语句的sql +func (db *DB) DebugMode() { + db.debug = true +} + +// getInstance 获取当前调用链真正使用的 db. 专为链式调用设计, 为每条调用链返回一个 db 的拷贝, 从而避免互相影响. +func (db *DB) getInstance() (tx *DB) { + if db.parent == nil { + tx = &DB{ + dialector: db.dialector, + logger: db.logger, + parent: db, + debug: db.debug, + teardown: teardown, + } + return tx + } + return db +} diff --git a/vendor/modules.txt b/vendor/modules.txt index ea8be8262..09e3b18d6 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -341,11 +341,26 @@ github.com/stoewer/go-strcase # github.com/stretchr/testify v1.8.3 ## explicit; go 1.20 github.com/stretchr/testify/assert -# github.com/vesoft-inc/nebula-go/v3 v3.0.0 +# github.com/vesoft-inc/nebula-go/v2 v2.0.0-ga +## explicit; go 1.13 +github.com/vesoft-inc/nebula-go/v2 +github.com/vesoft-inc/nebula-go/v2/nebula +github.com/vesoft-inc/nebula-go/v2/nebula/graph +# github.com/vesoft-inc/nebula-go/v3 v3.3.1 ## explicit; go 1.13 github.com/vesoft-inc/nebula-go/v3 github.com/vesoft-inc/nebula-go/v3/nebula github.com/vesoft-inc/nebula-go/v3/nebula/graph +# github.com/zhihu/norm v0.1.11 +## explicit; go 1.15 +github.com/zhihu/norm/constants +github.com/zhihu/norm/dialectors +github.com/zhihu/norm/internal/converts +github.com/zhihu/norm/internal/utils +# github.com/zhihu/norm/v3 v3.0.0 +## explicit; go 1.15 +github.com/zhihu/norm/v3 +github.com/zhihu/norm/v3/dialectors # go.etcd.io/etcd/api/v3 v3.5.6 ## explicit; go 1.16 go.etcd.io/etcd/api/v3/authpb