2016-02-25 43 views
1

我無法弄清楚如果我有log_date(格式:2015-02-20 00:00:00 + 0000)列的非常大的表中的最舊和最新的行表。獲取表格的最舊和最新的行

我曾嘗試以下變化:

select account_id, log_date FROM my.table where log_date<'2013-03-20 00:00' limit 1 allow filtering; 
ReadTimeout: code=1200 [Coordinator node timed out waiting for replica nodes' responses] message="Operation timed out - received only 0 responses." info={'received_responses': 0, 'required_responses': 1, 'consistency': 'ONE'} 

select account_id, log_date from my.table order by log_date desc limit 1; 
InvalidRequest: code=2200 [Invalid query] message="ORDER BY is only supported when the partition key is restricted by an EQ or an IN." 

我怎樣才能得到最古老和龐大的表的最新行?

回答

1

如果您的列族的主鍵是(account_id),那麼通過log_date命令獲取最新的帳戶根本不起作用。

在CQL中,您只能通過在指定的分區鍵下對集羣密鑰進行排序。所以如果你的主鍵是(account_id,logdate),意思是account_id是分區鍵,log_date是集羣鍵。你只能在你的審覈規定指定ACCOUNT_ID時做的順序:

select * from riskless.account_data_pg where account_id = 1 order by log_date; 

總之,如果你希望你的列族來存儲時間序列數據,你需要仔細設計你的主鍵,主鍵決定了設計如何&你可以點餐。

另一種選擇是與卡桑德拉,在列族索引行,與您可以使用Solr或Elasticsearch搜索API翻譯記憶庫一起使用的Solr或Elasticsearch。