我有一个 Hbase 表“http_access_log”,现在我想在它上面使用 Apache phoenix for SQL。
我应该创建 Phoenix View 或表来映射 hbase 表吗?而如果hbase表被hbase api更新了,那么phoenix View 或表会被更新吗?
最佳答案
如果您有一个预先存在的表,则必须创建一个 View 才能访问它:
create view "http_access_log_v" (pk VARCHAR PRIMARY KEY, "colfam1"."colum1" VARCHAR, "colfam1"."colum2" VARCHAR) as select * from "http_access_log";
有了上面的 View ,你就可以像这样选择它:
select * from http_access_log_v;
例子
假设我有一个 HBase 表“配置”。我无法通过 Phoenix 直接针对此表进行选择。
sqlline> select * from "config";
Error: ERROR 1012 (42M03): Table undefined. tableName=config (state=42M03,code=1012)
但是,如果我针对
select * from "config"
创建 View 此 HBase 表的:sqlline> create view "config-data" (pk VARCHAR PRIMARY KEY, "data"."id" VARCHAR, "data"."categoryName" VARCHAR) as select * from "config";
No rows affected (1.588 seconds)
然后,我可以查询已在 Phoenix SQL View 中配置的可用列的子集:
sqlline> select * from "config-data";
+------------------------------------------+------------------------------------------+------------------------------------------+
| PK | id | categoryName |
+------------------------------------------+------------------------------------------+------------------------------------------+
| QA-AA00|D|MC|MSG|C10|M3 | null | null |
| QA-AA00|D|MC|MSG|C2|M1 | null | null |
...
我仍然无法直接查询 HBase 表:
sqlline> select * from "config"; Error: ERROR 1012 (42M03): Table undefined. tableName=config (state=42M03,code=1012)
引用
关于sql - Phoenix 映射现有的 HBase 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29840477/