如何将所有Hive数据库及其表导出到csv或txt文件 [英] How to export all Hive databases and their tables to a csv or txt fiile

查看:132
本文介绍了如何将所有Hive数据库及其表导出到csv或txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据库中的所有表输出到csv或文本文件.

I am trying to output all tables in a database to an csv or text file.

我可以使用显示数据库"输出所有数据库,也可以使用"dal_std"显示数据库中的所有表,但是我如何遍历所有表并将其导出到csv或文本文件中正在尝试做.

I can output all the databases by using "show databases" and I can show all the tables in the databases by using "dal_std" but how to loop through all the tables and export it to a csv or text file is what I am trying to do.

我是Shell脚本的新手,但到目前为止,这是我的经验:

I am new to shell scripts but here is what i have so far:

hive -e "show databases" > d.txt

for line in d.txt:
hive -e "show tables in database > output.txt

有什么想法或简单的方法吗?

Any ideas or simply ways to do this?

推荐答案

您快要走到尽头了.只需添加更多细节即可完成!

You almost reached to an end. just adding up few more details to finish it up!

#!/bin/bash
echo "Executing the shell script"
hive -e "show databases" > databases.txt
for i in `cat databases.txt`
do
    printf "Given database name has below set of tables:"$i >> tableslist.txt
    printf '\n' >> tableslist.txt
    hive -e "show tables in $i" >> tableslist.txt

done
echo "shell scripts ends"

这篇关于如何将所有Hive数据库及其表导出到csv或txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