Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于Value的处理 #306

Open
AntarcticPresident opened this issue Jan 23, 2024 · 3 comments
Open

关于Value的处理 #306

AntarcticPresident opened this issue Jan 23, 2024 · 3 comments
Labels
type/question Type: question about the product

Comments

@AntarcticPresident
Copy link

type Value struct {
  NVal *NullType `thrift:"nVal,1,optional" db:"nVal" json:"nVal,omitempty"`
  BVal *bool `thrift:"bVal,2,optional" db:"bVal" json:"bVal,omitempty"`
  IVal *int64 `thrift:"iVal,3,optional" db:"iVal" json:"iVal,omitempty"`
  FVal *float64 `thrift:"fVal,4,optional" db:"fVal" json:"fVal,omitempty"`
  SVal []byte `thrift:"sVal,5,optional" db:"sVal" json:"sVal,omitempty"`
  DVal *Date `thrift:"dVal,6,optional" db:"dVal" json:"dVal,omitempty"`
  TVal *Time `thrift:"tVal,7,optional" db:"tVal" json:"tVal,omitempty"`
  DtVal *DateTime `thrift:"dtVal,8,optional" db:"dtVal" json:"dtVal,omitempty"`
  VVal *Vertex `thrift:"vVal,9,optional" db:"vVal" json:"vVal,omitempty"`
  EVal *Edge `thrift:"eVal,10,optional" db:"eVal" json:"eVal,omitempty"`
  PVal *Path `thrift:"pVal,11,optional" db:"pVal" json:"pVal,omitempty"`
  LVal *NList `thrift:"lVal,12,optional" db:"lVal" json:"lVal,omitempty"`
  MVal *NMap `thrift:"mVal,13,optional" db:"mVal" json:"mVal,omitempty"`
  UVal *NSet `thrift:"uVal,14,optional" db:"uVal" json:"uVal,omitempty"`
  GVal *DataSet `thrift:"gVal,15,optional" db:"gVal" json:"gVal,omitempty"`
  GgVal *Geography `thrift:"ggVal,16,optional" db:"ggVal" json:"ggVal,omitempty"`
  DuVal *Duration `thrift:"duVal,17,optional" db:"duVal" json:"duVal,omitempty"`
}

这段不能理解,按照逻辑,这里面的属性,只会有一个有值,那把它写成any,然后进行类型判断不好吗?做个interface,不是更简洁?

@haoxins
Copy link
Collaborator

haoxins commented Jan 31, 2024

https://github.com/haoxins/nebula-go/blob/master/examples/session_pool_example/session_pool_example.go#L33

这个是你想要的功能么?还是更多的关注是内部实现? 😂

@QingZ11 QingZ11 added the type/question Type: question about the product label Feb 1, 2024
@AntarcticPresident
Copy link
Author

AntarcticPresident commented Feb 2, 2024

https://github.com/haoxins/nebula-go/blob/master/examples/session_pool_example/session_pool_example.go#L33

这个是你想要的功能么?还是更多的关注是内部实现? 😂

都有吧。
你这个例子我看了,并不能满足需求,所以又去看的内部实现。

我的需求:
我能够自助获取点或者边的各项数据,例如点,我能拿到都有什么tag,tag上的属性值;边的话,我能拿到谁到谁。
现在发布的功能,以及这个例子,都是输出字符串,我得自己想办法提取信息(还挺难的)。

然后我看了内部实现,就发现这地方。数据输出的逻辑里面,定义了一个Value,这个Value的属性就上面一堆,你是什么类型的数据,就存到对应的字段。等到输出的时候,写了一大串if else。不够优雅,所以,就想问问这么设计的初衷是啥?

顺便问下,在value_wrapper里面加上这个方法成不?

func (valWrap ValueWrapper) GetValue() *nebula.Value {
	return valWrap.value
}

虽然用起来很麻烦,但起码有个口子能拿到结构化数据,而不是字符串

@nidu-china
Copy link

我是这样转的,还是踩了一个坑,value.asNull()返回的是0(数据库schema是字符串),我干脆返回nil了
func convertValue(value *nebula_go.ValueWrapper) (interface{}, error) {
if value.IsString() {
return value.AsString()
} else if value.IsInt() {
return value.AsInt()
} else if value.IsBool() {
return value.AsBool()
} else if value.IsFloat() {
return value.AsFloat()
} else if value.IsDate() {
return value.AsDate()
} else if value.IsTime() {
return value.AsTime()
} else if value.IsDateTime() {
return value.AsDateTime()
} else if value.IsDuration() {
return value.AsDuration()
} else if value.IsVertex() {
return value.AsNode()
} else if value.IsEdge() {
return value.AsRelationship()
} else if value.IsPath() {
return value.AsPath()
} else if value.IsList() {
return value.AsList()
} else if value.IsSet() {
return value.AsList()
} else if value.IsMap() {
return value.AsMap()
} else if value.IsGeography(){
return value.AsGeography()
} else if value.IsNull(){
return nil, nil
} else {
return nil, errors.New("nebula query cannot convert data type")
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/question Type: question about the product
Projects
None yet
Development

No branches or pull requests

4 participants