从HDFS中向hive数据仓库分区中上传数据

mac2024-11-06  57

从HDFS中向hive数据仓库分区中上传数据

从HDFS中向hive数据仓库中上传数据(分区,按年月日) 文件格式: 年-月-日 例: 最后有配套的分区表的创建

shell代码:

#!/bin/bash #创建全局对象,供后面使用 action=""; #获取该路径下所有的文件 然后进行遍历 得到文件的路径 for file in /root/AccountRegister/* do #获取文件的路径 去除后缀名 fname=${file//.txt/}; #得到文件名(例:1996-11-29) str=$(echo $fname | awk -F '/' '{print $NF}') #得到年 year=$(echo $str | awk -F '-' '{print $1}') #得到月 month=$(echo $str | awk -F '-' '{print $2}') #得到日 day=$(echo $str | awk -F '-' '{print $3}') #获取执行的hive语句 action=$action'load data local inpath "'$file'" into table default.Accountregister partition(year="'$year'",month="'$month'", day="'$day'");' done #测试使用,查看上面代码是否取到数据 echo $action echo $str echo $year echo $month echo $day #执行hive导入命令 hive -e "$action"

建表:

create table AccountRegister( AppID String, GameID String, ChildId String, IP String, AccountID String, LogType String, LogTime int, PlatformChannelId String, Idfa String, Android_id String, Mac String) partitioned by (year string,month string, day string) row format delimited fields terminated by '|';

结果:

年目录 月目录 日目录: 文件:

最新回复(0)