Domanda

voglio usare il seguente codice per l'aggiornamento di un campo ...

@@db.execute("UPDATE user_count SET counters = counters + #{val} WHERE cid = 1 ")

La prima volta che ho provato, che ho ottenuto il seguente venga meno;
CassandraCQL :: Errore :: InvalidRequestException: operazione non valida per i non commutativa columnfamily USER_COUNT
Ho scoperto che devo usare il contatore di confronto, ma i cant trovare come posso messa a punto che con la gemma cassandra-CQL ... Qualcuno sa come posso ottenere questo al lavoro? sotto c'è il mio codice che non funziona ...

@@db.execute("CREATE COLUMNFAMILY user_count(cid varchar PRIMARY KEY, counters counter) with comparator = counter " )
@@db.execute("INSERT INTO user_count (cid, counters) VALUES (?,?)", 1, 0)
È stato utile?

Soluzione

You need to set default_validation=CounterColumnType instead of comparator.

@@db.execute("CREATE COLUMNFAMILY user_count(cid varchar PRIMARY KEY, counters counter) with default_validation=CounterColumnType")
@@db.execute("update user_count set counters = counters + 1 where cid = 1")

You must use 'update' to change the counter value, there is no insert syntax for counters (in CQL update and insert do the same thing so you can create new rows using update).

Currently you cannot have counters and non-counters in the same column family (from the wiki: "A column family either contains only counters, or no counters at all.")

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top