怎样做视频上网站赚钱,网络科技公司一般都是骗,网站上海备案,想在网站里添加超链接怎么做前些天发现了一个巨牛的人工智能学习网站#xff0c;通俗易懂#xff0c;风趣幽默#xff0c;忍不住分享一下给大家。点击跳转到教程。
业务场景#xff1a;是在oracle 数据库和 hive 数据库中 #xff0c;有多个相同结构的表#xff0c;要求数据从2个库定时双向同步。…前些天发现了一个巨牛的人工智能学习网站通俗易懂风趣幽默忍不住分享一下给大家。点击跳转到教程。
业务场景是在oracle 数据库和 hive 数据库中 有多个相同结构的表要求数据从2个库定时双向同步。
导出时可以只导出部分字段则此时 hive 库和 oracle 库中表结构可以并非完全一致
1. 写一个文本文档把要导入的表名和库名先编辑好格式如 oracle_table_list_append.txt
wate.BUSI_xxx
wate.xxx_xxx_INFO
wate.xxx_USER_xxx
... # wate 是 oracle 数据库名 BUSI_xxx 是表名。
# 可写多行脚本执行时读取每个一行循环导入每个表的数据。
编写sgoop import 脚本并执行即可把数据从 oracle 数据库导入到 hive 数据库中。
currentdate -d yesterday %Y-%m-%d #获取当前时间
#currentdate -d yesterday 20190110 %Y-%m-%d #获取指定日期的前一天begin${current} 00:00:00sed -i /^$/d /opt/xxx/sqoop/conf/oracle_table_list_append.txt
cat /opt/xxx/sqoop/conf/oracle_table_list_append.txt|while read line
doOLD_IFS$IFSIFS.arr($line)db_name${arr[0]}table_name${arr[1]}echo ####begin to sqoop from oracle ${db_name}.${table_name} ......sqoop import \--connect jdbc:oracle:thin:192.168.xx.xx:1521/${db_name} \--username 数据库名 \--password 数据库密码 \--table ${table_name} \--where creationtime to_date(${begin},yyyy-mm-dd hh24:mi:ss) or xxxtimeto_date(${begin},yyyy-mm-dd hh24:mi:ss) or dxxtimeto_date(${begin},yyyy-mm-dd hh24:mi:ss) \--hive-drop-import-delims \--null-string \\N \--null-non-string \\N \--fields-terminated-by \007 \--lines-terminated-by \n \--hive-import \--hive-table hive数据库名.${table_name} \-m 10rc$?if [ $rc -ne 0 ]thenecho #### sqoop from oracle ${db_name}.${table_name} failed......# echo #### sqoop from oracle ${db_name}.${table_name} failed......|mail -s failed crontab_${current} xxx163.comelseecho ####sqoop from oracle ${db_name}.${table_name} successed......fidone
currentdate %Y-%m-%d %H:%M:%S #获取当前时间
end_timeStampdate -d $current %s
du_time$[end_timeStamp-begin_timeStamp]
echo sqoop total time used: $du_time s --where 此参数是条件过滤全表导入可不加此参数。
2. 编写sgoop export 脚本并执行则可把数据从 hive 库 导出到 oracle 数据库。
current_datetimedate %Y-%m-%d %H:%M:%S
echo Start Timing Task:$current_datetime
currentdate %Y-%m-%d %H:%M:%S #获取当前时间
begin_timeStampdate -d $current %stable_namecxx_xxx_day
daydate -d -1days %Y%m%d #昨天此表以天分区每次只导一天的数据echo ####开始导出${day}的数据 into oracle oracle数据库名.${table_name} ......sqoop export \--connect jdbc:oracle:thin:192.168.xxx.xxx:1521/oracle数据库连接名 \--username oracle数据库名 \--password oracle数据库密码 \--table ${table_name} \--export-dir /user/hive/xxx/hivexxx.db/xxx_xxx_day/day${day} \--columns xxx_no,datatime,xxx_value,xxx_status,xxx_voage,staxx_str,stxxxs_hex,fy_id \--input-fields-terminated-by \007 \--input-lines-terminated-by \n \--input-null-string \\N \--input-null-non-string \\N \--m 4rc$?if [ $rc -ne 0 ]thenecho Timing Task Error:echo ####sqoop from hive into oracle ${table_name} failed......elseecho ####sqoop from hive into oracle ${table_name} successed......fi
currentdate %Y-%m-%d %H:%M:%S #获取当前时间
end_timeStampdate -d $current %s
du_time$[end_timeStamp-begin_timeStamp]
echo sqoop total time used: $du_time s
--export-dir 指定HDFS上的文件路径
--columns 指定要导出的列可以只导出部分列 3. 官网说明文档http://sqoop.apache.org/docs/1.4.7/SqoopUserGuide.html
要查更多参数和用法可以直接查询官方文档。
import说明文档地址http://sqoop.apache.org/docs/1.4.7/SqoopUserGuide.html#_literal_sqoop_import_literal export说明文档地址http://sqoop.apache.org/docs/1.4.7/SqoopUserGuide.html#_literal_sqoop_export_literal