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

问题描述

如何使用 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 中,这有效地创建了一个 ColumnFamily,其中包含整数行(a 的值)以及由 b 和 c 的值以及文字字符串 'd' 组成的 CompositeColumns.当然,这一切都被 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;

正如预期的那样,我得到了:

And as expected I get:

 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

推荐答案

自动分页完成 https://issues.apache.org/jira/browse/CASSANDRA-4415,发布到 Cassandra 2.0.1

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

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

09-18 06:02