在Cassandra中创建了一个表,其中主键基于两列(groupname,type).当我试图在组名和类型相同的情况下插入多于一行时,那么在这种情况下它不会存储多个行,后续写入组名和类型中的相同…那么最新的写入正在替换以前的类似写道.为什么Cassandra会以这种方式替换而不是写入每一行插入?
写1
cqlsh:resto> insert into restmaster (rest_id,type,rname,groupname,address,city,country)values(blobAsUuid(timeuuidAsBlob(now())),'SportsBar','SportsDen','VK Group','Majestic','Bangalore','India');
写2
insert into restmaster (rest_id,'Sports Spot','Bandra','Mumbai','India');
写3
cqlsh:resto> insert into restmaster (rest_id,'Cricket Heaven ','Connaught Place','New Delhi','India');
我期待的结果(检查第4,5,6行)
groupname | type | rname ----------------+------------+----------------- none | Udipi | Gayatri Bhavan none | dinein | Blue Diamond VK Group | FoodCourt | FoodLion VK Group | SportsBar | Sports Den VK Group | SportsBar | Sports Spot VK Group | SportsBar | Cricket Heaven Viceroy Group | Vegetarian | Palace Heights Mainland Group | Chinese | MainLand China JSP Group | FoodCourt | Nautanki Ohris | FoodCourt | Ohris
但这是实际结果(写3已取代之前的2个插入[第4,5行])
cqlsh:resto> select groupname,rname From restmaster; groupname | type | rname ----------------+------------+----------------- none | Udipi | Gayatri Bhavan none | dinein | Blue Diamond VK Group | FoodCourt | FoodLion VK Group | SportsBar | Cricket Heaven Viceroy Group | Vegetarian | Palace Heights Mainland Group | Chinese | MainLand China JSP Group | FoodCourt | Nautanki Ohris | FoodCourt | Ohris cqlsh:resto> describe table restmaster; CREATE TABLE restmaster ( groupname text,type text,address text,city text,country text,rest_id uuid,rname text,PRIMARY KEY ((groupname),type) ) WITH bloom_filter_fp_chance=0.010000 AND caching='KEYS_ONLY' AND comment='' AND dclocal_read_repair_chance=0.100000 AND gc_grace_seconds=864000 AND index_interval=128 AND read_repair_chance=0.000000 AND replicate_on_write='true' AND populate_io_cache_on_flush='false' AND default_time_to_live=0 AND speculative_retry='99.0PERCENTILE' AND memtable_flush_period_in_ms=0 AND compaction={'class': 'SizeTieredCompactionStrategy'} AND compression={'sstable_compression': 'LZ4Compressor'};
对Cassandra数据库的所有插入实际上都是插入/更新操作,并且每个唯一定义的主键只能存在一组非键值.这意味着您不能为一个主键提供多组值,并且您只能看到最后一次写入.
原文链接:https://www.f2er.com/nosql/203270.html更多信息:
http://www.datastax.com/documentation/cql/3.1/cql/cql_intro_c.html
更新:数据模型
如果你使用了像键
Primary Key ((groupname),rname)
只要您拥有独特的餐厅名称,您就能获得您期望的结果.但你真正要问的是“我想对这些数据进行哪些查询?”所有Cassandra表都应该基于满足一类查询.我上面写的关键字基本上说“这个表是为了快速查找特定组中的所有餐馆而构建的,我将使用的唯一条件将是类型和餐馆名称”
您可以使用该架构执行的示例查询
SELECT * FROM restmaster WHERE groupname = 'Lettuce Entertain You' ; SELECT * FROM restmaster WHERE groupname = 'Lettuce Entertain You' and type = 'Formal' ; SELECT * FROM restmaster WHERE groupname = 'Lettuce Entertain You' and type = 'Formal' and rname > 'C' and rname < 'Y' ;