0

我已经在 Hypertable 中插入了数据。但我不知道,如何从结果中获得特定的价值。我的 PHP 节俭代码是:

    $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);

我得到以下结果:

object(Hypertable_ThriftGen_HqlResult)#24 (4) { ["results"]=> NULL ["cells"]=> array(2) { [0]=> object(Hypertable_ThriftGen_Cell)#25 (2) { ["key"] => object(Hypertable_ThriftGen_Key)#26 (6) { ["row"]=> string(32) "077262cc53a1fb1b5f651d31b6bf81ba" ["column_family"]=> string(8) "category" ["column_qualifier"]=> string(4 ) "name" ["timestamp"]=> float(1.3419935154984E+18) ["revision"]=> float(1.3419935154984E+18) ["flag"]=> int(255) } ["value"]= > string(7) "Medical" } [1]=> object(Hypertable_ThriftGen_Cell)#27 (2) { ["key"]=> object(Hypertable_ThriftGen_Key)#28 (6) { ["row"]=> string( 32) “077262cc53a1fb1b5f651d31b6bf81ba”["column_family"]=> string(8) "category" ["column_qualifier"]=> string(4) "type" ["timestamp"]=> float(1.3419935154984E+18) ["revision"]=> float (1.3419935154984E+18) ["flag"]=> int(255) } ["value"]=> string(7) "android" } } ["scanner"]=> NULL ["mutator"]=> NULL 0.9678

我可以知道如何从上述结果中获取["value"]=> string(7) "Medical"值。

4

1 回答 1

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;
}
于 2013-02-07T05:26:32.867 回答