使用时间戳对Map值进行cassandra范围查询

ki0zmccv  于 2021-06-14  发布在  Cassandra
关注(0)|答案(0)|浏览(149)

我在Cassandratable下面。

create table person( 
   id int PRIMARY KEY,  
   name text, 
   imp_dates map<text,timestamp>
 );

数据插入如下

insert into person(id,name,imp_dates) values(1,'one',{'birth':'1982-04-01','marriage':'2018-04-01'});
insert into person(id,name,imp_dates) values(2,'two',{'birth':'1980-04-01','marriage':'2010-04-01'});
insert into person(id,name,imp_dates) values(3,'three',{'birth':'1980-04-01','graduation':'2012-04-01'});

 id | name  | imp_dates
----+-------+-----------------------------------------------------------------------------------------------
  1 |   one |   {'birth': '1982-03-31 18:30:00.000000+0000', 'marriage': '2018-03-31 18:30:00.000000+0000'}
  2 |   two |   {'birth': '1980-03-31 18:30:00.000000+0000', 'marriage': '2010-03-31 18:30:00.000000+0000'}
  3 | three | {'birth': '1980-03-31 18:30:00.000000+0000', 'graduation': '2012-03-31 18:30:00.000000+0000'}

我有要求写查询如下。Map值列上的此必需范围。

select id,name,imp_dates from person where id =1 and imp_dates['birth'] < '2000-04-01';

我得到以下错误

Error from server: code=2200 [Invalid query] message="Only EQ relations are supported on map entries"

我能想到的可能解决办法是:
1) 将Map平面化为多列,然后使其成为主键的一部分。这将工作,但它不灵活,因为我可能不得不改变模式
2) 我可以创建另一个表person\u id\u by\u important\u dates来替换map,但是我失去了读取一致性,因为我必须从两个表中读取并加入自己。
我不希望在主键中包含imp\u dates(map)部分,因为每次插入新值时它都会创建新行。
感谢你的帮助。谢谢

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题