1. 程式人生 > >如何用shell呼叫hive

如何用shell呼叫hive

#!/bin/sh  
  
#引數傳遞  
  
source /etc/profile;  
source ~/.bash_profile;  
BASEDIR=`dirname $0`  
cd $BASEDIR  
  
#classpath優先當前目錄  
CLASSPATH=$BASEDIR  
#classpath其次是config目錄  
#classpath再次是lib目錄下面的所有jar包  
  
#設定引數  
D=`date +%Y-%m-%d`  
YESTODAY=`date -d "1 days ago" +%Y-%m-%d`  
  
if [ $# == 2  ]; then  
  YESTODAY=$2  
fi  
  
if [ $# == 4  ]; then  
  D=$4  
  YESTODAY=$2  
fi  
  
#HQL  
hive<<EOF  
LOAD DATA LOCAL INPATH '$HADOOP_DATA_HOME/consume-$YESTODAY.csv' OVERWRITE INTO TABLE tlbb.consume_log PARTITION (dt='$YESTODAY');  
EOF  
 方法二、
  #!/bin/sh
Java程式碼  收藏程式碼
#引數傳遞  
  
source /etc/profile;  
source ~/.bash_profile;  
BASEDIR=`dirname $0`  
cd $BASEDIR  
  
#classpath優先當前目錄  
CLASSPATH=$BASEDIR  
#classpath其次是config目錄  
#classpath再次是lib目錄下面的所有jar包  
  
#設定引數  
D=`date +%Y-%m-%d`  
YESTODAY=`date -d "1 days ago" +%Y-%m-%d`  
  
if [ $# == 2  ]; then  
  YESTODAY=$2  
fi  
  
if [ $# == 4  ]; then  
  D=$4  
  YESTODAY=$2  
fi  
  
echo "LOAD DATA LOCAL INPATH '/data/tlbb/hadoop_data/billlogout-$YESTODAY.csv' OVERWRITE INTO TABLE tlbb.logout_log PARTITION (dt='$YESTODAY');" | hive