Hadoop生態圈-phoenix完全分布式部署
作者:尹正傑
版權聲明:原創作品,謝絕轉載!否則將追究法律責任。
phoenix只是一個插件,我們可以用hive給hbase套上一個JDBC殼,但是你有沒有體會到Hive執行SQL語句是很慢的,因此我們采用phoenix插件的方式給hbase套上JDBC的殼。
一.Phoenix簡介
1>.其實Phoenix可以看成是在hbase的hive,它是使用SQL方式訪問HBase數據;
2>.內置多種協處理器實現,輕松實現二級索引和聚合查詢;
二.部署phoenix
1>.下載phoenix插件
下載地址:http://www.apache.org/dyn/closer.lua/phoenix/
2>.解壓
[yinzhengjie@s101 data]$ tar zxf apache-phoenix-4.10.0-HBase-1.2-bin.tar.gz -C /soft/ [yinzhengjie@s101 data]$
3>.創建軟連接
[yinzhengjie@s101 data]$ ln -s /soft/apache-phoenix-4.10.0-HBase-1.2-bin/ /soft/phoenix [yinzhengjie@s101 data]$
4>.配置環境變量並使之生效
[yinzhengjie@s101 data]$ sudo vi /etc/profile [sudo] password for yinzhengjie: [yinzhengjie@s101 data]$ [yinzhengjie@s101 data]$ tail -3 /etc/profile #ADD PHOENIX PHOENIX_HOME=/soft/phoenix PATH=$PATH:$PHOENIX_HOME/bin [yinzhengjie@s101 data]$ [yinzhengjie@s101 data]$ source /etc/profile [yinzhengjie@s101 data]$
5>.將phoenix類庫放置在hbase的lib目錄,分發,並重啟hbase
[yinzhengjie@s101 ~]$ cp /soft/phoenix/phoenix-4.10.0-HBase-1.2-client.jar /soft/hbase/lib/ [yinzhengjie@s101 ~]$ xrsync.sh /soft/hbase/lib/phoenix-4.10.0-HBase-1.2-client.jar =========== s102 %file =========== 命令執行成功 =========== s103 %file =========== 命令執行成功 =========== s104 %file =========== 命令執行成功 =========== s105 %file =========== 命令執行成功 [yinzhengjie@s101 ~]$ more `which xrsync.sh` #!/bin/bash #@author :yinzhengjie #blog:http://www.cnblogs.com/yinzhengjie #EMAIL:y1053419035@qq.com #判斷用戶是否傳參 if [ $# -lt 1 ];then echo "請輸入參數"; exit fi #獲取文件路徑 file=$@ #獲取子路徑 filename=`basename $file` #獲取父路徑 dirpath=`dirname $file` #獲取完整路徑 cd $dirpath fullpath=`pwd -P` #同步文件到DataNode for (( i=102;i<=105;i++ )) do #使終端變綠色 tput setaf 2 echo =========== s$i %file =========== #使終端變回原來的顏色,即白灰色 tput setaf 7 #遠程執行命令 rsync -lr $filename `whoami`@s$i:$fullpath #判斷命令是否執行成功 if [ $? == 0 ];then echo "命令執行成功" fi done [yinzhengjie@s101 ~]$ stop-hbase.sh stopping hbase...................... [yinzhengjie@s101 ~]$ start-hbase.sh starting master, logging to /soft/hbase/bin/../logs/hbase-yinzhengjie-master-s101.out Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0 Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0 s103: starting regionserver, logging to /soft/hbase/bin/../logs/hbase-yinzhengjie-regionserver-s103.out s103: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0 s103: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0 s104: starting regionserver, logging to /soft/hbase/bin/../logs/hbase-yinzhengjie-regionserver-s104.out s102: starting regionserver, logging to /soft/hbase/bin/../logs/hbase-yinzhengjie-regionserver-s102.out s104: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0 s102: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0 s104: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0 s102: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0 [yinzhengjie@s101 ~]$
6>.啟動phoenix
三.phoenix的常用命令介紹
Phoenix的數據類型請參考官網:http://phoenix.apache.org/language/datatypes.html
Phoenix的分析函數請參考官網:http://phoenix.apache.org/language/functions.html
1>.啟動phoenix的命令行

