




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、Phoenix安裝與使用文檔作者:宋亞飛2015年3月27日目錄Phoenix安裝與使用文檔 1目錄1描述1Phoenix 安裝 21、下載 Phoenix22、上傳壓縮包33、解壓縮文件34、配置 Phoenix35、修改權(quán)限36、驗(yàn)證是否成功3Phoenix 使用 41、建表42、導(dǎo)入數(shù)據(jù)43、查詢數(shù)據(jù)4查詢1、查詢?nèi)坑涗?5查詢2、查詢記錄總條數(shù) 5查詢3、查詢結(jié)果分組排序5查詢4、求平均值6查詢5、多字段分組,排序,別名。 6查詢6、查詢?nèi)掌陬愋妥侄?6查詢7、字符串,日期類型轉(zhuǎn)換64、Phoenix 基本 shell 命令 75、 用 Phoenix Java api 操彳HBas
2、e8Phoenix 支持 11描述現(xiàn)有hbase的查詢工具有很多如:Hive , Tez, Impala, Shark/Spark, Phoenix等。今天主要記錄 Phoenix。phoenix,中文譯為"鳳凰",很美的名字。Phoenix是由開源的一個(gè)項(xiàng)目, 后又捐給了 Apache基金會。它相當(dāng)于一個(gè)Java中間件,提供jdbc連接,操彳hbase數(shù)據(jù)表。但是在生產(chǎn)環(huán)境中,不可以用在OLTP中。在線事務(wù)處理的環(huán)境中,需要低延遲,而Phoenix在查詢HBase時(shí),雖然做了一些優(yōu)化, 但延遲還是不小。 所以依然是用在 OLAT中, 再將結(jié)果返回存儲下來。Phoenix官
3、網(wǎng)上,對 Phoenix講解已經(jīng)很詳細(xì)了。如果英語好,可以看官網(wǎng),更正式一 些。Phoenix 安裝1、下載 Phoenix下載地址:phoenix與HBase版本對應(yīng)關(guān)系Phoenix 2.x - HBase 0.94.xPhoenix 3.x - HBase 0.94.xPhoenix 4.x - HBase 0.98.1 +我目前測試使用版本概況:Hadoop2.2.0-HBase0.98.2所以我可以用 phoenix4.x 。下載的壓縮包為 phoenix-4.3.0-bin.tar.gzIndex of /apache/phoenixMaineL-gt modifiedSize D
4、scriLtig23-Aug-2014 08:51-2,目U-Dec-20L4 02:45-phoenix_ 3. 3. (V24-Feb-2015 13:56-phcenix-q. L 0/29-Au£-20M 08:52-ph日niz-4. 2. Z/ll-Dec-2014 02:45-phciBnix-q. 土 IV24-Feb-2015 13:57-2、上傳壓縮包將phoenix-4.3.0-bin.tar.gz上傳hbase集群的其中一個(gè)服務(wù)器的一個(gè)目錄下我上傳的目錄為/usr/lib3、解壓縮文件tar -zxvf phoenix-4.3.0-bin.tar.gz可看到有
5、個(gè)phoenix-4.3.0-bin/ 目錄,里面包含了Phoenix的所有文件。4、配置 Phoenix4.1、 將 phoenix-4.3.0-bin/目錄下 phoenix-core-4.3.0.jar、phoenix-4.3.0-client.jar 拷貝到各個(gè) hbase的lib目錄下。4.2、 重啟hbase集群,使 Phoenix的jar包生效。4.3、 將 hbase 的配置文件 hbase-site.xml 放到 phoenix-4.3.0-bin/bin/下,替換 Phoenix 原來的 配置文件。5、修改權(quán)限切換到下,修改 psql.py和sqlline.py的權(quán)限為77
6、7命令:chmod 777文件名6、驗(yàn)證是否成功6.1、 在 phoenix-4.3.0-bin/bin/下輸入命令: ./sqlline.py localhost如 果 看 到 如 下 界 面 表 示 啟Building list of tables and coluois for tab-coinpletion (set fascconnect ro79/79 (1。口贄 DeneDone sqlline versiem 1.1.S 0 : jdbc:pEioenix: localhost> |Phoenix系統(tǒng)表,系統(tǒng)6.2、 輸入!tables,查看都有哪些表。紅框部分是用戶建的
7、表,其他為 表中維護(hù)了用戶表的元數(shù)據(jù)信息。D; jdbc: phoeniiL : IoghIJIi口?仁下! tableij|TABLEJZAT|亍A3 n皿|TABLE_NAMETT|SYSTEM)|SYSTEMI|SYSTEM1111i*TI CATALOG| SEQUENCE:1 5TAT5 j STOCK_SYKEOL| WEB_STMI-16.3、 退出Phoenix。輸入!exit命令(PS: Phoenix早期版本如(2.11版本)需輸入!quilt才可退出, 目前高版本已改為!exit命令)0: jdbc:phoenix:localhoso IquilL0: jdbc:phoe
8、nix:localhcst> exit Closing: org,apache,phoenix.jdbc,PtioenixConnection roo0cenO3t)41 bln # |Phoenix 使用1、建表./psql.py localhost:2181 ./examples/stock_symbol.sql,其中./examples/stock_symbol.sql 是建表 的sql語句CREATE TABLE IF NOT EXISTS WEB_STAT (HOST CHAR(2) NOT NULL,DOMAIN VARCHAR NOT NULL,FEATURE VARCHA
9、R NOT NULL,DATE DATE NOT NULL,USAGE.CORE BIGINT, -usage 指定列族名USAGE.DB BIGINT, -usage 指定列族名STATS.ACTIVE_VISITOR INTEGERCONSTRAINT PK PRIMARY KEY ( HOST, DOMAIN, FEATURE, DATE )-指定主鍵);2、導(dǎo)入數(shù)據(jù)命令:./psql.py -t WEB_STAT localhost:2181 ./examples/web_stat.csvPS:其中-t后面是表名,./examples/web_stat.csv是csv數(shù)據(jù)(注意數(shù)據(jù)的分
10、隔符需要是 逗號)。3、查詢數(shù)據(jù)首先使用sqlline查看(截圖為部分列的數(shù)據(jù)),查詢表名不區(qū)分大小寫。查詢1、查詢?nèi)坑涗浾Z句:select * from web_stat;3 工,百 6eleftfrd (0«.112 m白MmCie jdbctpboenlxaelecL * Iem NEB_5TiI;I HOST1DCNAU41rcmmrIDATE-T-+| Ed+IApple - coat1Mac1M13-口 m01:01:01.DOO一十一 135I Ed|Apfple. eonIStare13013-01-0301:01-01.DDOI345I EU1GooqLeuCOt
11、t1AnaJ/tlcal2(113-01-1308:06:101,000125I E01Gocgle.cxM1SearcJil2013-01-0901:DI:QI.DOU1395I BO1Sal«fg-r«.ccin1I2013-01-0605:04:05,000112| EDISales farce .coa1Login101;Di:01.DDD1S| EQISdlesfarcc.ccHii1Repc-rLsI2013-01-0213102:01. DD£I25| EU1SalesforaB con1ReportJS:12G13-01.-0214:321,000
12、1L25I EU1SaleBf&rce.coa1Rflgrtttl2(113-01-05Q3:L1:12.DOO175I EU1Satiesforcer con1Reports12013-Ol-OSi04:14:13.00014TsI叩1Sa lesf orcc - cam1ReporLs12OU-01-1306:04:04,0013SS| HAIApple.cam1Login12C13-01-D101:Dl:DlaD00135|母LIApf>le. coin1LoqlnI2(113-01-04ai:Di:ai.DoaI135| HA1Applar cou1MacI2(113-0
13、1-0204:Dl:i01. D001345I 11A11Hacl2013-01-DSD1:D1:CI1.DOU13I帖1Apple:-cm1iPadI2013-01-0501:01:01,0001部|心IApple, ccmu1iPad15013-01-Dg01iDI:01.DOO135|以IApple. czasi1LPadI2013-01-0701:01:01sDOOI9I 11A1Google, ecu112013-01-07OGSDISUI.DIDO123| NA1G«gl«acx»1Anal/tloal2(113-01-1101:D2:01.DOO17
14、I liA1Google. g« GcKhgle-ccsB1Anai/tioa12013-01-1401:91:01,00016$| NA11Se9rcii120U-01-0B06:01:01,000345查詢2、查詢記錄總條數(shù)語句:select count from web_stat;0: jdbc:pftoenix:locaIhost> select count1 from web_stat;OTUHT(l)1 row aelected (0.054 seccnda)0: j dbc: phoe nix: loc a Ltio g t> |查詢3、查詢結(jié)果分組排序語句
15、:select domain,count as num from web_stat group by domain order by num desc;0: jdbc:phoenix:localho5t>select domalncount(I* amub from web_stat group by domain order by num desc:|DCHAItl1NUH| Sales farce d C0R1 2211 Ale.con1 91| Google, conMt-1 613 rows selected 0, QB1 aecondff | 0: jdbc:phoenix:
16、localhoO |查詢4、求平均值語句:select avg(core) from web_stat;01 jdbc:phoenix:localh03t> select avg(CORE) from web_stat;AVG (USAGE .CORE)| 217,07691 row selected 0*056 seconds)0: jdbc:phoemx: lQcalho3t> |查詢5、多字段分組,排序,別名語句:select domain,count as num,avg(core) as core,avg(db) as db from web_stat group by
17、domain order by num desc;0;nl-t 4>W!in?at HFlmrul 4<4# 西 frw 睦皆_at4t -gzwp by dwMETi Sry nwDCHKDiMUMC±KEI SaJjesfcrce-cai.| Afspfea .cdhI Gwqla EHI 240.7273 | mmI ziz.eTSI 257.63SJ| tl6.555S| Z13.75查詢6、查詢?nèi)掌陬愋妥侄握Z句:select host,domain,date from web_stat where TO_CHAR(date尸2013-01-15 07:09:01
18、.000'0: j dbc 3 phcbenix i lac a lho3t> select hnsE,. domain date from «Eh_3Eat where白 113 - 01-16 07: QSiOl - ODO ,1;+.DOMAINDATEI HOST |I 9A &a.ies rorce . cow+ 1 一+ E _ _ _.一1 row selecsed ,011N 2iecDiid3)| 2Q13-Q1-15 07:孫口1皿口 |查詢7、字符串,日期類型轉(zhuǎn)換語句:select TO_DATE('20131125',
19、39;yyyyMMdd') from web_stat;Ps:輸入的日期字符串會被轉(zhuǎn)換為hbase表date的日期類型。):jdbc:phoenix:local!i03L> select TO DATE(T201311251F ,yYyyMMddT) Emm web stat;DATE ri013-ll-55 00:00:00.0001 |2013-11-252013-11-25 2013-11-252013-11-252013-11-252013-11-252013-11-252013-11-2500:00:00.00000:00:00.00000:00:00.00000:00
20、:00.00000:00:00.00000:00:00,00000:00:00.00000:00:00.000總結(jié):Phoenix還支持了很多函數(shù)和 sql語法,在這里不再一一列舉。 更多請參考Phoenix支持部分4、Phoenix 基本 shell 命令PS:以下,可能有部分命令在Phoenix更高版本中已失效,改為其他命令代替,請注意。0: jdbc:phoenix:localhost> help!all !autocommit !batch!brief !call!close !closeall !columns !commit !connect!dbinfo !describe
21、 !dropall !exportedkeys !go!help !history !importedkeys !indexes isolation!list!manual!metadata !nativesql !outputformatExecute the specified SQL against all the current connectionsSet autocommit mode on or offStart or execute a batch of statementsSet verbose mode offExecute a callable statementClos
22、e the current connection to the databaseClose all current open connectionsList all the columns for the specified tableCommit the current transaction (if autocommit is off)Open a new connection to the database.Give metadata information about the databaseDescribe a tableDrop all tables in the current
23、databaseList all the exported keys for the specified tableSelect the current connectionPrint a summary of command usageDisplay the command historyList all the imported keys for the specified tableList all the indexes for the specified tableSet the transaction isolation for this connectionList the cu
24、rrent connectionsDisplay the SQLLine manualObtain metadata informationShow the native SQL for the specified statementSet the output format for displaying results(table,vertical,csv,tsv,xmlattrs,xmlelements)!primarykeys procedures properties !quit !reconnect !record !rehash !rollback !run !save !scan
25、List all the primary keys for the specified tableList all the proceduresConnect to the database specified in the properties file(s)Exits the program此命令在 Phoenix4.3 版本已改為!exitReconnect to the databaseRecord all output to the specified fileFetch table and column names for command completionRoll back t
26、he current transaction (if autocommit is off)Run a script from the specified fileSave the current variabes and aliasesScan for installed JDBC drivers!script !setStart saving a script to a file Set a sqlline variable5、用 Phoenix Java api 操作 HBase開發(fā)環(huán)境準(zhǔn)備:eclipse3.5、jdk1.7、window8、hadoop220、hbase
27、、phoenix4.3.01、從集群拷貝以下文件:core-site.xml、hbase-site.xmk hdfs-site.xml文件放到工程 src下2、把 phoenix 的 phoenix-4.3.0-client.jar 和 phoenix-core-4.3.0.jar 添加到工程 classpath3、配置集群中各節(jié)點(diǎn)的hosts文件,把客戶端的hostname: IP添加進(jìn)去4、在客戶端 host文件中加入集群的hostname和IP5、工程截圖j W Phoenix號srcj ,9 com.byzoro.phoenix.teJ Phoenix_TestJava兇 core-s
28、itehXitiI k hbjse-site.xml K ndfs-sitexml,占 JRE System Library '.a.aSI* * Referenced Librariesj lib匕 phoenix-4.3.0-client jare phoenix-core-4SnOjar6、工程代碼package com.byzoro.phoenix.test;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;pu
29、blic class Phoenix_Test /* 使用phoenix提供的api操彳hbase讀取數(shù)據(jù)* author songyafei* param args* throws Throwable* date 2015-03-25* /public static void main(String口 args) throws Throwable try /下面的驅(qū)動為 Phoenix老版本使用2.11使用,對應(yīng)hbase0.94+Class.forName("com.salesforce.phoenix.jdbc.PhoenixDriver");/phoenix4.3用
30、下面的驅(qū)動對應(yīng)hbase0.98+Class.forName("org.apache.phoenix.jdbc.PhoenixDriver"); catch (Exception e) e.printStackTrace();這里配置zookeeper的地址,可單個(gè),也可多個(gè)??梢允怯蛎蛘?ipString url = "jdbc:phoenix:1:2181”;/String url = "jdbc:phoenix:,:2181”;Connection conn = DriverManager.getConnection(url);
31、Statement statement = conn.createStatement();String sql = "select count(1) as num from web_stat"long time = System.currentTimeMillis();ResultSet rs = statement.executeQuery(sql);while (rs.next() int count = rs.getInt("num");System.out.println("row count is " + count);lo
32、ng timeUsed = System.currentTimeMillis() - time;System.out.println("time " + timeUsed + "mm");關(guān)閉連接rs.close();statement.close();conn.close();7、運(yùn)行截圖:.Problems 儂 Javadoc 匝>m 型 亡匹名淺<terminated> PhoenixTest Java Application C;Prograrn FiIesJaAbinjavaw.exe (2。15年3月26日 下午5:5610
33、)SLF4J: Failed to load class "org.slf4j.impl,StaticLogger SLF4J: Defaulting to no-operation (NOP) logger implement SLF4J: See http:/www i slf4j iorg/codes.html#Static LoggerB log4j:WARN No appenders could be found for logger (org.a log4j:WARN Please initialize the log4j system properly, log4j:W
34、ARN See /log4j/!.2/faq.h row count is 39 time 328mm實(shí)例二:package com.byzoro.phoenix.test;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;public class Phoenix_Test *使用phoenix提供的api操彳hbase中讀取數(shù)據(jù)* author songyafei* param
35、args* throws Throwable* date 2015-03-25* /public static void main(String口 args) throws Throwable try /下面的驅(qū)動為 Phoenix老版本使用2.11使用,對應(yīng)hbase0.94+Class.forName("com.salesforce.phoenix.jdbc.PhoenixDriver");/phoenix4.3用下面的驅(qū)動對應(yīng)hbase0.98+Class.forName("org.apache.phoenix.jdbc.PhoenixDriver"); catch (Exception e) e.printStackTrace();這里配置zk的地址,可單個(gè),也可多個(gè)??梢允怯蛎蛘遡pString url = "jdbc
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 汽車經(jīng)營租賃合同范本
- 2025至2030年中國開啟式高壓汞燈鎮(zhèn)流器數(shù)據(jù)監(jiān)測研究報(bào)告
- 腦卒中個(gè)案康復(fù)護(hù)理
- 2025至2030年中國多維皮革立體工藝品數(shù)據(jù)監(jiān)測研究報(bào)告
- 2025至2030年中國口腔護(hù)理含漱液數(shù)據(jù)監(jiān)測研究報(bào)告
- 轉(zhuǎn)承包協(xié)議合同范本
- 大豆計(jì)劃采購合同范本
- 2025年中國青霉素鉀粉劑市場調(diào)查研究報(bào)告
- 2025年度汽車貸款逾期債務(wù)清收合作協(xié)議
- 2025年度智能醫(yī)療設(shè)備軟件技術(shù)服務(wù)合同
- 行為規(guī)范教育中學(xué)校長在國旗下講話:嚴(yán)格要求自己規(guī)范自己的行為
- 2024年12月廣東廣州市港務(wù)局直屬事業(yè)單位引進(jìn)緊缺專業(yè)人才8人筆試歷年典型考題(歷年真題考點(diǎn))解題思路附帶答案詳解
- 七下綜合世界真奇妙-共享“地球村”
- DBJ50-T-100-2022 建筑邊坡工程施工質(zhì)量驗(yàn)收標(biāo)準(zhǔn)
- 2025年寧夏工商職業(yè)技術(shù)學(xué)院高職單招職業(yè)適應(yīng)性測試近5年??及鎱⒖碱}庫含答案解析
- DB11-T 1004-2023 房屋建筑使用安全檢查評定技術(shù)規(guī)程
- 《藝術(shù)與傳播》課件
- 烹飪安全知識培訓(xùn)課件
- 2025年湖北宜昌枝江金潤源集團(tuán)招聘17人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2023CSCO兒童及青少年白血病診療指南
- 第一單元 閱讀綜合實(shí)踐(同步課件)【知識精研】七年級語文下冊高效課堂(統(tǒng)編版)
評論
0/150
提交評論