从oracle导出数据为文本格式
代码
https://github.com/reader-sword/oracle-transform-TDH
驱动包位置:
oracle-drives.rar
https://download.csdn.net/my
touch /mnt/oracle_transport/sqoop.log
echo "" > /mnt/oracle_transport/sqoop.logi=0
cat table.txt |while read line
dotable=`echo $line `echo " -------------------------------------------begin hdfs dfs -rm ${table}------------------------------------------"hdfs dfs -rm -r /tmp/data/${table}
echo " ---------------------------------------------begin sqoop import ${table} --------------------------------------------------"sqoop import --connect jdbc:oracle:thin:@10.20.1.140:1521:orcl --username *** --password **** --query " select * from ${table} where \$CONDITIONS" --target-dir /tmp/data/${table} -m 1 --fields-terminated-by "\001" --hive-drop-import-delims --null-string '\\N' --null-non-string '\\N'let i++echo "${table} $i finished" >>/mnt/oracle_transport/sqoop.logecho " -------------------------------------- sqoop import finished ${table} $i--------------------------------------------"
done
创建外表
cat table.txt |while read line
doecho "DROP TABLE IF EXISTS JIAXING_PRE_MEACH.${line}_EXT;CREATE EXTERNAL TABLE JIAXING_PRE_MEACH.${line}_EXT (ROWKEY STRING, NUM INT, COUNTRY INT, RD INT)row format delimited fields terminated by \"\\001\" location '/tmp/data/${line}';" >/mnt/oracle_transport/create_ext/create_ext_${line}.sqlecho "-------------------------------------create_ext_${line}.sql finished ----------------------------------------------"
done
执行建外表命令并创建orc表
i=0
rm /mnt/oracle_transport/create_ext_orc_all.log
touch /mnt/oracle_transport/create_ext_orc_all.log
cat table.txt |while read line
dobeeline -u jdbc:hive2://10.20.1.144:10000 -f /mnt/oracle_transport/create_ext/create_ext_${line}.sqlstatement="DROP TABLE IF EXISTS JIAXING_PRE_MEACH.${line}_ORC;CREATE TABLE JIAXING_PRE_MEACH.${line}_ORC STORED AS ORC AS SELECT * FROM JIAXING_PRE_MEACH.${line}_EXT;select count(*) from JIAXING_PRE_MEACH.${line}_ORC;"beeline -u jdbc:hive2://10.20.1.144:10000 -e "$statement"let i++echo "JIAXING_PRE_MEACH.${line}_ORC $i finished" >>/mnt/oracle_transport/create_ext_orc_all.logecho "--------------------------------JIAXING_PRE_MEACH.${line}_ORC $i finished---------------------------------------------"
done