• hive 定时加载分区


    #!/bin/bash
    #每天定时位外部表加载分区
    #服务器当天的时间
    #加载环境变量
    source /etc/profile;
    #如果没有指定日期用当前日期如果指定的日期使用指定的日期
    echo 'starting...'
    if [ -z $1 ]
    then
    curdate=`date +%Y%m%d`
    else
    curdate=$1
    fi
    # alter table click add if not exists partition(logdate='20170821') LOCATION '/maats5/click/logdate=20170821';

    #数据库表
    tableList="click install register login pay"
    #为所有表加载当天的分区
    addPartitionOfCurDate_All() {
    for table in $tableList
    do
    echo "deal with " $table
    createHdfsDir $table $curdate
    addPartition $table $curdate
    done
    }

    #判断分区是否存在,如果不存在则创建
    createHdfsDir(){
    #$1=tablename,$2=curdate
    hdfs dfs -test -d /maats5/$1/logdate=$2
    if [ ! $? -eq 0 ] ;then
    #如果不存在则创建这个文件
    hdfs dfs -mkdir /maats5/$1/logdate=$2
    fi
    }

    #加载指定表的分区
    addPartition(){
    #$1=tablename, $2=curdate
    /home/hadoop/apps/hive/bin/hive -e "alter table maats.$1 add if not exists partition(logdate='$2') LOCATION '/maats5/$1/logdate=$2';" 1>/home/hadoop/maats/crontabTask/maatsLogs/crontab_hive.std 2>/home/hadoop/maats/crontabTask/maatsLogs/crontab_hive.err
    }

    #删除分区
    deletePartition(){
    /home/hadoop/apps/hive/bin/hive -e "alter table maats.$1 drop if exists partition(logdate='$2') " 1>/home/hadoop/maats/crontabTask/maatsLogs/crontab_hive.std 2>/home/hadoop/maats/crontabTask/maatsLogs/crontab_hive.err
    }

    #执行
    addPartitionOfCurDate_All
    echo "ending"

  • 相关阅读:
    Vuex
    浏览器渲染页过程描述
    mvvm 模式
    flex 布局
    js 浮点数计算
    3、异步编程-JS种事件队列的优先级
    高阶函数 debounce 和 throttle
    记录学习MVC过程,HTML铺助类(二)
    记录学习MVC过程,控制器方法和视图(一)
    修改以前项目遇到,所有页面继承BaseBage,Sesssion保存一个model,实现登录(记录一下)
  • 原文地址:https://www.cnblogs.com/rocky-AGE-24/p/7425440.html
Copyright © 2020-2023  润新知