apache / apache/cassandra-gocql-driver
NULL text, boolean and blob fields returned initialized to zero value by SliceMap()
- Dominant language
- Go
- Stars
- 2.7k
- Forks
- 658
- PR merge metrics
- No merged PRs in 30d
Description
Cassandra: 3.11
Gocql: master (70385f88b28b43805bd83d212169ab2d38810b15)
Go: go version go1.10.5 linux/amd64
Hello.
I have a Cassandra table with various column types some of which holding a null value:
id | blob | boolean | decimal | list>> | map>> | set | set | set | text
----+------+---------+---------+-------------------------------+------------------------------------+-----------+--------------+-----------+------
0 | null | null | null | null | null | null | null | null | null
I query the table with "SliceMap()" like this:
```
package main
import (
"fmt"
"github.com/gocql/gocql"
)
func main() {
cluster := gocql.NewCluster("10.42.188.4")
cluster.Consistency = gocql.One
cluster.PoolConfig.HostSelectionPolicy = gocql.RoundRobinHostPolicy()
cluster.Compressor = gocql.SnappyCompressor{}
s, err := cluster.CreateSession()
if err != nil {
panic(fmt.Sprintf("%s\n", err.Error()))
} else {
fmt.Println("Connection established.")
}
q := s.Query(`SELECT * FROM "testks"."types"`)
rows, ok := q.Iter().SliceMap()
if ok != nil {
panic(fmt.Sprintf("%s\n", ok.Error()))
}
for i, row := range rows {
fmt.Printf("Data for row #%d\n", i)
for col, val := range row {
fmt.Printf("%s (%T): %s ", col, val, val)
}
fmt.Printf("\n")
}
s.Close()
}
```
And get the following output:
Connection established.
Data for row #0
map>> (map[string]map[string]string): map[]
set ([][]uint8): []
decimal (*inf.Dec): \
list>> ([]map[string]string): []
boolean (bool): %!s(bool=false)
set ([]*inf.Dec): []
set ([]string): []
text (string):
id (*inf.Dec): 0
blob ([]uint8):
Only the 'decimal' value is set to 'nil'. All other values seem to have 'zero' value for their type. Now, I get that empty set, list and map types are represented as null, but I would expect 'nil' values text, boolean and blob columns. The applications need to be able to distinguish between a value and absence of value in the fields. Clearly a blank string, false or 0x [textAsBlob('')] are not the same as never-set values.
Any ideas?
Thanks.
Contributor guide
Research direction
Reproduce the report against Cassandra 3.11 using the shown SELECT and the Iter().SliceMap() entry point, then trace how NULL columns are decoded into the returned map. Done means NULL text, boolean, and blob values remain distinguishable from their zero values while the reported collection behavior is accounted for.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cassandra, go
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100