How can I export view data in hive?

巧了我就是萌 提交于 2019-12-24 10:25:15

问题


I have created 4 tables (a,b,c,d) in hive and created a view (x) on top of that tables by joining them.

-- How can i export the x underlying csv data from hdfs to local ?

-- How can i keep this csv in hdfs

for tables , we can do show create table a;

this will show the location of the hdfs where the underlying csv is stored.

hadoop fs get --from source_path_and_file --to dest_path_and_file

similarly how can i get the csv data from view into my local.


回答1:


You can export view data to the CSV using this:

insert overwrite local directory '/user/home/dir' row format delimited fields terminated by ',' select * from view;

Concatenate files in the local directory if you need single file using cat :

cat /user/home/dir/* > view.csv

Alternatively if the dataset is small, you can add order by in the query, this will trigger single reducer and produce single ordered file. This will perform slow if the dataset is big.




回答2:


1) to write your results in file you can use INSERT OVERWRITE as below:

insert overwrite local directory '/tmp/output'
row format delimited
fields terminated by '|'
select * from <view>;

2) If you want to write a file into HDFS then use above insert overwrite statement with local

3) No separate HDFS location for views.

View are purely logical construct from the table and there is no separate underlying storage created for them in HDFS.

Views are being used when you want to store intermediate results and query them directly instead of writing complex query on that table again and again. It's like we use with blocks in our query.



来源:https://stackoverflow.com/questions/54768501/how-can-i-export-view-data-in-hive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!