根据类型" time"的列来检索行。在cassandra db

时间:2018-03-23 09:51:39

标签: cassandra

如何根据类型"时间"的列来检索行。在cassandra db。

我们尝试了查询

select * 
from payment_transactions_by_transactiondate
where transaction_time>='00:00:00' 
and transaction_time<='23:59:59'  
and transaction_date='2018-03-21'
allow filtering;

, 但它没有获取行(where transaction_time is a primary key)。

1 个答案:

答案 0 :(得分:0)

You can not do a range query on the primary key. It's because Cassandra distributes data on different node based on a primary key. Instead What you can do, is to make the transaction_time clustering key. See the difference between primary key and clustering key。从上面的查询中,您似乎需要特定日期的交易( transaction_date )。因此,要执行此查询,请使用 transaction_date 主键和 transaction_time 群集密钥。

例如:

create table payment_transactions_by_transactiondate( 
      ....
      ....
      .... 
      primary key (transaction_date, transaction_time)
);