Can't update UDT using gocqlx

Hi so I have a usecase in which a user can create a secondary index on any table by calling an API. And I’m recording these indexes in a common table using map<text, frozen> where indexes is a User Defined Type:

CREATE TYPE indexes (
    local BOOLEAN,
    index_name TEXT,
    table_name TEXT,
    columns SET<TEXT>

When the API is called the secondary index is created. This part is working fine. But updating the row in the common tables is not. All the data in the UDT is stored as null:

 {'table_table1_20e24b85_d425_11e_int13_idx': {local: null, name: null, table_name: null, columns: null}}

Here’s my gocqlx code:

selectedTable.Indexes[indexName] = models.IndexModel{
	Local:     reqBody.Local,
	Name:      indexName,
	TableName: selectedTable.InternalName,
	Columns:   reqBody.Columns,

stmt, names = qb.Update("tables").Set("indexes").
	Where(qb.Eq("internal_name"), qb.Eq("name"), qb.Eq("description")).ToCql()
if err := config.GetScylla().Query(stmt, names).BindStruct(&selectedTable).ExecRelease(); err != nil {
	utils.HandleErrorResponse(c, err)

I hope the code is self-explanatory enough but all I’m doing is creating a map of string->indexes(UDT) to put in the common table and updating the common table with it.

Side note: why is the documentation on gocqlx so bad?

this question was answered in this github issue: Can’t update UDT using gocqlx · Issue #264 · scylladb/gocqlx · GitHub.
In short you have to add cql: struct tags to map specify the CQL field name to be mapped to a struct field.
Information about it can be found in gocql documentation: gocql/doc.go at 34fdeebefcbf183ed7f916f931aa0586fdaa1b40 · gocql/gocql · GitHub.

1 Like