2014-01-07 56 views

回答

20

null领域不存在卡桑德拉。

您可能会想到CQL数据模型,它隐藏了某些实现细节以便拥有更易于理解的数据模型。卡桑德拉是稀疏的,这意味着只有实际使用的数据才被存储。您可以通过将一些测试数据通过CQL添加到Cassandra来将其可视化。

cqlsh> CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1 } ; 
cqlsh> use test ; 
cqlsh:test> CREATE TABLE foo (name text, age int, pet text, primary key (name)) ; 
cqlsh:test> insert into foo (name, age, pet) values ('yves', 81, 'german shepherd') ; 
cqlsh:test> insert into foo (name, pet) values ('coco', 'ferret') ; 

cqlsh:test> SELECT * FROM foo ; 

name | age | pet 
-----+-----+------------------ 
coco | null | ferret 
yves | 81 | german shepherd 

所以,即使它似乎有一个空值,实际值是不存在的 - CQL是向你们表示null,因为这更有意义,直观。

如果你看看从节俭方面的表格,你可以看到该表格不包含coco的年龄。

$ bin/cassandra-cli 
[[email protected]] use test; 
[[email protected]] list foo; 
RowKey: coco 
=> (name=, value=, timestamp=1389137986090000) 
=> (name=age, value=00000083, timestamp=1389137986090000) 
------------------- 
RowKey: yves 
=> (name=, value=, timestamp=1389137973402000) 
=> (name=age, value=00000051, timestamp=1389137973402000) 
=> (name=pet, value=6765726d616e207368657068657264, timestamp=1389137973402000) 

在这里,你可以清楚地看到,yves有两列:agepet,而coco只有一个:age

3

据我所知,你不能用NULL做到这一点。

作为替代方案,你可以使用不同的空值,例如空字符串:''

在这种情况下,你可以用这样一个空的作者选择的所有书籍(假设笔者列适当索引) :除非你自己添加这些

SELECT * FROM book WHERE author = ''; 
-3

如果你在Cassandra上使用Solr,但不知道直接Cassandra查询,这将起作用。

SELECT * FROM BOOK WHERE solr_query = ' -author : [* TO *] ' 
相关问题