Hive匯入和匯出資料

來源:互聯網
上載者:User

hive官方提供兩種匯入資料的方式

1 從表中匯入:

insert overwrite table test

select * from test2;

2 從檔案匯入:

2.1 從本地檔案匯入:

load data local inpath '/Hadoop/aa.txt' overwrite into table test11

2.2  從hdfs匯入

load data inpath '/hadoop/aa.txt' overwrite into table test11

3 匯入檔案的列劃分

在建表的時候可以指定劃分的字元 如:

create table test11(id int,name string)

row format delimited

fields terminated by '\;' 以分號劃分檔案的列這樣匯入的資料檔案就如同 1;張三 這種格式。

4 到出資料

一般用 :bin/hive -e "select * from test" >> res.csv

或者:bin/hive -f sql.q >> res.csv (其中檔案sql.q寫入你想要執行的查詢語句)

5 中文亂碼問題

hive預設的字元編碼是utf8格式,所以用utf8模式儲存的資料都是可以正常顯示的,如果用ssh用戶端工具查看時仍是亂碼,這可能是你的用戶端工具的編碼方式決定的,以secureCRT為例,修改 session options -》apperance (這樣不影響其他session的編碼方式),當然 linux系統也需要做一下簡單的支援utf8的設定(這個一般都支援)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.