您的位置:首页 > 运维架构

sqoop数据抽取 分区表的示例

2018-01-10 10:26 337 查看
--分区表

#!/bin/bash

#mysql表名
 tableName=t_sys_file
#字段名
 columns=id,biz_field_name,biz_id,biz_table_name,bucket_name,content_type,created_date,disp_order_no,download_times,file_key,file_size,filename
#hive-database
 hive_datebase=ods
#hive-table
 hive_table=s01_t_sys_file
#partition
 hive_partition_key=etl_time
 #etl_time=`date "+%Y-%m-%d %H:%M:%S"`
 etl_time=`date "+%Y%m%d"`
#m个数
parallel_count=16
 
 for i in {1..1}
 do
  #redo rmr hdfs
  hadoop fs -rmr /user/hdfs/${hive_table}
  hadoop fs -rmr /user/hdfs/${tableName}

  cfg=`grep -v '^#' /home/gamaxwin/mo9_azkaban/database_set.cfg | grep -i "jianghujiuji_riskdb"`
  uid=`echo $cfg|awk -F, '{print $2}'`
  url=`echo $cfg|awk -F, '{print $3}'`
  pwd=`echo $cfg|awk -F, '{print $4}'`
  jceks_path=`echo $cfg|awk -F, '{print $5}'`

  sqoop import 
  -Dhadoop.security.credential.provider.path=${jceks_path}   
  --connect ${url}
  --username ${uid}
  --password-alias   ${pwd}   
  --hive-import
  --hive-overwrite
  --hive-database ${hive_datebase}
  --hive-table ${hive_table}
  --fields-terminated-by 'x01'
  --lines-terminated-by ' '
  --null-string '\N'   
  --null-non-string '\N'   
  --hive-delims-replacement ' '
  --compress
  --compression-codec org.apache.hadoop.io.compress.SnappyCodec
  --hive-partition-key $hive_partition_key 
  --hive-partition-value  ${etl_time} 
  --target-dir /user/hdfs/${hive_table} 
  --query  "select ${columns} from ${tableName}  where $CONDITIONS" 
  --split-by id 
  -m ${parallel_count}   
 
 done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sqoop import