sqoop导入数据到hive

一、从msyql导入到hive表中

创建hive表

sqoop import --connect  --username   --password   --query " SELECT * FROM User_LoginHistory.User_OnlineHistory_total WHERE  LoginTime>='2013-01-01' and LoginTime<'2013-01-01 00:01:00' and \$CONDITIONS"  -m 1 --fields-terminated-by '\t' --target-dir  /user/root/bh_base_data/login  --hive-import --hive-drop-import-delims  --hive-table bhdp_base_data.login --create-hive-table


追加模式导入hive表
sqoop import --connect  --username   --password  --append  --query "SELECT * FROM User_LoginHistory.User_OnlineHistory_total WHERE  LoginTime>='2013-01-01' and LoginTime<'2013-1-3' and \$CONDITIONS "  -m 1 --fields-terminated-by '\t'    --target-dir /user/hive/warehouse/bhdp_base_data.db/login



#!/bin/sh

tableNameList='DimAccountStatus DimAdInvestment DimAge DimAuthCategory DimAuthCheckStatus DimChannel DimCreditedById5 DimCreditedByMobile DimDate DimDegree DimGender D
imGeography DimHasMainPhoto DimHousing DimIncome DimInsign DimLoveStatus DimLoveType DimMarriage DimMergedDegree DimMergedHousing DimMergedIncome DimNewDegree DimNewHo
using DimNewIncome DimOrderStatus DimPhotoCheckStatus DimPlatform DimService DimTime DimUserIdType'

for tableName in ${tableNameList} 
do
        sqoop import --connect 'jdbc:mysql://172.16.4.113:3307/?useUnicode=true&characterEncoding=utf8' --username '***' --password '***' --query " SELECT * FR
OM bhdw.${tableName} where \$CONDITIONS"  -m 1 --fields-terminated-by '\t' --target-dir  /user/root/lmj_temp --hive-table bhdw.${tableName} --hive-import --hive-drop-i
mport-delims --null-non-string '\\N' --null-string '\\N' --hive-overwrite --create-hive-table 
done


二、从sqlserver导入到hive表中

#!/bin/sh
tableNameList='DimInsign Dim_Insign Dim_Services Dim_PayPlatform Dim_ServiceConfig Dim_WapProductSource'


for tableName in ${tableNameList} 
do
        sqoop import --connect "jdbc:sqlserver://172.16.3.190;username=***;password=***;database=BHDW"  --query " SELECT * FROM ${tableName}             where \$CONDITIONS"  -m 1 --fields-terminated-by '\t' --target-dir  /user/root/lmj_temp  --hive-import --hive-overwrite --hive-drop-import-delims --null-non-st
ring '\\N' --null-string '\\N'  --hive-table bhdw.${tableName}
done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值