0

I have some table in Cassandra employee_list (id int, name text, PRIMARY KEY (id)) . Supposing i want to add the names of employees to that table and i need unique integer IDs for every employee. Is there any way to add auto generated sequencial integer numbers in cassandra?

For example, i am just adding some name Jon Snow, and Cassandra attributes to that name number 1, for the next name Arya Stark number 2 and so on..

Thank you

P.S. I am familiar with UUID

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
Henrik
  • 159
  • 1
  • 15

1 Answers1

2

For what purposes do you need such functionality? For ordering, sorting? For ordering or sorting as a dirty solution you can do it during insertion in your code. But actually you have to define for yourself for what purpose do you need that and design it more carefully without need of auto increment.

It is hard to implement such things in Cassandra due to it's distributed nature. In SQL world thats easy cause you have one centralized server or even if you use sharding anyway SQL is centralized due to transactions at least. But having auto incremented id in Cassandra will lead to huge overhead of synchronization between nodes or/and to a centralized coordinator of that ids to avoid collisions. And as unique identifier you can use UUID which serves well for that purpose.

And may be this will help: How to create auto increment IDs in Cassandra

Stepan Pogosyan
  • 562
  • 1
  • 7
  • 15
  • Dear Stepan, thank you for comment. I think I will just find the maximum number of ID and for next data ID add 1. Մերսի :) – Henrik Oct 13 '17 at 12:26