Phoenix Mapping HBase

enter description here
enter description here

Phoenix 簡單使用

create table server_metrics(
    host varchar not null
    ,date date not null
    ,response_time integer
    ,gc_time integer
    ,cpu_time integer
    ,io_time integer,
    
    CONSTRAINT constraintName PRIMARY KEY (host,date)
)

select * from server_metrics;

upsert into server_metrics values('192.168.137.121','2017-06-22 17:33:55',10,1,1,1);
upsert into server_metrics values('192.168.137.122','2017-06-22 17:33:56',1,1,1,1);

How I map Phoenix table to an existing HBase table?

簡單結構

  create 'test1','i'
  put 'test1','1','i:name','zhangsan'
  put 'test1','2','i:name','lisi'
  put 'test1','1','i:age','15'
  put 'test1','2','i:age','2'

創(chuàng)建test1 視圖對應與hbase中的test1

注意視圖名稱、類簇名稱、qualify名稱都要用雙引號擴起來否則會默認創(chuàng)建成大寫,與原表才能對應。也可以創(chuàng)建表,這樣的話執(zhí)行drop table 操作后hbase中的表數(shù)據就被全部清空了;

  create  view "test1"(
    pk VARCHAR PRIMARY KEY
    ,"i"."name" varchar
    ,"i"."age" varchar
)
enter description here
enter description here
enter description here
enter description here

復雜結構

hbase(main):014:0> create 'test','i','j'

hbase(main):014:0> put 'test','1','i:name','zhangsan'
hbase(main):014:0> put 'test','2','i:name','lisi'
hbase(main):014:0> put 'test','1','j:name','wangwu'
hbase(main):014:0> put 'test','2','j:name','zhaoliu'

hbase(main):014:0> put 'test','1','i:age',15
hbase(main):014:0> put 'test','2','i:age',20
hbase(main):014:0> put 'test','1','j:age',23
hbase(main):014:0> put 'test','2','j:age',28
create  table "test"(
    pk VARCHAR PRIMARY KEY
    ,"i"."name" varchar
    ,"i"."age" integer
    ,"j"."name" varchar
    ,"j"."age" integer
)

enter description here
enter description here

可以看出發(fā)現(xiàn)了兩個問題,

  • 數(shù)據參數(shù)age導入異常
  • 不同類簇下存在同樣的qualify 會導致異常

數(shù)據異常是由于在hbase shell 中無論加不加單引號,數(shù)據默認都是使用的string類型存放,
在使用hbase api 導入數(shù)據時使用Bytes.toBytes(int) 接口寫入的數(shù)據才是真正的整形,而且映射關系的時候貌似前面都要使用無符號的對應類型,這點比較怪異。
具體可見Hbase and Phoenix can't able to map integers

對于第二個問題,目前貌似還沒有很好的解決方案,其根本原因還是SQLNOSQL的不同設計,在hbase 數(shù)據庫設計的不是十分復雜的情況下,該問題很好解決(一個hbase表表一個列簇,剛好對應SQL中的一張表),但是當hbase數(shù)據庫的類簇,qualify設計的很復雜時,目前只能先抽取一張表中的數(shù)據創(chuàng)建成視圖,想辦法多創(chuàng)建幾個視圖把不同維度表拿出來

-- 創(chuàng)建視圖 用以統(tǒng)計醫(yī)院相關數(shù)據,該數(shù)據由智能導診項目調出
create  view "aidoctor"(
    pk VARCHAR PRIMARY KEY
     ,"hos"."havgcost"           UNSIGNED_DOUBLE
     ,"hos"."havgday"            UNSIGNED_DOUBLE
     ,"hos"."havgfinproportion"  UNSIGNED_DOUBLE
     ,"hos"."havgreimburse"      UNSIGNED_DOUBLE
     ,"hos"."havgreproportion"   UNSIGNED_DOUBLE
     ,"hos"."hcount"             UNSIGNED_DOUBLE
     ,"hos"."oavgcost"           UNSIGNED_DOUBLE
     ,"hos"."oavgfinproportion"  UNSIGNED_DOUBLE
     ,"hos"."oavgreimburse"      UNSIGNED_DOUBLE
     ,"hos"."oavgreproportion"   UNSIGNED_DOUBLE
     ,"hos"."ocount"             UNSIGNED_DOUBLE
)

select * from "aidoctor"
order by "havgcost" asc limit 10
enter description here
enter description here

相關鏈接

How I map Phoenix table to an existing HBase table?

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容