如何使用CQL搜索具有空/空字段的记录? [英] How Can I Search for Records That Have A Null/Empty Field Using CQL?

查看:1067
本文介绍了如何使用CQL搜索具有空/空字段的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写查询以查找表中具有空/空字段的所有记录?我试过尝试下面的查询,但它不返回任何东西。

How can I write a query to find all records in a table that have a null/empty field? I tried tried the query below, but it doesn't return anything.

SELECT * FROM book WHERE author = 'null';


推荐答案

null 字段不存在于Cassandra中,除非您自己添加。

null fields don't exist in Cassandra unless you add them yourself.

您可能正在考虑CQL数据模型,隐藏某些实现细节,以便一个更容易理解的数据模型。 Cassandra是稀疏的,这意味着只有使用的数据实际上被存储。

You might be thinking of the CQL data model, which hides certain implementation details in order to have a more understandable data model. Cassandra is sparse, which means that only data that is used is actually stored. You can visualize this by adding in some test data to Cassandra through CQL.

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 ,因为这样更直观,更有意义。

So even it appears that there is a null value, the actual value is nonexistent -- CQL is showing you a null because this makes more sense, intuitively.

如果你看一看表Thrift侧,你可以看到表中没有这样的值 coco 的年龄。

If you take a look at the table from the Thrift side, you can see that the table contains no such value for coco's age.

$ bin/cassandra-cli
[default@unknown] use test;
[default@test] 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)

code> yves 有两列: age pet ,而 coco 只有一个: age

Here, you can clearly see that yves has two columns: age and pet, while coco only has one: age.

这篇关于如何使用CQL搜索具有空/空字段的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