hadoop - hbase表顶部的凤凰视图问题
问题描述
我正在使用 Hbase 版本 2.0.2 和 phoenix V5.0.0。我有一个 HBase 表,我们使用以下步骤创建了 Phoenix 视图
hbase(main):007:0> create 'phownix_test','details'
hbase(main):008:0> put 'phownix_test','1','details:MAC','1234567'
Took 1.5056 seconds
hbase(main):009:0> put 'phownix_test','1','details:deviceName','RAINDEVICE'
Took 0.0101 seconds
hbase(main):010:0> put 'phownix_test','1','details:CO2','234.543'
Took 0.0079 seconds
hbase(main):011:0> put 'phownix_test','1','details:latitude','9876543'
Took 0.0084 seconds
hbase(main):012:0> scan 'phownix_test'
ROW COLUMN+CELL
1 column=details:CO2, timestamp=1609744038606, value=234.543
1 column=details:MAC, timestamp=1609744024895, value=1234567
1 column=details:deviceName, timestamp=1609744031974, value=RAINDEVICE
1 column=details:latitude, timestamp=1609744051328, value=9876543
然后我在 HBase 表的顶部创建了一个凤凰视图。
create view "phownix_test"("ID" VARCHAR primary key,"details"."MAC" UNSIGNED_INT,"details"."CO2" UNSIGNED_FLOAT,"details"."deviceName" VARCHAR,"details"."latitude" UNSIGNED_LONG);
从凤凰视图中选择数据时,出现以下错误。
0: jdbc:phoenix:> select * from "phownix_test";
Error: ERROR 201 (22000): Illegal data. Expected length of at least 51 bytes, but had 23 (state=22000,code=201)
java.sql.SQLException: ERROR 201 (22000): Illegal data. Expected length of at least 51 bytes, but had 23
at org.apache.phoenix.exception.SQLExceptionCode$Factory$1.newException(SQLExceptionCode.java:503)
at org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:150)
at org.apache.phoenix.schema.KeyValueSchema.next(KeyValueSchema.java:214)
at org.apache.phoenix.expression.ProjectedColumnExpression.evaluate(ProjectedColumnExpression.java:116)
at org.apache.phoenix.compile.ExpressionProjector.getValue(ExpressionProjector.java:69)
at org.apache.phoenix.jdbc.PhoenixResultSet.getString(PhoenixResultSet.java:635)
at sqlline.Rows$Row.<init>(Rows.java:183)
at sqlline.BufferedRows.<init>(BufferedRows.java:38)
at sqlline.SqlLine.print(SqlLine.java:1660)
at sqlline.Commands.execute(Commands.java:833)
at sqlline.Commands.sql(Commands.java:732)
at sqlline.SqlLine.dispatch(SqlLine.java:813)
at sqlline.SqlLine.begin(SqlLine.java:686)
at sqlline.SqlLine.start(SqlLine.java:398)
at sqlline.SqlLine.main(SqlLine.java:291)
解决方案
如果要将 Phoenix 视图添加到现有 HBase 表中,则必须确保存储在表中的值按照 Phoenix 期望的方式编码为字节。由于您从 HBase shell 而不是通过 Phoenix 将数据写入表中,因此这可能不会发生(您的错误消息表明是这种情况)。
如果是新表,请不要使用 HBase shell——而是使用 Phoenix SQL 命令来创建表。这样一来,一切都将按照 Phoenix 期望的方式进行配置。此后仅使用 Phoenix 与数据交互(写入、查询、创建视图等)以避免与不同编码等相关的问题。
推荐阅读
- java - 如何在以下用例中减少样板代码
- c++ - 重载移位,因此它支持链接,也应该与 cout 一起使用
- azure-devops - 获取当前时间戳并与 yml 文件中的字符串连接
- python - 如何在组合过程中更新列表?
- sql - MS Access:每小时显示计数(即使时隙中没有记录)
- javascript - ReactJS incrementor++ 在 useReducer 中不起作用
- nginx - 提供私钥、CA 和 ssl 证书时在 nginx 上安装 ssl 证书
- ios - 如何让 app iCloud 文件夹显示在其他设备上
- python - 根据 ID 合并数据集中的行(字符串)
- postgresql - Heroku 请求超时 (H12)