带有'where'的Cassandra(CQL)select语句不起作用

php*_*.in 6 php cql cassandra phpcassa

我最近几天在使用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);
Run Code Online (Sandbox Code Playgroud)

它没有返回,我也尝试过以下查询

$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);
Run Code Online (Sandbox Code Playgroud)

但是当我尝试的时候

 $rows = $raw->client->execute_cql_query("SELECT * FROM User", cassandra_Compression::NONE);
Run Code Online (Sandbox Code Playgroud)

给出正确答案,显示所有行.请告诉我,如何正确使用'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
Run Code Online (Sandbox Code Playgroud)

Lyu*_*rov 8

在cassandra你不能像平时一样查询'table'.您需要为可能要查询的每个列设置二级索引.

假设我们有一张桌子:

 key      | User |   Age 
----------+----------------
 phpqa    | Jack |   20    
Run Code Online (Sandbox Code Playgroud)

您可以直接在密钥上查询:

SELECT * FROM User WHERE key='phpqa';
Run Code Online (Sandbox Code Playgroud)

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

您可以做些什么来使您的查询灵活变通:

  1. 如上所述的二级索引.
  2. 使用复合列作为键.如果你只想要查询2-3列,那么这是个好主意,但请仔细阅读本文详细说明如何以及何时使用复合键,这里有一个如何在phpcassa中实现它的链接.