shell脚本 hive 批量导入文件到hdfs分区

mac2024-10-05  70

建表语句

hive (default)> create table dept_partition( deptno int, dname string, loc string ) partitioned by (month string) row format delimited fields terminated by '\t';

shell 脚本

#!/bin/bash action=""; #获取文件夹下所有的文件 然后进行遍历 得到文件的路径 for file in /opt/module/datas/AccountCharge/* do #获取文件的路径 去除后缀名 name=${file//.txt/ }; #得到/后面的路径 str=$(echo $name | awk -F '/' '{print $NF}') #获取执行的语句 action=$action'load data local inpath "'$file'" into table dept_partition partition(month="'$str'")'';' done #执行hive导入命令 hive -e "$action"
最新回复(0)