Skip to content
Related Articles
Open in App
Not now

Related Articles

Partitioners with the TOKEN function in Cassandra

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 02 Dec, 2019
Improve Article
Save Article

In this article we will discuss how TOKEN function works in Cassandra using partitioners. There are 3 different type of partitioners that is supported by Cassandra Query Language.

Partitioners in CQL :

1. Murmur3partitioner 
2. RandomPartitioner
3. ByteOrderedPartitioner 

Let’s discuss one by one.

  1. Murmur3partitioner :
    It is default partitioner in Cassandra 3.0. If we used TOKEN function then it distribute data over cluster based on MurmurHash hash values. It is also useful to provide good performance and fast hashing.

  2. RandomPartitioner :
    It is default partitioner prior to Cassandra 1.2. It distribute data over across cluster by using MD5 hash values.

  3. ByteOrderedPartitioner :
    In Cassandra Query Language Byte Ordered partitioner data distribute over cluster based on data lexically by key bytes.It is used for ordered partitioning in Cassandra Query Language. It is also useful for backward compatibility.

Below given table is useful to understand, let’s have a look.

Partitioner NameData TypeDistribute data over cluster based on
Murmur3PartitionerbigintMurmurHash hash values
RandomPartitionervarintMD5 hash values
ByteOrderedPartitionerblobdata lexically by key bytes

Let’s understand the TOKEN function using partitioning key and return query based on Token partitioning key. first we are creating table.

Id int,
Name text,
Address text,

To insert data into table User_info used the following CQL Query:

INSERT INTO User_info (Id, Name, Address) 
       VALUES (301, 'Ashish', 'Delhi');
INSERT INTO User_info (Id, Name, Address) 
       VALUES (302, 'Rana', 'Mumbai');
INSERT INTO User_info (Id, Name, Address) 
       VALUES (303, 'Abi', 'Noida');
INSERT INTO User_info (Id, Name, Address) 
       VALUES (302, 'me', 'Noida'); 

Let’s have a look.

FROM User_info; 


By using TOKEN function.

FROM User_info; 

Reference for practitioners, and Reference for TOKEN function.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!