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>.解压

  1. [yinzhengjie@s101 data]$ tar zxf apache-phoenix-4.10.-HBase-1.2-bin.tar.gz -C /soft/
  2. [yinzhengjie@s101 data]$

3>.创建软连接

  1. [yinzhengjie@s101 data]$ ln -s /soft/apache-phoenix-4.10.-HBase-1.2-bin/ /soft/phoenix
  2. [yinzhengjie@s101 data]$

4>.配置环境变量并使之生效

  1. [yinzhengjie@s101 data]$ sudo vi /etc/profile
  2. [sudo] password for yinzhengjie:
  3. [yinzhengjie@s101 data]$
  4. [yinzhengjie@s101 data]$ tail - /etc/profile
  5. #ADD PHOENIX
  6. PHOENIX_HOME=/soft/phoenix
  7. PATH=$PATH:$PHOENIX_HOME/bin
  8. [yinzhengjie@s101 data]$
  9. [yinzhengjie@s101 data]$ source /etc/profile
  10. [yinzhengjie@s101 data]$

5>.将phoenix类库放置在hbase的lib目录,分发,并重启hbase

  1. [yinzhengjie@s101 ~]$ cp /soft/phoenix/phoenix-4.10.-HBase-1.2-client.jar /soft/hbase/lib/
  2. [yinzhengjie@s101 ~]$ xrsync.sh /soft/hbase/lib/phoenix-4.10.-HBase-1.2-client.jar
  3. =========== s102 %file ===========
  4. 命令执行成功
  5. =========== s103 %file ===========
  6. 命令执行成功
  7. =========== s104 %file ===========
  8. 命令执行成功
  9. =========== s105 %file ===========
  10. 命令执行成功
  11. [yinzhengjie@s101 ~]$ more `which xrsync.sh`
  12. #!/bin/bash
  13. #@author :yinzhengjie
  14. #blog:http://www.cnblogs.com/yinzhengjie
  15. #EMAIL:y1053419035@qq.com
  16.  
  17. #判断用户是否传参
  18. if [ $# -lt ];then
  19. echo "请输入参数";
  20. exit
  21. fi
  22.  
  23. #获取文件路径
  24. file=$@
  25.  
  26. #获取子路径
  27. filename=`basename $file`
  28.  
  29. #获取父路径
  30. dirpath=`dirname $file`
  31.  
  32. #获取完整路径
  33. cd $dirpath
  34. fullpath=`pwd -P`
  35.  
  36. #同步文件到DataNode
  37. for (( i=;i<=;i++ ))
  38. do
  39. #使终端变绿色
  40. tput setaf
  41. echo =========== s$i %file ===========
  42. #使终端变回原来的颜色,即白灰色
  43. tput setaf
  44. #远程执行命令
  45. rsync -lr $filename `whoami`@s$i:$fullpath
  46. #判断命令是否执行成功
  47. if [ $? == ];then
  48. echo "命令执行成功"
  49. fi
  50. done
  51. [yinzhengjie@s101 ~]$ stop-hbase.sh
  52. stopping hbase......................
  53. [yinzhengjie@s101 ~]$ start-hbase.sh
  54. starting master, logging to /soft/hbase/bin/../logs/hbase-yinzhengjie-master-s101.out
  55. Java HotSpot(TM) -Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
  56. Java HotSpot(TM) -Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
  57. s103: starting regionserver, logging to /soft/hbase/bin/../logs/hbase-yinzhengjie-regionserver-s103.out
  58. s103: Java HotSpot(TM) -Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
  59. s103: Java HotSpot(TM) -Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
  60. s104: starting regionserver, logging to /soft/hbase/bin/../logs/hbase-yinzhengjie-regionserver-s104.out
  61. s102: starting regionserver, logging to /soft/hbase/bin/../logs/hbase-yinzhengjie-regionserver-s102.out
  62. s104: Java HotSpot(TM) -Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
  63. s102: Java HotSpot(TM) -Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
  64. s104: Java HotSpot(TM) -Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
  65. s102: Java HotSpot(TM) -Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
  66. [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.-HBase-1.2-bin/phoenix-4.10.-HBase-1.2-client.jar!/org/slf4j/impl/StaticLoggerBinder.class]
  8. SLF4J: Found binding in [jar:file:/soft/hadoop-2.7./share/hadoop/common/lib/slf4j-log4j12-1.7..jar!/org/slf4j/impl/StaticLoggerBinder.class]
  9. SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
  10. // :: 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. / (%) Done
  17. Done
  18. sqlline version 1.2.
  19. : jdbc:phoenix:s102,s103,s104>

[yinzhengjie@s101 shell]$ sqlline.py s102,s103,s104

2>.查看帮助信息

  1. : jdbc:phoenix:s102,s103,s104> !help
  2. !all Execute the specified SQL against all the current
  3. connections
  4. !autocommit Set autocommit mode on or off
  5. !batch Start or execute a batch of statements
  6. !brief Set verbose mode off
  7. !call Execute a callable statement
  8. !close Close the current connection to the database
  9. !closeall Close all current open connections
  10. !columns List all the columns for the specified table
  11. !commit Commit the current transaction (if autocommit is off)
  12. !connect Open a new connection to the database.
  13. !dbinfo Give metadata information about the database
  14. !describe Describe a table
  15. !dropall Drop all tables in the current database
  16. !exportedkeys List all the exported keys for the specified table
  17. !go Select the current connection
  18. !help Print a summary of command usage
  19. !history Display the command history
  20. !importedkeys List all the imported keys for the specified table
  21. !indexes List all the indexes for the specified table
  22. !isolation Set the transaction isolation for this connection
  23. !list List the current connections
  24. !manual Display the SQLLine manual
  25. !metadata Obtain metadata information
  26. !nativesql Show the native SQL for the specified statement
  27. !outputformat Set the output format for displaying results
  28. (table,vertical,csv,tsv,xmlattrs,xmlelements)
  29. !primarykeys List all the primary keys for the specified table
  30. !procedures List all the procedures
  31. !properties Connect to the database specified in the properties file(s)
  32. !quit Exits the program
  33. !reconnect Reconnect to the database
  34. !record Record all output to the specified file
  35. !rehash Fetch table and column names for command completion
  36. !rollback Roll back the current transaction (if autocommit is off)
  37. !run Run a script from the specified file
  38. !save Save the current variabes and aliases
  39. !scan Scan for installed JDBC drivers
  40. !script Start saving a script to a file
  41. !set Set a sqlline variable
  42.  
  43. Variable Value Description
  44. =============== ========== ================================
  45. autoCommit true/false Enable/disable automatic
  46. transaction commit
  47. autoSave true/false Automatically save preferences
  48. color true/false Control whether color is used
  49. for display
  50. fastConnect true/false Skip building table/column list
  51. for tab-completion
  52. force true/false Continue running script even
  53. after errors
  54. headerInterval integer The interval between which
  55. headers are displayed
  56. historyFile path File in which to save command
  57. history. Default is
  58. $HOME/.sqlline/history (UNIX,
  59. Linux, Mac OS),
  60. $HOME/sqlline/history (Windows)
  61. incremental true/false Do not receive all rows from
  62. server before printing the first
  63. row. Uses fewer resources,
  64. especially for long-running
  65. queries, but column widths may
  66. be incorrect.
  67. isolation LEVEL Set transaction isolation level
  68. maxColumnWidth integer The maximum width to use when
  69. displaying columns
  70. maxHeight integer The maximum height of the
  71. terminal
  72. maxWidth integer The maximum width of the
  73. terminal
  74. numberFormat pattern Format numbers using
  75. DecimalFormat pattern
  76. outputFormat table/vertical/csv/tsv Format mode for
  77. result display
  78. propertiesFile path File from which SqlLine reads
  79. properties on startup; default is
  80. $HOME/.sqlline/sqlline.properties
  81. (UNIX, Linux, Mac OS),
  82. $HOME/sqlline/sqlline.properties
  83. (Windows)
  84. rowLimit integer Maximum number of rows returned
  85. from a query; zero means no
  86. limit
  87. showElapsedTime true/false Display execution time when
  88. verbose
  89. showHeader true/false Show column names in query
  90. results
  91. showNestedErrs true/false Display nested errors
  92. showWarnings true/false Display connection warnings
  93. silent true/false Be more silent
  94. timeout integer Query timeout in seconds; less
  95. than zero means no timeout
  96. trimScripts true/false Remove trailing spaces from
  97. lines read from script files
  98. verbose true/false Show verbose error messages and
  99. debug info
  100. !sql Execute a SQL command
  101. !tables List all the tables in the database
  102. !typeinfo Display the type map for the current connection
  103. !verbose Set verbose mode on
  104.  
  105. Comments, bug reports, and patches go to ???
  106. : jdbc:phoenix:s102,s103,s104>

0: jdbc:phoenix:s102,s103,s104> !help

3>.退出phoenix命令行

  1. : jdbc:phoenix:s102,s103,s104> !q
  2. Closing: org.apache.phoenix.jdbc.PhoenixConnection
  3. [yinzhengjie@s101 shell]$

0: jdbc:phoenix:s102,s103,s104> !q

4>.列出当前已经存在的表

  1. : jdbc:phoenix:s102,s103,s104> !tables
  2. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  3. | 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 |
  4. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  5. | | SYSTEM | CATALOG | SYSTEM TABLE | | | | | | false | null | false | |
  6. | | SYSTEM | FUNCTION | SYSTEM TABLE | | | | | | false | null | false | |
  7. | | SYSTEM | SEQUENCE | SYSTEM TABLE | | | | | | false | null | false | |
  8. | | SYSTEM | STATS | SYSTEM TABLE | | | | | | false | null | false | |
  9. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  10. : jdbc:phoenix:s102,s103,s104>

0: jdbc:phoenix:s102,s103,s104> !tables

5>.创建表(创建表时,TABLE_SCHEM和TABLE_NAME 默认均为大写,如果想要指定小写的话,需要加双引号)

  1. : jdbc:phoenix:s102,s103,s104> create table yinzhengjie.t1(id integer primary key, name varchar, age integer);
  2. No rows affected (1.258 seconds)
  3. : jdbc:phoenix:s102,s103,s104> !tables
  4. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  5. | 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 |
  6. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  7. | | SYSTEM | CATALOG | SYSTEM TABLE | | | | | | false | null | false | |
  8. | | SYSTEM | FUNCTION | SYSTEM TABLE | | | | | | false | null | false | |
  9. | | SYSTEM | SEQUENCE | SYSTEM TABLE | | | | | | false | null | false | |
  10. | | SYSTEM | STATS | SYSTEM TABLE | | | | | | false | null | false | |
  11. | | YINZHENGJIE | T1 | TABLE | | | | | | false | null | false | |
  12. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  13. : jdbc:phoenix:s102,s103,s104>

0: jdbc:phoenix:s102,s103,s104> create table yinzhengjie.t1(id integer primary key, name varchar, age integer);

6>.删除表(删除表时,TABLE_SCHEM和TABLE_NAME 默认均为大写,如果想要指定小写的话,需要加双引号)

  1. : jdbc:phoenix:s102,s103,s104> !tables
  2. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  3. | 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 |
  4. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  5. | | SYSTEM | CATALOG | SYSTEM TABLE | | | | | | false | null | false | |
  6. | | SYSTEM | FUNCTION | SYSTEM TABLE | | | | | | false | null | false | |
  7. | | SYSTEM | SEQUENCE | SYSTEM TABLE | | | | | | false | null | false | |
  8. | | SYSTEM | STATS | SYSTEM TABLE | | | | | | false | null | false | |
  9. | | YINZHENGJIE | T1 | TABLE | | | | | | false | null | false | |
  10. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  11. : jdbc:phoenix:s102,s103,s104> drop table YINZHENGJIE.T1;
  12. No rows affected (3.513 seconds)
  13. : jdbc:phoenix:s102,s103,s104> !tables
  14. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  15. | 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 |
  16. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  17. | | SYSTEM | CATALOG | SYSTEM TABLE | | | | | | false | null | false | |
  18. | | SYSTEM | FUNCTION | SYSTEM TABLE | | | | | | false | null | false | |
  19. | | SYSTEM | SEQUENCE | SYSTEM TABLE | | | | | | false | null | false | |
  20. | | SYSTEM | STATS | SYSTEM TABLE | | | | | | false | null | false | |
  21. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  22. : jdbc:phoenix:s102,s103,s104>

0: jdbc:phoenix:s102,s103,s104> drop table YINZHENGJIE.T1;

7>.添加数据,和修改数据是同一个方法

  1. : jdbc:phoenix:s102,s103,s104> select * from yinzhengjie.t1;
  2. +-----+-------+------+
  3. | ID | NAME | AGE |
  4. +-----+-------+------+
  5. +-----+-------+------+
  6. No rows selected (0.024 seconds)
  7. : jdbc:phoenix:s102,s103,s104> upsert into yinzhengjie.t1 values (,'tom',);
  8. row affected (0.02 seconds)
  9. : jdbc:phoenix:s102,s103,s104> select * from yinzhengjie.t1;
  10. +-----+-------+------+
  11. | ID | NAME | AGE |
  12. +-----+-------+------+
  13. | | tom | |
  14. +-----+-------+------+
  15. row selected (0.04 seconds)
  16. : jdbc:phoenix:s102,s103,s104>

0: jdbc:phoenix:s102,s103,s104> upsert into yinzhengjie.t1 values (1,'tom',20);

8>.删除数据

  1. : jdbc:phoenix:s102,s103,s104> select * from yinzhengjie.t1;
  2. +-----+-------+------+
  3. | ID | NAME | AGE |
  4. +-----+-------+------+
  5. | | tom | |
  6. +-----+-------+------+
  7. row selected (0.03 seconds)
  8. : jdbc:phoenix:s102,s103,s104> delete from yinzhengjie.t1 where id=;
  9. row affected (0.011 seconds)
  10. : jdbc:phoenix:s102,s103,s104> select * from yinzhengjie.t1;
  11. +-----+-------+------+
  12. | ID | NAME | AGE |
  13. +-----+-------+------+
  14. +-----+-------+------+
  15. No rows selected (0.024 seconds)
  16. : jdbc:phoenix:s102,s103,s104>

0: jdbc:phoenix:s102,s103,s104> delete from yinzhengjie.t1 where id=1;

9>.查看表结构

  1. : jdbc:phoenix:s102,s103,s104> !describe yinzhengjie.t1
  2. +------------+--------------+-------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----------------+-+
  3. | 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 | |
  4. +------------+--------------+-------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----------------+-+
  5. | | YINZHENGJIE | T1 | ID | | INTEGER | null | null | null | null | | | | null | |
  6. | | YINZHENGJIE | T1 | NAME | | VARCHAR | null | null | null | null | | | | null | |
  7. | | YINZHENGJIE | T1 | AGE | | INTEGER | null | null | null | null | | | | null | |
  8. +------------+--------------+-------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----------------+-+
  9. : jdbc:phoenix:s102,s103,s104>

0: jdbc:phoenix:s102,s103,s104> !describe yinzhengjie.t1

10>.统计行号

  1. : jdbc:phoenix:s102,s103,s104> select * from yinzhengjie.t1
  2. . . . . . . . . . . . . . . . > ;
  3. +-----+--------+------+
  4. | ID | NAME | AGE |
  5. +-----+--------+------+
  6. | | tom | |
  7. | | tomon | |
  8. | | danny | |
  9. | | jenny | |
  10. | | jay | |
  11. +-----+--------+------+
  12. rows selected (0.647 seconds)
  13. : jdbc:phoenix:s102,s103,s104> select count(*) from yinzhengjie.t1;
  14. +-----------+
  15. | COUNT() |
  16. +-----------+
  17. | |
  18. +-----------+
  19. row selected (0.119 seconds)
  20. : jdbc:phoenix:s102,s103,s104>

0: jdbc:phoenix:s102,s103,s104> select count(*) from yinzhengjie.t1;

11>.计算求和

  1. : jdbc:phoenix:s102,s103,s104> select * from yinzhengjie.t1;
  2. +-----+--------+------+
  3. | ID | NAME | AGE |
  4. +-----+--------+------+
  5. | | tom | |
  6. | | tomon | |
  7. | | danny | |
  8. | | jenny | |
  9. | | jay | |
  10. +-----+--------+------+
  11. rows selected (0.119 seconds)
  12. : jdbc:phoenix:s102,s103,s104> select sum(age) from yinzhengjie.t1;
  13. +-----------+
  14. | SUM(AGE) |
  15. +-----------+
  16. | |
  17. +-----------+
  18. row selected (0.116 seconds)
  19. : jdbc:phoenix:s102,s103,s104>

0: jdbc:phoenix:s102,s103,s104> select sum(age) from yinzhengjie.t1;

12>.生产一个0~1的随机数

  1. : jdbc:phoenix:s102,s103,s104> select rand();
  2. +----------------------+
  3. | RAND() |
  4. +----------------------+
  5. | 0.44590536408194137 |
  6. +----------------------+
  7. row selected (0.001 seconds)
  8. : jdbc:phoenix:s102,s103,s104>

0: jdbc:phoenix:s102,s103,s104> select rand();

13>.截串操作

  1. : jdbc:phoenix:s102,s103,s104> select substr('yinzhengjie',,);
  2. +----------+
  3. | 'zheng' |
  4. +----------+
  5. | zheng |
  6. +----------+
  7. row selected ( seconds)
  8. : jdbc:phoenix:s102,s103,s104>

0: jdbc:phoenix:s102,s103,s104> select substr('yinzhengjie',4,5);

14>.Phoenix与hbase表的映射关系

  1. [yinzhengjie@s101 ~]$ hbase shell
  2. SLF4J: Class path contains multiple SLF4J bindings.
  3. SLF4J: Found binding in [jar:file:/soft/hbase-1.2./lib/phoenix-4.10.-HBase-1.2-client.jar!/org/slf4j/impl/StaticLoggerBinder.class]
  4. SLF4J: Found binding in [jar:file:/soft/hbase-1.2./lib/slf4j-log4j12-1.7..jar!/org/slf4j/impl/StaticLoggerBinder.class]
  5. SLF4J: Found binding in [jar:file:/soft/hadoop-2.7./share/hadoop/common/lib/slf4j-log4j12-1.7..jar!/org/slf4j/impl/StaticLoggerBinder.class]
  6. SLF4J: Found binding in [jar:file:/soft/apache-hive-2.1.-bin/lib/log4j-slf4j-impl-2.4..jar!/org/slf4j/impl/StaticLoggerBinder.class]
  7. SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
  8. HBase Shell; enter 'help<RETURN>' for list of supported commands.
  9. Type "exit<RETURN>" to leave the HBase Shell
  10. Version 1.2., rUnknown, Mon May :: CDT
  11.  
  12. hbase(main)::> create 'yinzhengjie:phoenix','f1','f2'
  13. row(s) in 1.4400 seconds
  14.  
  15. => Hbase::Table - yinzhengjie:phoenix
  16. hbase(main)::>

新建HBase表(hbase(main):001:0> create 'yinzhengjie:phoenix','f1','f2')

  1. : jdbc:phoenix:s102,s103,s104> !tables
  2. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  3. | 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 |
  4. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  5. | | SYSTEM | CATALOG | SYSTEM TABLE | | | | | | false | null | false | |
  6. | | SYSTEM | FUNCTION | SYSTEM TABLE | | | | | | false | null | false | |
  7. | | SYSTEM | SEQUENCE | SYSTEM TABLE | | | | | | false | null | false | |
  8. | | SYSTEM | STATS | SYSTEM TABLE | | | | | | false | null | false | |
  9. | | YINZHENGJIE | T1 | TABLE | | | | | | false | null | false | |
  10. +------------+--------------+-------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+------------+
  11. : jdbc:phoenix:s102,s103,s104> create table "yinzhengjie:phoenix"( "id" varchar primary key, "f1"."name" varchar, "f1"."age" unsigned_int );
  12. No rows affected (6.134 seconds)
  13. : jdbc:phoenix:s102,s103,s104> !tables
  14. +------------+--------------+----------------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+---+
  15. | 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 |
  16. +------------+--------------+----------------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+---+
  17. | | SYSTEM | CATALOG | SYSTEM TABLE | | | | | | false | null | false | |
  18. | | SYSTEM | FUNCTION | SYSTEM TABLE | | | | | | false | null | false | |
  19. | | SYSTEM | SEQUENCE | SYSTEM TABLE | | | | | | false | null | false | |
  20. | | SYSTEM | STATS | SYSTEM TABLE | | | | | | false | null | false | |
  21. | | | yinzhengjie:phoenix | TABLE | | | | | | false | null | false | |
  22. | | YINZHENGJIE | T1 | TABLE | | | | | | false | null | false | |
  23. +------------+--------------+----------------------+---------------+----------+------------+----------------------------+-----------------+--------------+-----------------+---------------+---------------+---+
  24. : jdbc:phoenix:s102,s103,s104>

创建映射关系(0: jdbc:phoenix:s102,s103,s104> create table "yinzhengjie:phoenix"( "id" varchar primary key, "f1"."name" varchar, "f1"."age" unsigned_int );)

  1. : jdbc:phoenix:s102,s103,s104> upsert into "yinzhengjie:phoenix" values('row1','tom',);
  2. row affected (0.073 seconds)
  3. : jdbc:phoenix:s102,s103,s104> select * from "yinzhengjie:phoenix";
  4. +-------+-------+------+
  5. | id | name | age |
  6. +-------+-------+------+
  7. | row1 | tom | |
  8. +-------+-------+------+
  9. row selected (0.039 seconds)
  10. : jdbc:phoenix:s102,s103,s104>

Phoenix插入数据并查看(0: jdbc:phoenix:s102,s103,s104> upsert into "yinzhengjie:phoenix" values('row1','tom',20);)

  1. hbase(main)::> scan 'yinzhengjie:phoenix'
  2. ROW COLUMN+CELL
  3. row1 column=f1:_0, timestamp=, value=x
  4. row1 column=f1:age, timestamp=, value=\x00\x00\x00\x14
  5. row1 column=f1:name, timestamp=, value=tom
  6. row(s) in 0.1430 seconds
  7.  
  8. hbase(main)::> put 'yinzhengjie:phoenix','row2','f1:age',
  9. row(s) in 0.0720 seconds
  10.  
  11. hbase(main)::> scan 'yinzhengjie:phoenix'
  12. ROW COLUMN+CELL
  13. row1 column=f1:_0, timestamp=, value=x
  14. row1 column=f1:age, timestamp=, value=\x00\x00\x00\x14
  15. row1 column=f1:name, timestamp=, value=tom
  16. row2 column=f1:age, timestamp=, value=
  17. row(s) in 0.0250 seconds
  18.  
  19. hbase(main)::>

HBase插入数据并查看(hbase(main):004:0> put 'yinzhengjie:phoenix','row2','f1:age',30)

15>.简单分析函数案例

  1. hbase(main)::> create 'yinzhengjie:mapping2','f1','f2'
  2. row(s) in 1.2260 seconds
  3.  
  4. => Hbase::Table - yinzhengjie:mapping2
  5. hbase(main)::>

新建HBase表(hbase(main):029:0> create 'yinzhengjie:mapping2','f1','f2')

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

创建映射关系(0: jdbc:phoenix:s102,s103,s104> create table "yinzhengjie:mapping2"( "id" varchar primary key, "f1"."name" varchar, "f1"."age" unsigned_int );)

  1. : jdbc:phoenix:s102,s103,s104> upsert into "yinzhengjie:mapping2" values('row1','tom',);
  2. row affected (0.01 seconds)
  3. : jdbc:phoenix:s102,s103,s104> upsert into "yinzhengjie:mapping2" values('row2','tom',);
  4. row affected (0.008 seconds)
  5. : jdbc:phoenix:s102,s103,s104> upsert into "yinzhengjie:mapping2" values('row3','tom',);
  6. row affected (0.01 seconds)
  7. : jdbc:phoenix:s102,s103,s104> upsert into "yinzhengjie:mapping2" values('row4','tom',);
  8. row affected (0.009 seconds)
  9. : jdbc:phoenix:s102,s103,s104> select FIRST_VALUE("f1"."age") WITHIN GROUP(ORDER BY "f1"."age" desc) from "yinzhengjie:mapping2" ;
  10. +--------------------------------------+
  11. | null("f1"."age", false, "f1"."age") |
  12. +--------------------------------------+
  13. | |
  14. +--------------------------------------+
  15. row selected (0.019 seconds)
  16. : jdbc:phoenix:s102,s103,s104>

简单分析函数案例(0: jdbc:phoenix:s102,s103,s104> select FIRST_VALUE("f1"."age") WITHIN GROUP(ORDER BY "f1"."age" desc) from "yinzhengjie:mapping2" ;)

  注意,数据在Phoenix端插入,建议不要在HBase端手动插入,否则会抛出异常:“Error: ERROR 201 (22000): Illegal data. Expected length of at least 4 bytes, but had 2 (state=22000,code=201)”

16>.

17>.

Hadoop生态圈-phoenix完全分布式部署以及常用命令介绍的更多相关文章

  1. Hadoop生态圈-zookeeper完全分布式部署

    Hadoop生态圈-zookeeper完全分布式部署 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客部署是建立在Hadoop高可用基础之上的,关于Hadoop高可用部署请参 ...

  2. Hadoop 2.6.0分布式部署參考手冊

    Hadoop 2.6.0分布式部署參考手冊 关于本參考手冊的word文档.能够到例如以下地址下载:http://download.csdn.net/detail/u012875880/8291493 ...

  3. Hadoop生态圈-CentOs7.5单机部署ClickHouse

    Hadoop生态圈-CentOs7.5单机部署ClickHouse 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 到了新的公司,认识了新的同事,生产环境也得你去适应新的集群环境,我 ...

  4. Hadoop生态圈-zookeeper本地搭建以及常用命令介绍

    Hadoop生态圈-zookeeper本地搭建以及常用命令介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.下载zookeeper软件 下载地址:https://www.ap ...

  5. Hadoop生态圈-phoenix的视图(view)管理

    Hadoop生态圈-phoenix的视图(view)管理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.

  6. Hadoop生态圈-phoenix(HBase)的索引配置

    Hadoop生态圈-phoenix(HBase)的索引配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 创建索引是为了优化查询,我们可以在phoenix上配置索引方式. 一.修改 ...

  7. maven常用命令介绍

    mvn 3.0.4 创建maven项目命令  mvn  archetype:generate   -DgroupId=damocles-autocredit -DartifactId=damocles ...

  8. 转:maven常用命令介绍

    mvn 3.0.4 创建maven项目命令  mvn  archetype:generate   -DgroupId=damocles-autocredit -DartifactId=damocles ...

  9. Docker 安装与常用命令介绍

    docker的镜像文件作用就是:提供container运行的文件系统层级关系(基于AUFS实现),所依赖的库文件.已经配置文件等等. 安装docker yum install -y docker 启动 ...

随机推荐

  1. java实验五实验报告

    一.实验内容 Cmp传输与加解密 结对编程,一人服务器,一人客户端,服务器向客户端发送经RSA加密的密钥和用密钥加密的密文(使用DES算法),客户端负责接收加密后的密钥和密文,并解密得出明文. 二.实 ...

  2. 【转】Verilog HDL常用建模方式——《Verilog与数字ASIC设计基础》读书笔记(四)

    Verilog HDL常用建模方式——<Verilog与数字ASIC设计基础>读书笔记(四) Verilog HDL的基本功能之一是描述可综合的硬件逻辑电路.所谓综合(Synthesis) ...

  3. RabbitMQ使用笔记

    一.安装 1.下载所需安装包 下载服务端(原因在于RabbitMQ服务端代码是使用并发式语言erlang编写的):http://www.rabbitmq.com/install-windows.htm ...

  4. 微服务架构之思维三部曲:What、Why、How

    本文转自:http://www.servicemesh.cn/?/article/49 What:什么是微服务? 某百科对微服务架构的定义和阐述:微服务可以在“自己的程序”中运行,并通过“轻量级设备与 ...

  5. 如何实现MySQL表数据随机读取?从mysql表中读取随机数据

    文章转自 http://blog.efbase.org/2006/10/16/244/如何实现MySQL表数据随机读取?从mysql表中读取随机数据?以前在群里讨论过这个问题,比较的有意思.mysql ...

  6. Win2019 IPV6 支持存在问题

    1. 昨天晚上尝试 使用IPV6进行Oracle与SQLserver 的链接测试.从晚上六点到晚上八点测试环境一直不通. 后来换了服务器之后发现立即就可以了. 经过简单确认 怀疑Win server ...

  7. dotnet core sdk 2.1 在centos下的安装

    1. 安装微软的仓库 rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm 2. 修改仓库 ...

  8. 事件ID:7026(“下列引导或系统启动驱动程序无法加载: cdrom”)的解决方法

     电脑没有安装光驱,而是使用USB光驱/虚拟光驱软件,每次开机后"事件查看器"都显示错误:"下列引导或系统启动驱动程序无法加载: cdrom"(事件ID:7 ...

  9. 反Nim博弈

    原文地址:https://blog.csdn.net/xuejye/article/details/78975900 在尼姆博奕中取完最后一颗糖的人为赢家,而取到最后一颗糖为输家的就是反尼姆博奕.这道 ...

  10. hbase 多个过滤器组合(列表)

    使用FilterList要保证过滤器的顺序需要使用List<Filter> private static void mutilFilterData() throws IOException ...