A tuple data type is useful when we need to accommodate many fields we can accommodate maximum 32768 fields. let’s understand tuple data type with an example.
Here, first we are going to create table for example Emp_data is a table name and E_id is primary key of table and E_data field is tuple type in below given table. let’s have a look.
CREATE TABLE Emp_data ( E_id int PRIMARY KEY, E_data tuple<int, text, int> );
Now, we are going to insert some data in Emp_data table by using following CQL query.
INSERT INTO Emp_data (E_id, E_data) VALUES(501, (1, 'ok', 200)); INSERT INTO Emp_data (E_id, E_data) VALUES(502, (2, 'test', 500)); INSERT INTO Emp_data (E_id, E_data) VALUES(503, (3, 'final', 400));
Now, to see the output Emp_data table used the following CQL query.
SELECT * FROM Emp_data;
Now, to apply filter we are going to create indexing on E_data field which is tuple data type.
CREATE INDEX on Emp_data (E_data);
We can used tuple type field in where clause to filter data.
SELECT * FROM Emp_data WHERE E_data = (2, 'test', 500);
Tuple type can be used for nested purpose also. Again we are going to create a new table for nested purpose.so, let’s have a look.
CREATE TABLE nested_Emp_data ( E_id int PRIMARY KEY, E_data tuple<int, tuple< text, int>> );
Now, insert data into nested_Emp_data tableby using following CQL query.
INSERT INTO nested_Emp_data (E_id, E_data) VALUES (101, (1, ('Ashish', 200))); INSERT INTO nested_Emp_data (E_id, E_data) VALUES (102, (2, ('rana', 500))); INSERT INTO nested_Emp_data (E_id, E_data) VALUES (103, (3, ('data', 800)));
To see the output used the following CQL query.
select * from nested_Emp_data;
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Static type using batch in Cassandra
- Overview of User Defined Type (UDT) in Cassandra
- Collection Data Type in Apache Cassandra
- Pre-defined data type in Apache Cassandra
- Static type in Cassandra
- Altering a table to add a collection data type in Cassandra
- Updating MAP collection data type in Cassandra
- Counter Type in Cassandra
- Role of keys in Cassandra
- High Availability Mechanism in Cassandra
- Apache Cassandra tools
- Blob conversion function in Cassandra
- Designing models in Cassandra
- Introduction to Apache Cassandra
- Apache Cassandra (NOSQL database)
- Architecture of Apache Cassandra
- Overview of Data modeling in Apache Cassandra
- Concept of indexing in Apache Cassandra
- Monitoring cluster in Cassandra
- Virtual machine installation for Cassandra CQL query
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.