开发者

How to insert data into Hbase tables using PHP Stargate client

I'm playing around with an install of HBase cluster, and am trying to access the data via the Stargate REST interface. Most of the read-only functions (i.e. listing tables, getting version, meta data, etc) are work nicely. However, I'm having trouble with actually inserting data into any tables I've created. Here's what I've got so far....

Created a dummy table with two columns, as follows:

$table_schema = <<<SCHEMA
    <TableSchema name="mytable" IS_META="false" IS_ROOT="false">
        <ColumnSchema name="inf开发者_如何学JAVAo" BLOCKSIZE="65536" BLOOMFILTER="false" BLOCKCACHE="false" COMPRESSION="NONE" LENGTH="2147483647" VERSIONS="1" TTL="-1" IN_MEMORY="false" />
        <ColumnSchema name="url" BLOCKSIZE="65536" BLOOMFILTER="false" BLOCKCACHE="false" COMPRESSION="NONE" LENGTH="2147483647" VERSIONS="1" TTL="-1" IN_MEMORY= "false"/>
    </TableSchema>
SCHEMA;

require_once "HTTP/Request.php";
$request = new HTTP_Request("http://localhost:8080");
$request->setMethod(HTTP_REQUEST_METHOD_PUT);
$request->addHeader("Accept", "text/xml");
$request->addHeader("Accept", "text/xml");
$request->setBody($table_schema);
$request->sendRequest();

The table creation works fine. Next, I want to insert some data into my new table. Here's how I attempt to do it:

$row_key = base64_encode("higgilty");
$column_name = base64_encode("info");
$value = base64_encode("Here is a test value");

$data = <<<DATA
     <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     <CellSet>
         <Row key="$row_key">
             <Cell column="$column_name">
                 $value
             </Cell>
         </Row>
     </CellSet>
DATA;

require_once "HTTP/Request.php";
$request = new HTTP_Request("http://localhost:8080/mytable/higgilty");
$request->setMethod(HTTP_REQUEST_METHOD_PUT);
$request->addHeader("Accept", "text/xml");
$request->addHeader("Accept", "text/xml");
$request->setBody($data);
$request->sendRequest();

The result of this request returns a 503 error, with the following exception:

[...] org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException: Column family  does not exist in region [...]

The error is pretty clear, but I am not sure what is wrong with my schema posted above.

I also wonder if I'm better off using the Thrift package and generating necessary PHP client files instead of using Starbase? If anyone has any experience with this I'd love to hear from you.

Any help is greatly appreciated.


You need to specify the column name as a family:qualifier pair. The "ColumnSchema" which you specify only gives the family name, so you can say, for example, $column_name = base64_encode("info:column1");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