2012-07-11 57 views
0

我在Hypertable中插入了數據。但我不知道,如何從結果中獲得特別的價值。我的PHP節儉的代碼是:如何使用php解析Hypertable數據

$GLOBALS['THRIFT_ROOT'] = "/opt/hypertable/0.9.5.6/lib/php"; 

    require_once $GLOBALS['THRIFT_ROOT'].'/ThriftClient.php'; 

    $client = new Hypertable_ThriftClient("localhost", 38080); 

    $namespace = $client->namespace_open("appuniv"); 

    $query = "select * from category_details limit 1"; 

    $tab = $client->hql_query($namespace, $query); 

    var_dump($tab); 

我發現了下面的結果:

對象(Hypertable_ThriftGen_HqlResult)#24(4){[ 「結果」] => NULL [ 「細胞」 ] =>陣列(2){[0] =>對象(Hypertable_ThriftGen_Cell)#25(2) {[ 「鑰匙」] =>對象(Hypertable_ThriftGen_Key)#26(6){[ 「行」] => 串(32)「077262cc53a1fb1b5f651d31b6bf81ba」[「column_family」] => string(8)「category」[「column_qualifier」] => string(4)「name」 [「timestamp」] => float(1.3419935154984E + 18) [「revision」] => 浮子(1.3419935154984E + 18)[ 「標誌」] => INT(255)} [ 「值」] =>串(7) 「醫療」} [1] =>對象(Hypertable_ThriftGen_Cell)#27(2) {[「key」] => object(Hypertable_ThriftGen_Key)#28(6){[「row」] => string(32) 「077262cc53a1fb1b5f651d31b6bf81ba」[「column_family」] => string(8) 「category」[[ 「column_qualifier」] =>串(4) 「類型」[ 「時間戳」] => 浮子(1.3419935154984E + 18)[ 「修訂」] =>浮子(1.3419935154984E + 18) [ 「標誌」] => INT(255)} [ 「值」] =>串(7) 「機器人」}} [ 「掃描器」] => NULL [ 「增變」] => NULL} 0.9678

可能我知道如何得到[「值」] =>字符串(7)「醫療」值從上面的結果。

回答

0
/** 
* Sort result by column family/qualifier 
* @param thrift result 
*/ 
private function sort($data) 
{ 
    $result = array(); 
    foreach ($data as $cell) 
    { 
     $row = $cell->key->row; 
     if (!isset($result[$row])) { 
      $result[$row] = new stdClass; 
      $result[$row]->row = $cell->key->row; 
      foreach ($this->columns as $col) { 
       $pos = strpos($col, ':') ; 
       $qualifier = ($pos) ? substr($col, $pos + 1) : NULL; 
       $col = !$pos ? $col : substr($col, 0, $pos); 
       if (!$qualifier) 
        $result[$row]->{$col} = NULL; 
       else if ($qualifier[0] != '/') 
        $result[$row]->{$col}[$qualifier] = NULL; 
      } 
     } 
     $result[$row]->{$cell->key->column_family}[$cell->key->column_qualifier] = $cell->value; 
    } 
    return $result; 
}