我最近几天在使用Cassandra.我正在使用
PHPCassa库.
当我尝试使用以下代码时,它无法正常工作.
require_once('phpcassa/connection.php'); require_once "phpcassa/columnfamily.php"; // Create new ConnectionPool like you normally would $pool = new ConnectionPool("newtest"); // Retrieve a raw connection from the ConnectionPool $raw = $pool->get(); $rows = $raw->client->execute_cql_query("SELECT * FROM User WHERE KEY='phpqa'",cassandra_Compression::NONE); echo "<pre>"; print_r($rows); echo "<pre>"; // Return the connection to the pool so it may be used by other callers. Otherwise,// the connection will be unavailable for use. $pool->return_connection($raw); unset($raw);
它没有返回,我也尝试过以下查询
$rows = $raw->client->execute_cql_query("SELECT * FROM User WHERE age='32'",cassandra_Compression::NONE); $rows = $raw->client->execute_cql_query("SELECT * FROM User WHERE name='jack'",cassandra_Compression::NONE);
但是当我尝试的时候
$rows = $raw->client->execute_cql_query("SELECT * FROM User",cassandra_Compression::NONE);
给出正确答案,显示所有行.请告诉我,如何正确使用’WHERE’.
Keyspace细节
Strategy Class: org.apache.cassandra.locator.SimpleStrategy Strategy Options: None Replication Factor: 1 Ring Start Token: 6064078270600954295 End Token: 6064078270600954295 Endpoints: 127.0.0.1
在cassandra你不能像平时一样查询’table’.您需要为可能要查询的每个列设置二级索引.
假设我们有一张桌子:
key | User | Age ----------+---------------- phpqa | Jack | 20
您可以直接在密钥上查询:
SELECT * FROM User WHERE key='phpqa';
但是要执行其他WHERE查询,您需要在WHERE子句中可用的列上使用二级索引.
您可以做些什么来使您的查询灵活变通:
> Secondary indexes如上所述.
>使用复合列作为键.如果您只想查询2-3列,那么这是一个好主意,但是阅读this article详细说明了如何以及何时使用复合键,这里有一个如何在phpcassa中实现它的链接.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。