zoukankan      html  css  js  c++  java
  • hivef:hive 执行 sql 文件

    hivef:hive 执行 sql 文件

    #!/bin/bash
    
    yesterday=`date -d -1days '+%Y-%m-%d'`
    today=`date '+%Y-%m-%d'`
    tomarrow=`date -d 1days '+%Y-%m-%d'`
    
    #echo "从外部只传递两个参数时,第一个参数必须是 hive sql 文件,第二个必须是YYYY-MM-DD格式的日期!"
    #echo "从外部只传递一个参数时,第一个参数必须是 hive sql 文件"
    
    if [ $# == 2 ]; then
       sqlfile=$1
       echo "从外部只传递两个参数时,第一个参数必须是 hive sql 文件,第二个必须是YYYY-MM-DD格式的日期!"
       if [ $2 == "1970-01-01" ]; then
          ## 正常调度时,real 作业的日期是当天,但是依赖 real 作业的离线作业的日期是前一天
          if [[ $sqlfile == *"real.sql"* ]]; then
             echo "定时调度运行real 作业时,只需要一个sql文件作为参数,日期默认取当天"
             dt=$today
          else
             echo "正常调度时,real 作业的日期是当天,但是依赖 real 作业的离线作业的日期是前一天"
             dt=$yesterday
          fi
       elif [[ $2 =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] && date -d "$2" >/dev/null
          then echo "Date $2 is valid and matches the format (YYYY-MM-DD)"
          echo "手动运行的时候,第二个参数为日期,需要手动指定,格式: YYYY-MM-DD"
          dt=$2
       else
          echo "Date $2 not matches the format (YYYY-MM-DD)!"
          exit 11
       fi
    else
       echo "无法识别的参数!"
       exit 11
    fi
    
    echo "===>> 当前sql: $sqlfile, 执行日期: $dt"
    
    hive 
    -d yesterday=$yesterday -d date=$dt -d tomarrow=$tomarrow 
    -f $sqlfile 
    -i hdfs://emr-header-1.cluster-70637:9000/dw/hive_udf/hive_udf_init.hql
    
    if test $? -ne 0
    then
    exit 11
    fi
    
    
  • 相关阅读:
    正则表达式
    http协议组成(请求状态码)
    谈一谈你对js线程的理解
    CSS 中定位方式有几种,说明他们的意义
    手机端白屏前端优化的方法,5 种以上
    用 js 写一个获取随机颜色的程序
    如何获取本地存储信息
    cuda 版本查阅
    ubuntu16.04 ROS安转及RVIZ启动
    Tensorflow和Caffe 简介
  • 原文地址:https://www.cnblogs.com/myblog1900/p/11539934.html
Copyright © 2011-2022 走看看