#!/bin/bash
if [ -n "$2" ] ;then
do_date=$2
else
do_date=`date -d '-1 day' +%F`
fi
db_name=ztdata_sync.[dbo]
sqoop=/data/program/sqoop-1.4.6/bin/sqoop
import_data() {
$sqoop import -D mapred.job.queue.name=hive \
--driver com.microsoft.sqlserver.jdbc.SQLServerDriver \
--connect "jdbc:sqlserver://xx.xx.xx.xx:1433;username=sa;password=xxxx;database=xxx" \
--fields-terminated-by "\t" \
--delete-target-dir \
--null-string '\\N' \
--null-non-string '\\N' \
--target-dir /ztdata_import/$1/$do_date \
--delete-target-dir \
--num-mappers 1 \
--compress \
--compression-codec org.apache.hadoop.io.compress.SnappyCodec \
--fields-terminated-by "\t" \
--query "$2"' and $CONDITIONS;'
}
import_123B(){
import_data "123B" " select * FROM [123B] where 1=1 "
}