如何將Hive倉庫中的查詢結果匯出到本地檔案

2021-08-22 08:21:24 字數 1637 閱讀 4952

我在hive倉庫中有個表,已經使用hql跑出來結果,存到了hive中。表的schema如下

show create table test_xiaoxiannv.dw_clickadvert_daily;

create external table test_xiaoxiannv.dw_clickadvert_daily(

id int,

ip string,

time string,

action string,

dm string,

pnum int,

a0 string,

a1 string,

a2 string,

a3 string,

a4 string,

a5 string,

a6 string,

a7 string,

a8 string,

a9 string,

a10 string,

a11 string,

a12 string,

a13 string,

a14 string,

a15 string)

partitioned by (

dt date)

row format delimited

fields terminated by

','

stored as inputformat

'org.apache.hadoop.mapred.textinputformat'

outputformat

'org.apache.hadoop.hive.ql.io.hiveignorekeytextoutputformat'

location

tblproperties (

'transient_lastddltime'='1533263442')

可以看到,分隔符是逗號,

那麼匯出成csv檔案就很方便了,操作步驟如下:

使用 /bin/hive -e 「hql」 >> target_file_path.csv | 或者使用 /bin/hive -f sql.q >> target_file_path.csv

[hive@tony-client ~]$ hive -e "select * from test_xiaoxiannv.dw_clickadvert_daily" >> ~/test_xiaoxiannv.dw_clickadvert_daily.csv

logging initialized using configuration in file:/etc/hive/2.5

.0.0-1245/0/hive-log4j.properties

oktime taken: 3.09 seconds, fetched: 322914 row(s)

[hive@tony-client ~]$ wc -l ~/test_xiaoxiannv.dw_clickadvert_daily.csv

322914 /home/hive/test_xiaoxiannv.dw_clickadvert_daily.csv

另外,關於分隔符的問題,可參考這哥們的博文:

如何將查詢結果進行排名

於是乎我就開始寫,嘿,奇怪,我還真沒有寫過,於是找了寫資料,借鑑了一下別人的,結果如下 create procedure csp getoperatorscorebydate begindate datetime,enddate datetime ascreate table temp 定義臨時表,...

hive如何將split切割後的結果轉成列輸出

首先建立乙個測試表 test 將需求表明。id name 1 yy,tl,dd 2 xy,dl,dz 想要得到的結果是 1 yy 1 tl 1 dd 2 xy 2 dl 2 dz思路 需要將name通過 進行切割 split 得到陣列結果集,就需要考慮如何將這個陣列和id如何輸出,此時就要借助exp...

MSSQL如何將查詢結果拼接成字串

在博問上看到乙個提問 mssql如何將查詢結果拼接成字串 想了一下應該怎麼實現呢,在c 等語言下好實現,但在sql裡實現 還真沒做過。目標 想要在sql中將查詢的結果拼接為 1 2 3 4 5 分析 要進行拼接就要取得每行的值,想到了游標可以做到。於是有了下面的方法 select name from...