How Can I Use the Counter Column?
The counter column of GeminiDB Cassandra API is used to keep track of metrics like page views, messages, and other measurable statistics.
Supported Operations
In open-source Cassandra, the counter column stores values as 64-bit signed integers which can only be incremented or decremented. In addition, GeminiDB Cassandra API provides the following functions:
- You can set values in the counter column.
- You can delete counters by column, row, range, and partition.
- Write performance of a table with counters will deteriorate if they are deleted by range and partition, so these functions are disabled by default.
- To delete values by range and partition, set counter_multiline_deletion_enabled to true.
Constraints
- A counter cannot be defined as a primary key.
- If a counter is used, all of the columns other than primary keys must be counters.
- TTL cannot be set for counters.
- INSERT cannot be executed for counters, which can only be inserted through UPDATE statements.
Example
CREATE TABLE t0(pk int, ck int, v1 counter, v2 counter, v3 counter, PRIMARY KEY(pk, ck)); # Writes counter columns. Sets values for v1, increments values for v2, and decrements values for v3. UPDATE t0 SET v1 = 1, v2 = v2 + 1, v3 = v3 - 1 WHERE pk = 1 AND ck = 1; # Deletes counters by column. DELETE v1 FROM t0 where pk = 1 AND ck = 1; # Deletes counters by row. DELETE FROM t0 where pk = 1 AND ck = 1;
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot