#!/bin/bash
TABLES=(
ods_pay1
ods_pay2
ods_pay3
ods_pay4
)
start_date=${1}"01"
end_date=${2}"01"
function main(){
if [ $# -lt 2 ] ; then
printf "Please enter two parameters.\n";
printf "Usage: $0 start_date end_date\n";
exit 1
fi
for table in ${TABLES[*]}
do
SQL="create or replace view ods.${table}_v as"
local start_date_tmp=${start_date}
while [[ "$start_date_tmp" -le "$end_date" ]] ;
do
month=`date -d "${start_date_tmp}" +%Y%m`
SQL="${SQL} select * from ods.${table}_${month} union all"
start_date_tmp=$(date -d "${start_date_tmp}+1months" +%Y%m%d)
done
SQL=${SQL%union all*}
hive -n ${username} -p ${password} -u jdbc:hive2://hadoop01:10000/ods -e "${SQL}"
done
}
main "$@"
|