【问题标题】:datastax cassandra query result decoding in phpphp中的datastax cassandra查询结果解码
【发布时间】:2016-01-11 11:31:23
【问题描述】:

我正在使用 Cassandra 并使用 Datastax PHP CQL。

鉴于以下查询,我应该如何解码结果?

$cql = SELECT * FROM  company WHERE userid = 1001 ORDER BY gpsTime DESC LIMIT 1;                           
$statement = new Cassandra\SimpleStatement($cql);
$result = $this->session->execute($statement);

我尝试解码:

foreach($result as $row){
    // Get values from row and add to array
    array_push($allVehicleInfo,array(
        'userID'    => $row['userid']->value,
        'gpsTime'   => $row['gpstime']->seconds,
         'latitude' => $row['latitude']->value )
    );
}

但是,我收到一个错误:

消息:未定义属性:Cassandra\Decimal::$value


我的表架构是:

$cql = "CREATE TABLE " company " (
    userID bigint,
    userName ascii,
    latitude decimal,
    longitude decimal,
    accuracy float,
    altitude float,
    gpsTime timestamp );

【问题讨论】:

    标签: cassandra datastax cqlsh


    【解决方案1】:

    value 是一个函数而不是属性,所以你必须做$row['latitude']->value()

    【讨论】:

      【解决方案2】:

      正如亚历克斯所说,在您的示例中,value 不是属性。相反,请检查您尝试解码的类的文档。 The documentation can be found here.

      如果您不确定自己处理的是哪个类,可以使用内置函数get_class() - see get_class() manual

      一旦您知道要处理的类是什么,您可以查看 DataStax PHP 驱动程序文档,了解您需要调用哪个函数来检索正确的值。

      例如,如果您正在处理Cassandra\Timestamp 类,则必须调用time() 函数以将时间检索为intSee Timestamp documentation.

      在您的情况下,您可能正在处理Float,因此检查the Float documentation 并查看您是否需要调用函数value() 来检索Cassandra\Float 实例的float 值。


      代码解决方案:

      foreach($result as $row){
          // Get values from row and add to array
          array_push($allVehicleInfo,array(
              'userID'    => $row['userid']->value(),
              'gpsTime'   => $row['gpstime']->seconds,
               'latitude' => $row['latitude']->value() )
          );
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-08-17
        • 2020-02-04
        • 2015-05-12
        • 1970-01-01
        • 2016-05-05
        • 2020-11-01
        • 1970-01-01
        相关资源
        最近更新 更多