第一步:创建分区表
create database hive_autoload;
create table hive_autoload.student2(
uid string,
gender string,
fuid string
)
partitioned by (dt string)
row format delimited fields terminated by "\t";
第二步创建脚本文件
1.在shell脚本的开头往往有一句话来定义使用哪种sh解释器来解释脚本。
目前研发送测的shell脚本中主要有以下两种方式:
(1) #!/bin/sh
(2) #!/bin/bash
区别:
#!/bin/sh-------------------程序执行错误就不会向下运行
#!/bin/bash-----------------程序运行错误略过错误继续向下执行
loadstudent.sh文件
#!/bin/bash
#定义昨天的日期时间
yesterday=`date -d '0 days ago' +%Y%m%d`
#定义local数据目录
hive_load='/datas/student1.txt'
#定义hive路径
hive_home=/opt/app/hive-1.2.2
#向表中添加分区
hive_sql="load data local inpath '"${hive_load}"' into table hive_autoload.student2 partition(dt="${yesterday}")"
echo "$hive_sql"
hive -e "$hive_sql"
2.创建job文件
type=command
command=bash loadstudent.sh
上传执行