zoukankan      html  css  js  c++  java
  • 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"

  • 相关阅读:
    计算在线人数
    微软MSMQ消息件研究(一)
    jQuery循序渐进2
    单点登陆的ASP.NET应用程序设计[zt]
    利用SQL2005的缓存依赖
    .Net 操作MSMQ
    GridView中数据格式化
    TcpListener/TcpClient/UdpClient 的区别及联系
    微软消息件MSMQ研究DEMO(二)
    Nhibernate(1)
  • 原文地址:https://www.cnblogs.com/rocky-AGE-24/p/7425440.html
Copyright © 2011-2022 走看看