zoukankan      html  css  js  c++  java
  • 通过创建临时表合并某一个库的hive小文件

    #!/bin/bash
    #需要指定hive中的库名
    
    #set -x
    set -e
    
    DB=$1
    
    if [ -z $1 ];then
        echo “Usage:$0  DbName”
        exit 1
    fi
    
    #注释掉cron对应的计划任务
    row=$(sed -n '/sjob_exec.sh/=' /etc/crontab)
    sed -i "$row s/^/#/" /etc/crontab
    
    #获取hive表定义
    ret=$(sudo -u hdfs hive -e "use ${DB};show tables;"|grep -v _tmp|grep -v importinfo)
    
    for tem in $ret;
    do
        echo ${tem}
        sudo -u hdfs hive -e "use ${DB};drop table ${tem}_tmp"
        sudo -u hdfs hive -e "use ${DB};create table ${tem}_tmp_1 as select * from ${tem}"
        sudo -u hdfs hive -e "use ${DB};alter table ${tem} rename to ${tem}_tmp"
        sudo -u hdfs hive -e "use ${DB};alter table ${tem}_tmp_1 rename to ${tem}"
    done
    
    impala-shell -q 'invalidate metadata' -i hslave1
    
    #恢复对应的cron任务
    row=$(sed -n '/sjob_exec.sh/=' /etc/crontab)
    sed -i "$row s/#//" /etc/crontab
  • 相关阅读:
    github使用及介绍
    git分支 & git标签
    nginx配置文件参考
    PHP优化
    Nginx优化
    Git安装及基础命令使用
    JavaScript框架设计-node节点
    论文爬取(一)
    JAVA日报
    JAVA日报
  • 原文地址:https://www.cnblogs.com/ggzone/p/10121153.html
Copyright © 2011-2022 走看看