標籤:des style color 使用 資料 2014
建立表:drop table t
create table if not exists t (t string) partitioned by (log_date string) row format delimited fields terminated by ‘\t‘ lines terminated by ‘\n‘ create table t1 like t create table t2 as select * from t //如果加多餘的欄位或者加group by等關鍵字會報錯 裝載資料:load data local inpath ‘/opt/aimcpro/libc/first.txt‘ into table test_libc_20140711_1; insert overwrite into table tt partition(ds=‘{$begin}‘)
動態分區插入:insert overwrite tpartition (contry)select ... ,se.ctyfrom emp se 一次性從表中匯入多個分區:from table tinsert overwrite table em (p=a)select * from t where p=ainsert overwrite table em (p=b)select * from t where p=b
匯出資料:insert overwrite local dirctory ‘/tmp‘select * from t 或者:hadoop fs -cp sr des 表產生函數:結合Regex可以對文本詞統計 浮點數自動轉化問題 顯示類型轉換: cast(salary as float) mysql匯出遠端資料:mysql -h 10.199.82.31 -P 3304 -umns -pmns mns -e" select UID,NOTICETYPE from SUBSCRIBEINFO where NOTICETYPE=403 or NOTICETYPE=4 or NOTICETYPE=304;" > user_notify.lst Regex抽取:regexp_extract(col2,‘(\\d*)(:)0‘,0)匹配值為:12345678901:0 在hive中執行dfs命令:只需將hadoop關鍵字去掉即可 實現隨機抽樣: 對資料做標記後再對標記隨機排序select user_device from (select user_device from (select user_device,"1" flag from test_libc_t) t distribute by t.flag sort by t.flag,rand()) tt limit 100 調整日誌輸出層級,sql出錯時可以得到詳細錯誤資訊: hive --hiveconf hive.root.logger=DEBUG,console 只針對當前回話修改 桶為表分區的更細粒度劃分,建立帶桶的表: create table bucketed_user(id int,name string) clustered by (id) sorted by(name) into 4 buckets row format delimited fields terminated by ‘\t‘ stored as textfile; 在這裡,我們使用使用者ID來確定如何劃分桶對桶中的資料進行採樣:hive> SELECT * FROM bucketed_users
> TABLESAMPLE(BUCKET 1 OUT OF 4 ON id); 即區第一個桶的資料(4/4=1表示取一個桶的資料,1表示從第一個開始取)