input 选中的数据导出_大数据项目之电商数仓项目 0393

fd6c1808f50c791acb2470c970a7dff1.png

Azkaban 调度

8.1 Azkaban 部署

8.2 创建 MySQL 数据库和表

(1)创建 gmall_report 数据库

注:SQL 语句

CREATE DATABASE `gmall_report` CHARACTER SET 'utf8' COLLATE

'utf8_general_ci';

(2)创建表

DROP TABLE IF EXISTS `ads_user_topic`;

CREATE TABLE `ads_user_topic` (

`dt` date NOT NULL,

`day_users` bigint(255) NULL DEFAULT NULL,

`day_new_users` bigint(255) NULL DEFAULT NULL,

`day_new_payment_users` bigint(255) NULL DEFAULT NULL,

`payment_users` bigint(255) NULL DEFAULT NULL,

`users` bigint(255) NULL DEFAULT NULL,

`day_users2users` double(255, 2) NULL DEFAULT NULL,

`payment_users2users` double(255, 2) NULL DEFAULT NULL,

`day_new_users2users` double(255, 2) NULL DEFAULT NULL,

PRIMARY KEY (`dt`) USING BTREE

) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci

ROW_FORMAT = Compact;

8.3 Sqoop 导出脚本

1)编写 Sqoop 导出脚本

在/home/atguigu/bin 目录下创建脚本 sqoop_export.sh

[atguigu@hadoop102 bin]$ vim sqoop_export.sh

在脚本中填写如下内容

#!/bin/bash

hive_db_name=gmall

mysql_db_name=gmall_report

export_data() {

/opt/module/sqoop/bin/sqoop export

--connect

"jdbc:mysql://hadoop102:3306/${mysql_db_name}?useUnicode=true&

characterEncoding=utf-8"

--username root

--password 000000

--table $1

--num-mappers 1

--export-dir /warehouse/$hive_db_name/ads/$1

--input-fields-terminated-by "t"

--update-mode allowinsert

--update-key $2

--input-null-string 'N'

--input-null-non-string 'N'

}

case $1 in

"ads_uv_count")

export_data "ads_uv_count" "dt"

;;

"ads_user_action_convert_day")

export_data "ads_user_action_convert_day" "dt"

;;

"ads_user_topic")

export_data "ads_user_topic" "dt"

;;

"all")

export_data "ads_uv_count" "dt"

export_data "ads_user_action_convert_day" "dt"

export_data "ads_user_topic" "dt"

;;

esac

关于导出 update 还是 insert 的问题

 --update-mode:

updateonly 只更新,无法插入新数据

allowinsert 允许新增

 --update-key:允许更新的情况下,指定哪些字段匹配视为同一条数据,进行更新

而不增加。多个字段用逗号分隔。

 --input-null-string 和--input-null-non-string:

分别表示,将字符串列和非字符串列的空串和“null”转义。

官网地址:http://sqoop.apache.org/docs/1.4.6/SqoopUserGuide.html

Sqoop will by default import NULL values as string null. Hive is

however using string N to denote NULL values and therefore

predicates dealing with NULL(like IS NULL) will not work correctly.

You should append

parameters --null-string and --null-non-string in case of import

job or --input-null-string and --input-null-non-string in case

of an export job if you wish to properly preserve NULL values.

Because sqoop is using those parameters in generated code, you need

to properly escape value N to N:

Hive 中的 Null 在底层是以“N”来存储,而 MySQL 中的 Null 在底层就是 Null,

为 了 保 证 数 据 两 端 的 一 致 性 。 在 导 出 数 据 时 采 用 --input-null-string 和

--input-null-non-string 两个参数。导入数据时采用--null-string 和--null-non-string。

3)执行 Sqoop 导出脚本

[atguigu@hadoop102 bin]$ chmod 777 sqoop_export.sh

[atguigu@hadoop102 bin]$ sqoop_export.sh all

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值