获取impala下全部的数据库建表语句

方法一:python

如今的导出仍是有缺陷的,导出的文件中仍是存在其余没必要要的信息sql

#!/bin/bash
##获取数据库
databases=$(hive -e "show databases; exit;") 
for database in $databases;
do        
#获取hive建表语句        
tables=$(hive -e "use $database; show tables;")       
 for table in $tables;        
 do                             
 echo "--=========== db: $database , table: $table ===========" >> $database.sql
 echo "$(hive -e "use $database;show create table $table;");" >> $database.sql
 done
done

尚未找到其余方法。有其余解决方法,能够Mark一下我shell

方法二:数据库

20191108今天有想出来一个方法,有点繁杂,但也是能够的,用impala-shellbash

1.先准备一个文件(tables_name.txt),咱们会读这个文件工具

[root@bigdata zw]# more tables_name.txt 
show create table cdata.c01_bill_distr_stat
show create table cdata.c01_bill_distr_stat_temp1
show create table cdata.c01_bill_pro_bal
show create table cdata.c01_bill_repay_stat
show create table cdata.c01_bill_repay_stat_temp1

2.一个小脚本spa

#!/usr/bin/python
# -*- coding:utf-8 -*-

import time,sys
import os
reload(sys)
sys.setdefaultencoding("utf8")



file=open("tables_name.txt")
send_file = file.readlines()
for i in send_file:
   os_cmd1 = "impala-shell -q 'use cdata' "
   os_cmd2 = "impala-shell -q '"+ i.strip('\n') +"'"
   os.system(os_cmd2)
file.close()

都放在一个目录下,运行python脚本,这时候,日志会打印到屏幕上,须要获取屏幕上的日志内容便可。日志

我用的xshell工具code

 

 

 

这个时候,全部的日志都会打印到文件中(bigdata_2019-11-08_17-20-11),能够找到本身想要的内容。blog

相关文章
相关标签/搜索