gocqltable
gocqltable copied to clipboard
UnMarshalling of collection types is not supported?
UPDATE - looks like collections of UDT-s are not supported, as I was able to get it working with list
I have a schema defined like this (omitted some fields for simplicity):
CREATE TYPE IF NOT EXISTS firewire.address (
addressline text,
city text,
state text,
zipcode text
);
CREATE TABLE IF NOT EXISTS firewire.card_by_customer (
identitykey text,
firstname text static,
lastname text static,
createdate timestamp,
addresses map<text, frozen<address>> static,
accountid text,
// additional fields
. . .
PRIMARY KEY (identitykey, accountid)
) WITH CLUSTERING ORDER BY (accountid ASC);
And appropriate Golang structs defined as:
type CardByCustomer struct {
IdentityKey string 'cql:"identitykey"'
FirstName string 'cql:"firstname"'
LastName string 'cql:"lastname"'
CreateDate time.Time 'cql:"createdate"'
Addresses map[string]Address 'cql:"addresses"'
AccountID string 'cql:"accountid"'
// additional fields
. . .
}
type Address struct {
AddressLine string cql:"addressline"'
City string 'cql:"city"'
State string 'cql:"state"'
ZIPCode string 'cql:"zipcode"'
}
Code to initialize gocql and gocqltable:
// Generic initialization of gocql
cluster := gocql.NewCluster(hosts...)
cluster.Keyspace = keyspaceName
cluster.Consistency = gocql.Quorum
session, err := cluster.CreateSession()
if err != nil {
log.Fatalln("Unable to open up a session with the Cassandra database (err=" + err.Error() + ")")
}
defer session.Close()
// Tell gocqltable to use this session object as the default for new objects
gocqltable.SetDefaultSession(session)
// Set the current keyspace
keyspace = gocqltable.NewKeyspace(keyspaceName)`
Creating records into Cassandra works just fine:
newEntry := CardByCustomer{
IdentityKey: identityKey,
FirstName: "Isaak",
. . .
}
accountTable := EntityTable{
recipes.CRUD{ // EXAMPLE
keyspace.NewTable(
"card_by_customer", // The table name
[]string{"identitykey"}, // Row keys
nil, // Range keys
CardByCustomer{}, // We pass an instance of the CardByCustomer struct that will be used as a type template during fetches.
),
},
}
err := accountTable.Insert(newEntry)
if err != nil {
log.Fatalln(err)
}
But then I am trying retrieve single record or all records I am getting this:
Retrieving all records
panic: reflect.Set: value of type map[string]map[string]interface {} is not assignable to type map[string]main.Address
goroutine 85 [running]:
panic(0x22f440, 0xc42016d6b0)
/usr/local/go/src/runtime/panic.go:500 +0x1a1
reflect.Value.assignTo(0xc420174cc0, 0xc42017ed20, 0x15, 0x283a59, 0xb, 0x240080, 0x0, 0xc42004fd78, 0xc420174cc0, 0xc42017ed20)
/usr/local/go/src/reflect/value.go:2163 +0x35c
reflect.Value.Set(0x240080, 0xc420184f00, 0x195, 0xc420174cc0, 0xc42017ed20, 0x15)
/usr/local/go/src/reflect/value.go:1333 +0xa4
github.com/kristoiv/gocqltable/reflect.MapToStruct(0xc42004fd78, 0x225040, 0xc420184ea0, 0x225040, 0xc420184ea0)
/Users/ggevorgyan/git/go/src/github.com/kristoiv/gocqltable/reflect/reflect.go:50 +0x31a
github.com/kristoiv/gocqltable.(*Iterator).Next(0xc42016f280, 0xc4200198d0, 0xdef75)
/Users/ggevorgyan/git/go/src/github.com/kristoiv/gocqltable/query.go:58 +0x160
github.com/kristoiv/gocqltable.(*Iterator).Range.func1(0xc42016f280, 0xc420174c00, 0xc420174c60)
/Users/ggevorgyan/git/go/src/github.com/kristoiv/gocqltable/query.go:69 +0x40
created by github.com/kristoiv/gocqltable.(*Iterator).Range
/Users/ggevorgyan/git/go/src/github.com/kristoiv/gocqltable/query.go:81 +0xac
I have tried to change my model using different approaches, but I need the built-in collection types, otherwise the model does not reflect what I need this for.
Thanks in advance