hbase 上的 phoenix 视图问题 table

phoenix view issue on top of hbase table

我使用的是Hbase 2.0.2 版本和phoenix V5.0.0。我在上面有一个 HBase table 我们使用以下步骤创建了 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 上创建了一个 phoenix 视图 table。

create view "phownix_test"("ID" VARCHAR primary key,"details"."MAC" UNSIGNED_INT,"details"."CO2" UNSIGNED_FLOAT,"details"."deviceName" VARCHAR,"details"."latitude" UNSIGNED_LONG);

从 phoenix 视图中选择数据时出现以下错误。

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.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 table,您必须确保存储在 table 中的值按照 Phoenix 期望的方式编码为字节。由于您是从 HBase shell 而不是通过 Phoenix 将数据写入 table,所以这可能不会发生(您的错误消息表明是这种情况)。

如果是新的 table,请不要使用 HBase shell——而是使用 Phoenix SQL 命令来创建 table。这样一切都将按照 Phoenix 期望的方式进行配置。然后以后只使用 Phoenix 与数据交互(写入、查询、创建视图等)以避免与不同编码等相关的问题。

我们仅插入 Hbase 的那一刻我们必须以二进制格式对数据进行编码。然后我们可以相应地创建具有所需数据类型的 Phoenix View。它对我有用