Search code examples
cassandracassandra-2.0cassandra-2.1cassandra-3.0spring-data-cassandra

How to Select Nth Row in Cassandra DB Table


i need to select 'N'th row from cassandra table based on the particular number i'm getting from my logic. i.e: if logic output is 23 means, i need to get 23rd row details. since there is no auto increment in cassandra,i cant able to go with ID key match. In SQL they getting it using OFFSET and LIMIT. i dont know how to achieve this feet in Cassandra. Can we achieve this by using any UDF concept??? Someone reply me the solution.Thanks in advance.

Table Schema :

CREATE TABLE new_card ( 
    customer_id bigint, 
    card_number text, 
    active tinyint, 
    auto_pay int, 
    available_credit_limit double, 
    average_card_spend_half_yearly double, 
    average_card_spend_monthly double, 
    average_card_spend_quarterly double, 
    average_card_spend_yearly double, 
    avg_half_yearly_spend_mcc double,
    PRIMARY KEY (customer_id, card_number) 
);

Solution

  • If you are using Java driver, refer Paging

    Note, Cassandra does not support direct offsets, pages are read sequentially. If you have to use offsets to be used in your queries, you might want to revisit your data model. You could have created a composite partition key including the row number as an additional column on top of you existing partition key column.