hbase表顶部的phoenix视图问题

zdwk9cvp  于 2021-07-15  发布在  Hadoop
关注(0)|答案(2)|浏览(611)

我使用的是hbase 2.0.2版和phoenix 5.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表的顶部创建了一个phoenix视图。

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

ffx8fchx1#

如果要将phoenix视图添加到现有hbase表中,则必须确保表中存储的值按phoenix预期的方式编码为字节。因为您是从hbase shell而不是通过phoenix将数据写入表中,所以这种情况可能不会发生(错误消息表明情况就是这样)。
如果是新表,不要使用hbase shell,而是使用phoenix sql命令来创建表。这样一切都将按照Phoenix城的预期进行配置。此后,只使用phoenix与数据交互(写入、查询、创建视图等),以避免与不同编码等相关的问题。

jm81lzqq

jm81lzqq2#

在我们插入hbase的那一刻,我们必须以二进制格式对数据进行编码。然后我们可以相应地用所需的数据类型创建phoenix视图。它对我有用

相关问题