php – Cassandra(CQL)select语句,其中’where’不起作用

前端之家收集整理的这篇文章主要介绍了php – Cassandra(CQL)select语句,其中’where’不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我最近几天在使用Cassandra.我正在使用 PHPCassa库.

当我尝试使用以下代码时,它无法正常工作.

  1. require_once('PHPcassa/connection.PHP');
  2. require_once "PHPcassa/columnfamily.PHP";
  3.  
  4. // Create new ConnectionPool like you normally would
  5. $pool = new ConnectionPool("newtest");
  6.  
  7. // Retrieve a raw connection from the ConnectionPool
  8. $raw = $pool->get();
  9.  
  10. $rows = $raw->client->execute_cql_query("SELECT * FROM User WHERE KEY='PHPqa'",cassandra_Compression::NONE);
  11.  
  12. echo "<pre>";
  13. print_r($rows);
  14. echo "<pre>";
  15.  
  16. // Return the connection to the pool so it may be used by other callers. Otherwise,// the connection will be unavailable for use.
  17. $pool->return_connection($raw);
  18. unset($raw);

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

  1. $rows = $raw->client->execute_cql_query("SELECT * FROM User WHERE age='32'",cassandra_Compression::NONE);
  2. $rows = $raw->client->execute_cql_query("SELECT * FROM User WHERE name='jack'",cassandra_Compression::NONE);

但是当我尝试的时候

  1. $rows = $raw->client->execute_cql_query("SELECT * FROM User",cassandra_Compression::NONE);

给出正确答案,显示所有行.请告诉我,如何正确使用’WHERE’.

Keyspace细节

  1. Strategy Class: org.apache.cassandra.locator.SimpleStrategy
  2. Strategy Options: None
  3. Replication Factor: 1
  4.  
  5. Ring
  6.  
  7. Start Token: 6064078270600954295
  8. End Token: 6064078270600954295
  9. Endpoints: 127.0.0.1
在cassandra你不能像平时一样查询’table’.您需要为可能要查询的每个列设置二级索引.

假设我们有一张桌子:

  1. key | User | Age
  2. ----------+----------------
  3. PHPqa | Jack | 20

您可以直接在密钥上查询

  1. SELECT * FROM User WHERE key='PHPqa';

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

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

> Secondary indexes如上所述.
>使用复合列作为键.如果您只想查询2-3列,那么这是一个好主意,但是阅读this article详细说明了如何以及何时使用复合键,这里有一个如何在phpcassa中实现它的链接.

猜你在找的PHP相关文章