scylladb/gocqlx

Issue with CAS operations

Closed this issue · 6 comments

Hi,
I'm trying to use CAS features offered by gocqlx.
But I'm having an issue:

  • If I use Exec *Queryx.ExecCASRelease(), I always receive the value APPLIED=FALSE, even if the query has been applied.
  • If I use Exec *Queryx.GetCASRelease(dest), I always receive the value APPLIED=FALSE and moreover nothing is returned in Dest.

Here my example:
appl, err := cassandra.NamedExecCASStmtStruct(ctx, ADDCASSANDRAENTRYCAS, cData, &cData2)

ADDCASSANDRAENTRYCAS = fmt.Sprintf(INSERT INTO %s (id, name) VALUES (:id, :name) IF NOT EXISTS;, CassandraTableName)

`
func (c *Cassandra) NamedExecCASStmtStruct(ctx context.Context, query string, args interface{}, dest interface{}) (bool, error) {

logger.Infof("Executing query: %s - args: %s", query, args)
q, n, err := gocqlx.CompileNamedQueryString(query)
if err != nil {
	logger.Errorf("Error during creation of query %s. Args %s. Err: %s", query, args, err)
	return false, err
}
    appl, err := c.session.ContextQuery(ctx, q, n).BindStruct(args).GetCASRelease(dest)
if err != nil {
	logger.Errorf("Error executing cassandra statement: %s. Args %s. Err: %s", query, args, err)
	return false, err
}
return appl, nil

`

The query application is ok, in fact it inserts the data only if it does not exist, but it seems that query results are not correctly retrieved.

I also tried as explained in example_test.go but it seems to not work.
Can you please help me? Am I missing something?
Using gocql.MapScanCas it all works, but I would prefer to use query binding with gocqlx.

What DB are you using.

Hi! I'm using Cassandra 3.11

This does not work with Cassandra because it includes the [applied] column in metadata and the query skips metadata by default. To work around this you can call NoSkipMetadata() on your query before execution and it should work as desired.

You can read more here and in the two referenced issues.

Thanks @kevinbarbour, just tried and it perfectly works!
If you agree we can close the issue.

Great, glad that worked for you!

@kevinbarbour let's document that.