本文介绍了迭代通过Cassandra宽行与CQL3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用CQL3引入一系列复合列?

How can I pull in a range of Composite columns with CQL3?

请考虑以下内容:

CREATE TABLE Stuff (
    a int,
    b text,
    c text,
    d text,
    PRIMARY KEY (a,b,c)
);

在Cassandra中,这有效地创建了一个带有整数行(值为a)和CompositeColumns由b和c的值和字符串'd'组成。当然,这一切都是由CQL3覆盖的,所以我们会认为我们正在插入到单个数据库行...但我离题。

In Cassandra what this effectively does is creates a ColumnFamily with integer rows (values of a) and with CompositeColumns composed of the values of b and c and the literal string 'd'. Of course this is all covered up by CQL3 so that we will think that we're inserting into individual database rows... but I digress.

并考虑以下输入集合:

INSERT INTO Stuff (a,b,c,d) VALUES (1,'A','P','whatever0');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'A','Q','whatever1');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'A','R','whatever2');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'A','S','whatever3');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'A','T','whatever4');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'B','P','whatever5');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'B','Q','whatever6');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'B','R','whatever7');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'B','S','whatever8');
INSERT INTO Stuff (a,b,c,d) VALUES (1,'B','T','whatever9');

在我目前的用例中,我想读取Stuff的所有值, n 值。我如何做到这一点?这是我目前使用 n = 4

In my current use case, I want to read all of the values of Stuff, n values at a time. How do I do this? Here's my current take using n=4:

SELECT * FROM Stuff WHERE a=1 LIMIT 4;

和预期一样,我得到:

 a | b | c | d
---+---+---+-----------
 1 | A | P | whatever0
 1 | A | Q | whatever1
 1 | A | R | whatever2
 1 | A | S | whatever3

我遇到的麻烦是我如何获得下4个?这是我的尝试:

The trouble that I run into is how do I get the next 4? Here is my attempt:

SELECT * FROM Stuff WHERE a=1 AND b='A' AND c>'S' LIMIT 4;

这不行,因为我们约束b等于'A'要做的事!但是我在CQL3语法中找不到任何东西,允许我继续迭代。我希望我可以做类似的事情:

This doesn't work because we've constrained b to equal 'A' - which is a reasonable thing to do! But I've found nothing in the CQL3 syntax that allows me to keep iterating anyway. I wish I could do something like:

SELECT * FROM Stuff WHERE a=1 AND {b,c} > {'A','S'} LIMIT 4;

如何达到我想要的结果。也就是说,我如何使CQL3返回:

How do I achieve my desired result. Namely, how do I make CQL3 return:

 a | b | c | d
---+---+---+-----------
 1 | A | T | whatever0
 1 | B | P | whatever1
 1 | B | Q | whatever2
 1 | B | R | whatever3


推荐答案

自动分页完成,它发布到Cassandra 2.0.1

Auto paging is done https://issues.apache.org/jira/browse/CASSANDRA-4415, it's release to Cassandra 2.0.1

这篇关于迭代通过Cassandra宽行与CQL3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 06:02