hive 學習筆記精簡

來源:互聯網
上載者:User

標籤: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表示從第一個開始取)  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.