1 [yinzhengjie@s101 shell]$ sqlline.py s102,s103,s104 2 Setting property: [incremental, false] 3 Setting property: [isolation, TRANSACTION_READ_COMMITTED] 4 issuing: !connect jdbc:phoenix:s102,s103,s104 none none org.apache.phoenix.jdbc.PhoenixDriver 5 Connecting to jdbc:phoenix:s102,s103,s104 6 SLF4J: Class path contains multiple SLF4J bindings. 7 SLF4J: Found binding in [jar:file:/soft/apache-phoenix-4.10.0-HBase-1.2-bin/phoenix-4.10.0-HBase-1.2-client.jar!/org/slf4j/impl/StaticLoggerBinder.class] 8 SLF4J: Found binding in [jar:file:/soft/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] 9 SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. 10 18/06/13 18:16:44 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 11 Connected to: Phoenix (version 4.10) 12 Driver: PhoenixEmbeddedDriver (version 4.10) 13 Autocommit status: true 14 Transaction isolation: TRANSACTION_READ_COMMITTED 15 Building list of tables and columns for tab-completion (set fastconnect to true to skip)... 16 91/91 (100%) Done 17 Done 18 sqlline version 1.2.0 19 0: jdbc:phoenix:s102,s103,s104>
2>.查看幫助信息

0: jdbc:phoenix:s102,s103,s104> !help !all Execute the specified SQL against all the current connections !autocommit Set autocommit mode on or off !batch Start or execute a batch of statements !brief Set verbose mode off !call Execute a callable statement !close Close the current connection to the database !closeall Close all current open connections !columns List all the columns for the specified table !commit Commit the current transaction (if autocommit is off) !connect Open a new connection to the database. !dbinfo Give metadata information about the database !describe Describe a table !dropall Drop all tables in the current database !exportedkeys List all the exported keys for the specified table !go Select the current connection !help Print a summary of command usage !history Display the command history !importedkeys List all the imported keys for the specified table !indexes List all the indexes for the specified table !isolation Set the transaction isolation for this connection !list List the current connections !manual Display the SQLLine manual !metadata Obtain metadata information !nativesql Show the native SQL for the specified statement !outputformat Set the output format for displaying results (table,vertical,csv,tsv,xmlattrs,xmlelements) !primarykeys List all the primary keys for the specified table !procedures List all the procedures !properties Connect to the database specified in the properties file(s) !quit Exits the program !reconnect Reconnect to the database !record Record all output to the specified file !rehash Fetch table and column names for command completion !rollback Roll back the current transaction (if autocommit is off) !run Run a script from the specified file !save Save the current variabes and aliases !scan Scan for installed JDBC drivers !script Start saving a script to a file !set Set a sqlline variable Variable Value Description =============== ========== ================================ autoCommit true/false Enable/disable automatic transaction commit autoSave true/false Automatically save preferences color true/false Control whether color is used for display fastConnect true/false Skip building table/column list for tab-completion force true/false Continue running script even after errors headerInterval integer The interval between which headers are displayed historyFile path File in which to save command history. Default is $HOME/.sqlline/history (UNIX, Linux, Mac OS), $HOME/sqlline/history (Windows) incremental true/false Do not receive all rows from server before printing the first row. Uses fewer resources, especially for long-running queries, but column widths may be incorrect. isolation LEVEL Set transaction isolation level maxColumnWidth integer The maximum width to use when displaying columns maxHeight integer The maximum height of the terminal maxWidth integer The maximum width of the terminal numberFormat pattern Format numbers using DecimalFormat pattern outputFormat table/vertical/csv/tsv Format mode for result display propertiesFile path File from which SqlLine reads properties on startup; default is $HOME/.sqlline/sqlline.properties (UNIX, Linux, Mac OS), $HOME/sqlline/sqlline.properties (Windows) rowLimit integer Maximum number of rows returned from a query; zero means no limit showElapsedTime true/false Display execution time when verbose showHeader true/false Show column names in query results showNestedErrs true/false Display nested errors showWarnings true/false Display connection warnings silent true/false Be more silent timeout integer Query timeout in seconds; less than zero means no timeout trimScripts true/false Remove trailing spaces from lines read from script files verbose true/false Show verbose error messages and debug info !sql Execute a SQL command !tables List all the tables in the database !typeinfo Display the type map for the current connection !verbose Set verbose mode on Comments, bug reports, and patches go to ??? 0: jdbc:phoenix:s102,s103,s104>
3>.退出phoenix命令行

