如何使用 PHP Stargate 客户端将数据插入 Hbase 表

发布于 2024-08-19 11:42:50 字数 2087 浏览 8 评论 0原文

我正在安装 HBase 集群,并尝试通过 Stargate REST 接口访问数据。大多数只读功能(即列出表、获取版本、元数据等)都可以很好地工作。但是,我在将数据实际插入到我创建的任何表中时遇到了麻烦。这是我到目前为止所得到的......

创建了一个包含两列的虚拟表,如下所示:

$table_schema = <<<SCHEMA
    <TableSchema name="mytable" IS_META="false" IS_ROOT="false">
        <ColumnSchema name="info" 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();

表创建工作正常。接下来,我想将一些数据插入到我的新表中。以下是我尝试执行此操作的方法:

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

此请求的结果返回 503 错误,但有以下例外:

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

该错误非常清楚,但我不确定上面发布的架构出了什么问题。

我还想知道使用 Thrift 包并生成必要的 PHP 客户端文件是否比使用 Starbase 更好?如果有人有这方面的经验,我很乐意听取您的意见。

非常感谢任何帮助。

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="info" 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盛夏尉蓝 2024-08-26 11:42:50

您需要将列名称指定为 family:qualifier 对。您指定的“ColumnSchema”仅提供系列名称,因此您可以说,例如,$column_name = base64_encode("info:column1");

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文