参考自 李蒙强 的博客:《ETL利器Kettle实战应用解析系列二》
重新操作、改造、配图
三张事实表
drop table aa_cust;
create table aa_cust --客户表
(
custno int, --客户号
custname varchar(32), --客户名称
custid varchar(32), --客户编码
custtype int, --客户类型(1为对私,2为对公)
CONSTRAINT aa_cust_pkey PRIMARY KEY (custno)
);
drop table aa_account;
create table aa_account --账户表
(
acctno int, --账户号
custno int, --客户号(aa_cust::custno)
amt int, --账户余额
CONSTRAINT aa_account_pkey PRIMARY KEY (acctno)
);
drop table aa_trade;
create table aa_trade --交易表
(
tradeid int, --交易号
acctno int, --账户号
amt int, --交易额
CONSTRAINT aa_trade_pkey PRIMARY KEY (tradeid)
);
--插入客户
insert into aa_cust values(1, 'Private1', '100001', 1);
insert into aa_cust values(2, 'Public1', '200001', 2);
--插入账户
insert into aa_account values(1, 1, 50);
insert into aa_account values(2, 1, 60);
insert into aa_account values(3, 2, 4000);
insert into aa_account values(4, 2, 5000);
--插入交易
insert into aa_trade values(1, 1, 10);
insert into aa_trade values(2, 1, 15);
insert into aa_trade values(3, 2, 20);
insert into aa_trade values(4, 2, 25);
insert into aa_trade values(5, 3, -10);
insert into aa_trade values(6, 3, -15);
insert into aa_trade values(7, 4, -20);
insert into aa_trade values(8, 4, -25);
一张维度表
drop table aa_trade_all;
create table aa_trade_all
(
tradeid int,
acctno int,
amt int,
custno int,
custname varchar(32),
custid varchar(32),
custtype_str varchar(32),
value varchar(32),
CONSTRAINT aa_trade_all_pkey PRIMARY KEY (tradeid)
);
创建“DB连接”
拖拽“表输入”步骤
拖拽“数据库查询”步骤1
拖拽“数据库查询”步骤2
拖拽“过滤记录”步骤
拖拽“JavaScript代码”步骤1
拖拽“JavaScript代码”步骤2
拖拽“增加常量”步骤1
拖拽“增加常量”步骤2
拖拽“文本文件输出”步骤
拖拽“插入/更新”步骤
拖拽“Excel输出”步骤