Skip to content

NULL text, boolean and blob fields returned initialized to zero value by SliceMap() #1248

@petr-stratoscale

Description

@petr-stratoscale

Cassandra: 3.11
Gocql: master (70385f8)
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<frozen<map<text, text>>> | map<text, frozen<map<text, text>>> | 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<text, frozen<map<text, text>>> (map[string]map[string]string): map[]
set ([][]uint8): []
decimal (*inf.Dec): <nil>
list<frozen<map<text, text>>> ([]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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions