Cassandra (CQL) select语句with 'where'不起作用


Cassandra (CQL) select statement with 'where' is not working

我最近几天在用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"。

用于细节
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中,你不能像平常那样查询一个'表'。您需要为可能要查询的每个列设置二级索引。

假设我们有一个表:

 key      | User |   Age 
----------+----------------
 phpqa    | Jack |   20    

可以直接在键上查询:

SELECT * FROM User WHERE key='phpqa';

但是要执行其他WHERE查询,您需要在WHERE子句中可用的列上建立二级索引。

你能做些什么来使你的查询更灵活呢?

  1. 上述二级索引。
  2. 使用组合列作为键。如果您想查询的列只有2-3列,那么这是个好主意,但是请通读这篇文章,详细了解如何以及何时使用组合键,这里有一个如何在phpcassa中实现它的链接。

添加'name'和'age'作为二级索引:

CREATE INDEX name_key on User( name );  
CREATE INDEX age_key on User( age );

那么您应该能够使用您的select语句。

您使用保留字作为列名:

http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

$raw->client->execute_cql_query("SELECT * FROM User WHERE KEY='phpqa'", 
cassandra_Compression::NONE)