HBAse 5、Phoenix使用
8101 ワード
1、建表
2、データのインポート
3、クエリーデータ
まずsqllineを使用して(一部の列のデータを切り取る)、クエリー・テーブル名は大文字と小文字を区別しません.
クエリー1、クエリーのすべてのレコード
文:select * from web_stat;
クエリ2、クエリレコードの合計数
文:select count(1) from web_stat;
クエリー3、クエリー結果のグループ化ソート
文:select domain,count(1) as num from web_stat group by domain order by num desc;
クエリ4、平均値を求める
文:select avg(core) from web_stat;
クエリー5、マルチフィールドグループ化、ソート、別名.
文:select domain,count(1) as num,avg(core) as core,avg(db) as db from web_stat group by domain order by num desc;
クエリー6、クエリー日付タイプフィールド
文:select host,domain,date from web_stat where TO_CHAR(date)='2013-01-15 07:09:01.000';
クエリー7、文字列、日付タイプ変換
文:select TO_DATE('20131125','yyyyMMdd') from web_stat;
Ps:入力した日付文字列はhbaseテーブルdateの日付タイプに変換されます.
まとめ:Phoenixは多くの関数とsql構文をサポートしており、ここでは一つ一つ列挙しません.詳細はPhoenixサポートセクションを参照してください
4、Phoenix基本shellコマンド
PS:以下、一部のコマンドがPhoenix以降で失効した場合がありますので、他のコマンドに変更してください.
$ ./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 VARCHAR NOT NULL,
DATE DATE NOT NULL,
USAGE.CORE BIGINT,--usage
USAGE.DB BIGINT,--usage
STATS.ACTIVE_VISITOR INTEGER
CONSTRAINT PK PRIMARY KEY (HOST, DOMAIN, FEATURE, DATE)--
);
2、データのインポート
:./psql.py -t WEB_STAT localhost:2181 ../examples/web_stat.csv
PS: -t , ../examples/web_stat.csv csv ( )。
3、クエリーデータ
まずsqllineを使用して(一部の列のデータを切り取る)、クエリー・テーブル名は大文字と小文字を区別しません.
クエリー1、クエリーのすべてのレコード
文:select * from web_stat;
クエリ2、クエリレコードの合計数
文:select count(1) from web_stat;
クエリー3、クエリー結果のグループ化ソート
文:select domain,count(1) as num from web_stat group by domain order by num desc;
クエリ4、平均値を求める
文:select avg(core) from web_stat;
クエリー5、マルチフィールドグループ化、ソート、別名.
文:select domain,count(1) as num,avg(core) as core,avg(db) as db from web_stat group by domain order by num desc;
クエリー6、クエリー日付タイプフィールド
文:select host,domain,date from web_stat where TO_CHAR(date)='2013-01-15 07:09:01.000';
クエリー7、文字列、日付タイプ変換
文:select TO_DATE('20131125','yyyyMMdd') from web_stat;
Ps:入力した日付文字列はhbaseテーブルdateの日付タイプに変換されます.
まとめ:Phoenixは多くの関数とsql構文をサポートしており、ここでは一つ一つ列挙しません.詳細はPhoenixサポートセクションを参照してください
4、Phoenix基本shellコマンド
PS:以下、一部のコマンドがPhoenix以降で失効した場合がありますので、他のコマンドに変更してください.
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 Phoenix4.3 !exit
!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