0: jdbc:phoenix:s102,s103,s104> !q Closing: org.apache.phoenix.jdbc.PhoenixConnection [yinzhengjie@s101 shell]$
4>.列出當前已經存在的表

0: jdbc:phoenix:s102,s103,s104> !tables +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_NAME | SELF_REFERENCING_COL_NAME | REF_GENERATION | INDEX_STATE | IMMUTABLE_ROWS | SALT_BUCKETS | MULTI_TENANT | VIEW_STATE | +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ | | SYSTEM | CATALOG | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | FUNCTION | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | SEQUENCE | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | STATS | SYSTEM TABLE | | | | | | false | null | false | | +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ 0: jdbc:phoenix:s102,s103,s104>
5>.創建表(創建表時,TABLE_SCHEM和TABLE_NAME 默認均為大寫,如果想要指定小寫的話,需要加雙引號)

0: jdbc:phoenix:s102,s103,s104> create table yinzhengjie.t1(id integer primary key, name varchar, age integer); No rows affected (1.258 seconds) 0: jdbc:phoenix:s102,s103,s104> !tables +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_NAME | SELF_REFERENCING_COL_NAME | REF_GENERATION | INDEX_STATE | IMMUTABLE_ROWS | SALT_BUCKETS | MULTI_TENANT | VIEW_STATE | +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ | | SYSTEM | CATALOG | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | FUNCTION | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | SEQUENCE | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | STATS | SYSTEM TABLE | | | | | | false | null | false | | | | YINZHENGJIE | T1 | TABLE | | | | | | false | null | false | | +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ 0: jdbc:phoenix:s102,s103,s104>
6>.刪除表(刪除表時,TABLE_SCHEM和TABLE_NAME 默認均為大寫,如果想要指定小寫的話,需要加雙引號)

0: jdbc:phoenix:s102,s103,s104> !tables +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_NAME | SELF_REFERENCING_COL_NAME | REF_GENERATION | INDEX_STATE | IMMUTABLE_ROWS | SALT_BUCKETS | MULTI_TENANT | VIEW_STATE | +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ | | SYSTEM | CATALOG | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | FUNCTION | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | SEQUENCE | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | STATS | SYSTEM TABLE | | | | | | false | null | false | | | | YINZHENGJIE | T1 | TABLE | | | | | | false | null | false | | +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ 0: jdbc:phoenix:s102,s103,s104> drop table YINZHENGJIE.T1; No rows affected (3.513 seconds) 0: jdbc:phoenix:s102,s103,s104> !tables +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_NAME | SELF_REFERENCING_COL_NAME | REF_GENERATION | INDEX_STATE | IMMUTABLE_ROWS | SALT_BUCKETS | MULTI_TENANT | VIEW_STATE | +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ | | SYSTEM | CATALOG | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | FUNCTION | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | SEQUENCE | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | STATS | SYSTEM TABLE | | | | | | false | null | false | | +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ 0: jdbc:phoenix:s102,s103,s104>
7>.添加數據,和修改數據是同一個方法

0: jdbc:phoenix:s102,s103,s104> select * from yinzhengjie.t1; +-----+-------+------+ | ID | NAME | AGE | +-----+-------+------+ +-----+-------+------+ No rows selected (0.024 seconds) 0: jdbc:phoenix:s102,s103,s104> upsert into yinzhengjie.t1 values (1,'tom',20); 1 row affected (0.02 seconds) 0: jdbc:phoenix:s102,s103,s104> select * from yinzhengjie.t1; +-----+-------+------+ | ID | NAME | AGE | +-----+-------+------+ | 1 | tom | 20 | +-----+-------+------+ 1 row selected (0.04 seconds) 0: jdbc:phoenix:s102,s103,s104>
8>.刪除數據

0: jdbc:phoenix:s102,s103,s104> select * from yinzhengjie.t1; +-----+-------+------+ | ID | NAME | AGE | +-----+-------+------+ | 1 | tom | 20 | +-----+-------+------+ 1 row selected (0.03 seconds) 0: jdbc:phoenix:s102,s103,s104> delete from yinzhengjie.t1 where id=1; 1 row affected (0.011 seconds) 0: jdbc:phoenix:s102,s103,s104> select * from yinzhengjie.t1; +-----+-------+------+ | ID | NAME | AGE | +-----+-------+------+ +-----+-------+------+ No rows selected (0.024 seconds) 0: jdbc:phoenix:s102,s103,s104>
9>.查看表結構

