這篇文章主要為大家展示了“hive如何整合phoenix”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“hive如何整合phoenix”這篇文章吧。
創(chuàng)新互聯(lián)公司公司2013年成立,先為堆龍德慶等服務(wù)建站,堆龍德慶等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為堆龍德慶企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
首先需要phoenix整合hbase
hive整合hbase,此處參照之前的筆記
將phoenix{core,queryserver,4.8.0-HBase-0.98,hive}拷貝到$hive/lib/
根據(jù)官網(wǎng)要求修改配置文件
> vim conf/hive-env.sh
> vim conf/hive-site.xml
啟動:
> hive -hiveconf phoenix.zookeeper.quorum=hadoop01:2181
創(chuàng)建內(nèi)部表
create table phoenix_table (
s1 string,
i1 int,
f1 float,
d1 double
)
STORED BY 'org.apache.phoenix.hive.PhoenixStorageHandler'
TBLPROPERTIES (
"phoenix.table.name" = "phoenix_table",
"phoenix.zookeeper.quorum" = "hadoop01",
"phoenix.zookeeper.znode.parent" = "/hbase",
"phoenix.zookeeper.client.port" = "2181",
"phoenix.rowkeys" = "s1, i1",
"phoenix.column.mapping" = "s1:s1, i1:i1, f1:f1, d1:d1",
"phoenix.table.options" = "SALT_BUCKETS=10, DATA_BLOCK_ENCODING='DIFF'"
);
創(chuàng)建成功。查詢phoenix和hbase中都有相應(yīng)的表生成:phoenix
hbase:
屬性
phoenix.table.name
phoenix指定表名
默認值:hive一樣的表
phoenix.zookeeper.quorum
指定ZK地址
默認值:localhost
phoenix.zookeeper.znode.parent
指定HBase在ZK的目錄
默認值:/ hbase
phoenix.zookeeper.client.port
指定ZK端口
默認值:2181
phoenix.rowkeys
指定phoenix的rowkey,即hbase的rowkey
要求
phoenix.column.mapping
hive與phoenix之間的列映射。
插入數(shù)據(jù)
使用hive測試表pokes導(dǎo)入數(shù)據(jù)
> insert into table phoenix_table select bar,foo,12.3 as fl,22.2 as dl from pokes;
成功、查詢
在phoenix中查詢
還可以使用phoenix導(dǎo)入數(shù)據(jù),看官網(wǎng)的解釋
注意:phoenix4.8認為加tbale關(guān)鍵字為語法錯誤,其他版本沒試,不知道官網(wǎng)怎么沒說明
創(chuàng)建外部表
For external tables Hive works with an existing Phoenix table and manages only Hive metadata. Deleting an external table from Hive only deletes Hive metadata and keeps Phoenix table
首先在phoenix創(chuàng)建表
phoenix> create table PHOENIX_TABLE_EXT(aa varchar not null primary key,bb varchar);
再在hive中創(chuàng)建外部表:
create external table phoenix_table_ext_1 ( aa string, bb string ) STORED BY 'org.apache.phoenix.hive.PhoenixStorageHandler' TBLPROPERTIES ( "phoenix.table.name" = "phoenix_table_ext ", "phoenix.zookeeper.quorum" = "hadoop01", "phoenix.zookeeper.znode.parent" = "/hbase", "phoenix.zookeeper.client.port" = "2181", "phoenix.rowkeys" = "aa", "phoenix.column.mapping" = "aa:aa, bb:bb" );
創(chuàng)建成功,插入成功
這些選項可以設(shè)置在hive CLI
性能調(diào)優(yōu)
參數(shù) | 默認值 | 描述 |
phoenix.upsert.batch.size | 1000 | 批量大小插入。 |
[phoenix-table-name].disable.wal | false | 它暫時設(shè)置表屬性DISABLE_WAL = true??捎糜谔岣咝阅?/td> |
[phoenix-table-name].auto.flush | false | 當(dāng)WAL是disabled 的flush又為真,則按文件刷進庫 |
查詢數(shù)據(jù)
可以使用HiveQL在phoenix表查詢數(shù)據(jù)。一個簡單表查詢當(dāng)hive.fetch.task.conversion=more and hive.exec.parallel=true.就可以像在Phoenix CLI一樣快。
參數(shù) | 默認值 | 描述 |
hbase.scan.cache | 100 | 為一個單位請求讀取行大小。 |
hbase.scan.cacheblock | false | 是否緩存塊。 |
split.by.stats | false | If true, mappers will use table statistics. One mapper per guide post. |
[hive-table-name].reducer.count | 1 | reducer的數(shù)量. In tez mode is affected only single-table query. See Limitations |
[phoenix-table-name].query.hint | Hint for phoenix query (like NO_INDEX) |
遇到的問題:
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org.apache.hadoop.hbase.client.Scan.isReversed()Z
最開始我用的hbase-0.96.2-hadoop2版本,不能整合,這個是需要hbase-client-0.98.21-hadoop2.jar包,更換這個jar包就解決了,但是還是會報下面的錯
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:ERROR 103 (08004): Unable to establish connection.
于是更換了hbase的版本為0.98.21的 ok了
---------
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. java.lang.StringIndexOutOfBoundsException: String index out of range: -1
因為字段對應(yīng)不一樣
create table phoenix_table_3 (a string,b int) STORED BY 'org.apache.phoenix.hive.PhoenixStorageHandler' TBLPROPERTIES ("phoenix.table.name" = "phoenix_table_3","phoenix.zookeeper.quorum" = "hadoop01","phoenix.zookeeper.znode.parent" = "/hbase","phoenix.zookeeper.client.port" = "2181","phoenix.rowkeys" = "a1","phoenix.column.mapping" = "a:a1, b:b1","phoenix.table.options" = "SALT_BUCKETS=10, DATA_BLOCK_ENCODING='DIFF'");
hive表字段與phoenix字段一樣就可以了
----------
創(chuàng)建成功,插入也能成功,就是hive查詢的時候報錯找不到a1列,因為phoenix是aa列
Failed with exception java.io.IOException:java.lang.RuntimeException: org.apache.phoenix.schema.ColumnNotFoundException: ERROR 504 (42703): Undefined column. columnName=A1
create external table phoenix_table_ext (a1 string,b1 string)STORED BY 'org.apache.phoenix.hive.PhoenixStorageHandler' TBLPROPERTIES ("phoenix.table.name" = "phoenix_table_ext","phoenix.zookeeper.quorum" = "hadoop01","phoenix.zookeeper.znode.parent" = "/hbase","phoenix.zookeeper.client.port" = "2181","phoenix.rowkeys" = "aa","phoenix.column.mapping" = "a1:aa, b1:bb");
解決辦法:同上hive表字段與phoenix字段一樣就可以了
以上是“hive如何整合phoenix”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前文章:hive如何整合phoenix
分享鏈接:http://aaarwkj.com/article22/gppsjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、定制開發(fā)、軟件開發(fā)、移動網(wǎng)站建設(shè)、外貿(mào)建站、全網(wǎng)營銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)