RECOMMENDED PATHS
ArchitectLOGIN TO START THIS PATH
VIEW COURSES
0%
DS101: Introduction to Apache Cassandra™
0%
DS201: DataStax Enterprise 6 Foundations of Apache Cassandra™
0%
DS210: DataStax Enterprise 6 Operations with Apache Cassandra™
0%
DS220: DataStax Enterprise 6 Practical Application Data Modeling with Apache Cassandra™
DeveloperLOGIN TO START THIS PATH
VIEW COURSES
0%
DS101: Introduction to Apache Cassandra™
0%
DS201: DataStax Enterprise 6 Foundations of Apache Cassandra™
0%
DS220: DataStax Enterprise 6 Practical Application Data Modeling with Apache Cassandra™
Graph SpecialistLOGIN TO START THIS PATH
VIEW COURSES
0%
DS101: Introduction to Apache Cassandra™
0%
DS201: DataStax Enterprise 6 Foundations of Apache Cassandra™
0%
DS220: DataStax Enterprise 6 Practical Application Data Modeling with Apache Cassandra™
0%
DS330: DataStax Enterprise 6 Graph
UNIT CONTENTS
Unit Status
 
 
  Previous Unit: UDTs
Finish & Next Unit: UDFs And UDAs  

DSE Version: 6.0

Counters

Video

In this unit, we will be moving on to the counters data type. A counter is a data type where you can store a 64-bit signed integer that can be incremented or decremented. These could be useful, depending on your data model.

Transcript: 

Alright let’s move onto counters.  This is another data type that might come in handy as you are considering your data model design.  As we said before, this could potentially be another tool in your data model design tool box. So what is a counter?  Seems self-explanatory, huh? A counter is a data type where you can have a column that stores a 64 bit signed integer.  What else, what else...oh yes! They can be incremented and decremented and the values are changed using the CQL UPDATE command.   They need to have a specially dedicated table however, as the only thing allowed in a table with counters are the primary key columns, which can’t be counters and the counter column or columns.  Yup, you can have more than one counter column in your table.

Let’s take a look at a little example, shall we?  Let’s say we have own a ranch and we specialize in cows.  For whatever reason, we are particularly interested in how many moos each of our cows make.  We for that, we need some way to count up moos. So! We create a table called “moo_counts” and we have cow name, which is is also our primary key and the moo-count counter column.  So far so good. Now to add to our moo count, we will use UPDATE to update the moo_counts table presumably every time we hear a moo. In this example, we updated the moo-count to increment the value, whatever it happens to be, by 8 where the cow is named Betsy.  Got it?

Okay, some caveats you have to remember.  Cassandra is a distributed system. If you haven’t learned that by now, we’ve got bigger problems than counters here.  Seeing as it is a distributed system, replication can sometimes cause consistency errors in counter columns. Be aware that this can happen.  Also, you cannot insert or assign values. The default starting value of a counter is 0. Another thing, counters must be the ONLY non-primary key column or columns.  Counter are not idempotent. In DataStax Enterprise, you cannot use USING TIMESTAMP or USING TTLs to update counters. You must use the UPDATE command. And finally, counter columns cannot be indexed or deleted.

Okay!  I think that’s enough about counters to make you dangerous.  There is a small exercise you should do to enforce your understanding.

No write up.
No Exercises.
No FAQs.
No slides.
No resources.