0: jdbc:phoenix:s102,s103,s104> !describe yinzhengjie.t1 +------------+--------------+-------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----------------+-+ | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | COLUMN_NAME | DATA_TYPE | TYPE_NAME | COLUMN_SIZE | BUFFER_LENGTH | DECIMAL_DIGITS | NUM_PREC_RADIX | NULLABLE | REMARKS | COLUMN_DEF | SQL_DATA_TYPE | | +------------+--------------+-------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----------------+-+ | | YINZHENGJIE | T1 | ID | 4 | INTEGER | null | null | null | null | 0 | | | null | | | | YINZHENGJIE | T1 | NAME | 12 | VARCHAR | null | null | null | null | 1 | | | null | | | | YINZHENGJIE | T1 | AGE | 4 | INTEGER | null | null | null | null | 1 | | | null | | +------------+--------------+-------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----------------+-+ 0: jdbc:phoenix:s102,s103,s104>
10>.統計行號

0: jdbc:phoenix:s102,s103,s104> select * from yinzhengjie.t1 . . . . . . . . . . . . . . . > ; +-----+--------+------+ | ID | NAME | AGE | +-----+--------+------+ | 1 | tom | 20 | | 2 | tomon | 30 | | 3 | danny | 15 | | 4 | jenny | 35 | | 5 | jay | 45 | +-----+--------+------+ 5 rows selected (0.647 seconds) 0: jdbc:phoenix:s102,s103,s104> select count(*) from yinzhengjie.t1; +-----------+ | COUNT(1) | +-----------+ | 5 | +-----------+ 1 row selected (0.119 seconds) 0: jdbc:phoenix:s102,s103,s104>
11>.計算求和

0: jdbc:phoenix:s102,s103,s104> select * from yinzhengjie.t1; +-----+--------+------+ | ID | NAME | AGE | +-----+--------+------+ | 1 | tom | 20 | | 2 | tomon | 30 | | 3 | danny | 15 | | 4 | jenny | 35 | | 5 | jay | 45 | +-----+--------+------+ 5 rows selected (0.119 seconds) 0: jdbc:phoenix:s102,s103,s104> select sum(age) from yinzhengjie.t1; +-----------+ | SUM(AGE) | +-----------+ | 145 | +-----------+ 1 row selected (0.116 seconds) 0: jdbc:phoenix:s102,s103,s104>
12>.生產一個0~1的隨機數

0: jdbc:phoenix:s102,s103,s104> select rand(); +----------------------+ | RAND() | +----------------------+ | 0.44590536408194137 | +----------------------+ 1 row selected (0.001 seconds) 0: jdbc:phoenix:s102,s103,s104>
13>.截串操作

0: jdbc:phoenix:s102,s103,s104> select substr('yinzhengjie',4,5); +----------+ | 'zheng' | +----------+ | zheng | +----------+ 1 row selected (0 seconds) 0: jdbc:phoenix:s102,s103,s104>
14>.Phoenix與hbase表的映射關系

[yinzhengjie@s101 ~]$ hbase shell SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/soft/hbase-1.2.6/lib/phoenix-4.10.0-HBase-1.2-client.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/soft/hbase-1.2.6/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/soft/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/soft/apache-hive-2.1.1-bin/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. HBase Shell; enter 'help<RETURN>' for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell Version 1.2.6, rUnknown, Mon May 29 02:25:32 CDT 2017 hbase(main):001:0> create 'yinzhengjie:phoenix','f1','f2' 0 row(s) in 1.4400 seconds => Hbase::Table - yinzhengjie:phoenix hbase(main):002:0>

