Phoenix的团队用了一句话概括Phoenix:“We put the SQL back in NoSQL” 意思是:我们把SQL又放回NoSQL去了!这边说的NoSQL专指HBase,意思是可以用SQL语句来查询Hbase,你可能会说:“Hive和Impala也可以啊!”。但是Hive和Impala还可以查询文本文件,Phoenix的特点就是,它只能查Hbase,别的类型都不支持!但是也因为这种专一的态度,让Phoenix在Hbase上查询的性能超过了Hive和Impala!
1.具有完整ACID事务功能的标准SQL和JDBC API的强大功能 2.通过利用HBase,使得NoSQL读取更加灵活 3.Apache Phoenix与其他Hadoop产品完全集成,如Spark,Hive,Pig,Flume和Map Reduce。
安装地址 官网 http://apache.fayea.com/phoenix/ (注意:hbase的版本一定要与phoenix的版本保持一致,否则运行报错,hbase-0.99没有相关的版本下载)CDH安装 下载CDH版Phoenix (需要自己编译) https://github.com/chiastic-security/phoenix-for-cloudera/tree/4.8-HBase-1.2-cdh5.8 http://blog.stone-head.org/apache-phoenix-for-cloudera-cdh/ 安装过程 下载,解压后,把phoenix-{version}-server.jar拷贝到hbase的同级lib目录下,重启hbase运行过程 在phoenix-{version}/bin 目录下 $ ./sqlline.py localhost可以进入命令行模式
0: jdbc:phoenix:localhost>退出命令行的方式是执行 !quit
0: jdbc:phoenix:localhost>!quit 0: jdbc:phoenix:localhost> 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 !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 使用过程 Start Sqlline: $ sqlline.py [zookeeper] - Execute the following statements when Sqlline connects: 创建表
create table test (mykey integer not null primary key, mycolumn varchar);增加,修改表数据
upsert into test values (1,'Hello'); upsert into test values (2,'World!');查询表数据
select * from test;删除表(如果是建立表,则同时删除phoenix与hbase表数据,如果是建立view,则不删除hbase的数据)
drop table test 导入测试数据 csv导入(适用于导入少量数据) bin/./psql.py -t {表名} {zookeeper地址} xx.csvmr导入(适用于导入大量数据) 建立测试数据 xx.txt上传到hdfs上面在phoenix当前的文件夹下面,执行以下命令 HADOOP_CLASSPATH=/root/apps/phoenix/phoenix-4.8.0-cdh5.8.0/lib/hbase-protocol-1.2.0-cdh5.8.0.jar:/etc/hbase/conf hadoop jar phoenix-4.8.0-cdh5.8.0-client.jar org.apache.phoenix.mapreduce.CsvBulkLoadTool -t {表名} -i hdfs:///phoenix/data/data.csv -z {zookeeper地址}:2181