Help Needed with Sample Method in Gremlin-Go

Hello Apache TinkerPop Community, I'm currently working on a Go project using the Apache TinkerPop for graph operations, and I've encountered a problem I'm hoping someone could assist with. I'm trying to retrieve a specified number of random users from my graph with the following function:
func (r userRepository) GetNRandomUsers(qty int, ignoreIds []string, microverseId string) ([]string, error) {
users := r.g.Users()
if microverseId != "" {
users.Filter(__.UserInMultiverse(microverseId))
}
if len(ignoreIds) > 0 {
users.Not(__.HasId(ignoreIds))
}
queryResponse, err := users.Id().Sample(qty).Next()
if err != nil {
return nil, err
}
return queryResponse.GetInterface().([]string), nil
}
func (r userRepository) GetNRandomUsers(qty int, ignoreIds []string, microverseId string) ([]string, error) {
users := r.g.Users()
if microverseId != "" {
users.Filter(__.UserInMultiverse(microverseId))
}
if len(ignoreIds) > 0 {
users.Not(__.HasId(ignoreIds))
}
queryResponse, err := users.Id().Sample(qty).Next()
if err != nil {
return nil, err
}
return queryResponse.GetInterface().([]string), nil
}
However, I keep encountering an error on the line queryResponse, err := users.Id().Sample(qty).Next() which is using the .Sample(qty) method. The error message I'm receiving is: "Error occurred during operation gremlinServerWSProtocol.responseHandler(): 'E0502: error in read loop, error message '{code:87 message:{"requestId":"4ce6dc05-6fd1-49d7-b5d5-eea85bf7db2a","code":"InternalFailureException","detailedMessage":"null: .sample(Long)"} attributes:map[]}'. statusCode: 87'" Regrettably, I couldn't find any additional information in the documentation or on other channels which could provide me with a solution to this issue. If anyone could provide insights on what I might be doing wrong or suggest potential fixes, it would be greatly appreciated. Moreover, if you need more context or further clarification, please let me know and I'll be more than happy to provide it. Best regards.
4 Replies
ColeGreer
ColeGreer2y ago
How big is qty? The issue appears to be that qty is being mapped to a Java long. If qty can safely be stored in a uint32, your issue should be resolved by changing Sample(qty) to Sample(int32(qty))
pedrobalbino
pedrobalbinoOP2y ago
Hello, it worked. Thank you very much !!! What is the problem with int 64 as quantity on the sample method ?
Yang Xia
Yang Xia2y ago
I believe it has to do with typing in Go vs Java, where Go int can be 32 or 64 bit, so it's serialized as a Java long to the server to account for the widest possibility, but since the sample method only takes integers, it will throw a type related error. To make sure you send Java integers you have to specifically use int32 in Go.
Jim Idle
Jim Idle2y ago
I will open another question about this, because all my uint32 values used in MergeV property maps are being inserted as long, despite them being uint32. int32 uses integer
Want results from more Discord servers?
Add your server