0: jdbc:phoenix:s102,s103,s104> !tables +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_NAME | SELF_REFERENCING_COL_NAME | REF_GENERATION | INDEX_STATE | IMMUTABLE_ROWS | SALT_BUCKETS | MULTI_TENANT | VIEW_STATE | +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ | | SYSTEM | CATALOG | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | FUNCTION | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | SEQUENCE | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | STATS | SYSTEM TABLE | | | | | | false | null | false | | | | YINZHENGJIE | T1 | TABLE | | | | | | false | null | false | | +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+ 0: jdbc:phoenix:s102,s103,s104> create table "yinzhengjie:phoenix"( "id" varchar primary key, "f1"."name" varchar, "f1"."age" unsigned_int ); No rows affected (6.134 seconds) 0: jdbc:phoenix:s102,s103,s104> !tables +------------+--------------+----------------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+---+ | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_NAME | SELF_REFERENCING_COL_NAME | REF_GENERATION | INDEX_STATE | IMMUTABLE_ROWS | SALT_BUCKETS | MULTI_TENANT | V | +------------+--------------+----------------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+---+ | | SYSTEM | CATALOG | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | FUNCTION | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | SEQUENCE | SYSTEM TABLE | | | | | | false | null | false | | | | SYSTEM | STATS | SYSTEM TABLE | | | | | | false | null | false | | | | | yinzhengjie:phoenix | TABLE | | | | | | false | null | false | | | | YINZHENGJIE | T1 | TABLE | | | | | | false | null | false | | +------------+--------------+----------------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+---+ 0: jdbc:phoenix:s102,s103,s104>

0: jdbc:phoenix:s102,s103,s104> upsert into "yinzhengjie:phoenix" values('row1','tom',20); 1 row affected (0.073 seconds) 0: jdbc:phoenix:s102,s103,s104> select * from "yinzhengjie:phoenix"; +-------+-------+------+ | id | name | age | +-------+-------+------+ | row1 | tom | 20 | +-------+-------+------+ 1 row selected (0.039 seconds) 0: jdbc:phoenix:s102,s103,s104>

hbase(main):003:0> scan 'yinzhengjie:phoenix' ROW COLUMN+CELL row1 column=f1:_0, timestamp=1528976336116, value=x row1 column=f1:age, timestamp=1528976336116, value=\x00\x00\x00\x14 row1 column=f1:name, timestamp=1528976336116, value=tom 1 row(s) in 0.1430 seconds hbase(main):004:0> put 'yinzhengjie:phoenix','row2','f1:age',30 0 row(s) in 0.0720 seconds hbase(main):005:0> scan 'yinzhengjie:phoenix' ROW COLUMN+CELL row1 column=f1:_0, timestamp=1528976336116, value=x row1 column=f1:age, timestamp=1528976336116, value=\x00\x00\x00\x14 row1 column=f1:name, timestamp=1528976336116, value=tom row2 column=f1:age, timestamp=1528976579187, value=30 2 row(s) in 0.0250 seconds hbase(main):006:0>
15>.簡單分析函數案例

hbase(main):029:0> create 'yinzhengjie:mapping2','f1','f2' 0 row(s) in 1.2260 seconds => Hbase::Table - yinzhengjie:mapping2 hbase(main):030:0>

0: jdbc:phoenix:s102,s103,s104> create table "yinzhengjie:mapping2"( "id" varchar primary key, "f1"."name" varchar, "f1"."age" unsigned_int ); No rows affected (5.901 seconds) 0: jdbc:phoenix:s102,s103,s104>

0: jdbc:phoenix:s102,s103,s104> upsert into "yinzhengjie:mapping2" values('row1','tom',10); 1 row affected (0.01 seconds) 0: jdbc:phoenix:s102,s103,s104> upsert into "yinzhengjie:mapping2" values('row2','tom',40); 1 row affected (0.008 seconds) 0: jdbc:phoenix:s102,s103,s104> upsert into "yinzhengjie:mapping2" values('row3','tom',30); 1 row affected (0.01 seconds) 0: jdbc:phoenix:s102,s103,s104> upsert into "yinzhengjie:mapping2" values('row4','tom',50); 1 row affected (0.009 seconds) 0: jdbc:phoenix:s102,s103,s104> select FIRST_VALUE("f1"."age") WITHIN GROUP(ORDER BY "f1"."age" desc) from "yinzhengjie:mapping2" ; +--------------------------------------+ | null("f1"."age", false, "f1"."age") | +--------------------------------------+ | 50 | +--------------------------------------+ 1 row selected (0.019 seconds) 0: jdbc:phoenix:s102,s103,s104>
注意,數據在Phoenix端插入,建議不要在HBase端手動插入,否則會拋出異常:“Error: ERROR 201 (22000): Illegal data. Expected length of at least 4 bytes, but had 2 (state=22000,code=201)”
16>.
17>.