-
Notifications
You must be signed in to change notification settings - Fork 623
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
CASSGO-36 Could MapScan() get nil instead of zero value for null value? #1699
Comments
Hi!
We can't change the behavior of There is no easy way to populate map where null is mapped to nil interface with with the current API, but it is possible. By the way, for query building (and mapping values to structs if you have use case for that) you might find https://github.com/scylladb/gocqlx useful. |
Rather than changing the Your loop would instead look something like: for {
rowData, err := iter.RowData()
if err != nil {
return nil, err
}
m := make(map[string]interface{}, len(columns))
values := make([]interface{}, len(columns))
for i, v := range rowData.Values {
m[rowData.Columns[i]] = v
values[i] = reflect.ValueOf(v).Addr().Interface()
}
if !iter.Scan(values...) {
break
}
// Handle NaN values
for key, value := range m {
if f, ok := value.(*float64); ok && f != nil && math.IsNaN(*f) {
m[key] = "NaN"
}
}
results = append(results, m)
} You could even deference the values in the map after |
Hi,
I am new to using Gocql, and I'm currently trying to write a reusable function for selecting data. I want the function to return the query result dynamically. However, when using MapScan, null values are being converted to zero, which is causing confusion for me in distinguishing between zero and null. I have reviewed previous issues and documentation but haven't found a similar solution. Could you please provide some suggestions?
Please answer these questions before submitting your issue. Thanks!
What version of Cassandra are you using?
4.1.0
What version of Gocql are you using?
v1.3.2
What version of Go are you using?
v1.20
What did you do?
What did you expect to see?
The null value in the m variable is distinguished from the zero value.
What did you see instead?
null is converted to zero values.
If you are having connectivity related issues please share the following additional information
Describe your Cassandra cluster
please provide the following information
nodetool status
SELECT peer, rpc_address FROM system.peers
gocql_debug
tag and post the outputThe text was updated successfully, but these errors were encountered: