如何在CQL3中为复合键列提供空列值 [英] How can I have null column value for a composite key column in CQL3

查看:83
本文介绍了如何在CQL3中为复合键列提供空列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这听起来很愚蠢,因为SQL的复合主键中没有空值。但是只是想确认我们是否可以在CQL3中使用相同的代码?

因此,我们有一个像这样的表来存储宽行:

This may sound silly as there are no null values in SQL's composite primary key. But just want to confirm if we can have the same in CQL3?
So, we have a table like this to store wide rows:

CREATE TABLE keyspace12.colFamily1 
(
  id text, 
  colname text,
  colvalue blob,
  PRIMARY KEY (id,colname, colvalue)
) WITH COMPACT STORAGE

在某些情况下,colname为null。我可以那样做吗?如果是,那怎么办?如果为否,那么存储宽列行的方法是什么,在该行中我们可以在cassandra的复合列的第一部分中添加一些null(根据Thrift的约定)?

And we have some cases where colname is null. Can I do that? If yes, then how? If NO, then what are the ways to store wide columns rows where we can have some null in first part of composite column of cassandra(As per Thrift's convention)?

相关问题是:
CQL3和数百万列复合关键用例 Cassandra-如何使用cqlsh创建复合列名(不是键)

推荐答案

说我有一个列家庭

CREATE TABLE cnt_test (time_slot text , comp1 text, comp2 text, field1 counter, field2 counter, PRIMARY KEY(time_slot,comp1, comp2));

现在我要在其中插入一些数据

Now i am trying to insert some data in it

UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='' AND comp2='ABC';
UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='' AND comp2='ABC';
UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='' AND comp2='ABC';
UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='' AND comp2='XYZ';
UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='PQR' AND comp2='';

如上所示,我在复合键部分插入了一些空值,而不是 null ,而是放置空白字符。

As you can see in the above statements i have inserted some empty values in the compound key part, just instead of null i am putting the blank character.

我什至可以在同一查询上

I can even query on the same

 SELECT * FROM cnt_test WHERE time_slot='20130924' AND comp1='' AND comp2='ABC';

 time_slot | comp1 | comp2 | field1 | field2
-----------+-------+-------+--------+--------
  20130924 |       |   ABC |      4 |      8

(1 rows)

SELECT * FROM cnt_test WHERE time_slot='20130924' AND comp1='PQR' AND comp2='';

 time_slot | comp1 | comp2 | field1 | field2
-----------+-------+-------+--------+--------
  20130924 |   PQR |       |      1 |      2

(1 rows)

所以总结每件事只需替换空列值,空列,即'' c

So to summarize every thing just replace the null column value with empty column i.e ''

这篇关于如何在CQL3中为复合键列提供空列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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