zoukankan      html  css  js  c++  java
  • Kettle 创建 Transformation

    1.第一步,先准备数据和工具

    安装好mysql以及客户端工具

    数据:


    USE `test`;

    CREATE TABLE `account` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `account_name` varchar(50) CHARACTER SET latin1 NOT NULL,
      `customer_id` int(11) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

    CREATE TABLE `customer` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `customer_name` varchar(50) CHARACTER SET latin1 NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

    CREATE TABLE `trade` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `customer_id` int(11) NOT NULL,
      `status` int(11) NOT NULL COMMENT '对内= 1 ,对外= 2',
      `amount` decimal(11,2) NOT NULL,
      `account_id` int(11) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

    CREATE TABLE `trade_detail` (
      `customer_name` varchar(50) CHARACTER SET latin1 NOT NULL,
      `customer_id` int(11) NOT NULL,
      `account_name` varchar(50) CHARACTER SET latin1 NOT NULL,
      `account_id` int(11) NOT NULL,
      `amount` double DEFAULT NULL,
      `description` tinytext
    ) ENGINE=InnoDB DEFAULT CHARSET=gbk;

    以上
    我们建了四个表,客户customer,账户account,交易记录trade,交易明细表trade_detail

    现在插入数据

    insert into test.`account` (account_name,customer_id) values("account1",1),("account2",1),("account3",1),("account4",1),("account5",1);

    insert into test.`customer` (customer_name) values("customer1"),("customer2"),("customer3"),("customer4"),("customer5");

    insert into test.`trade` (customer_id,status,amount,account_id) values(1,1,100,1),(1,1,200,2),(1,1,240,3),(1,2,320,4),(1,2,500,5);


    用下面的sql查询一下得到每个客户下每个账户的交易明细

    SELECT * FROM trade t
    LEFT JOIN account a ON t.`account_id` = a.`id`
    LEFT JOIN customer c ON c.`id` = t.`customer_id`;


    2.我们要用kettle完成将这三个表中的数据汇总到trade_detial表中

    看下面一步一步的操作:


    2.1我们新建一个Transformation

    点击保存按钮,保存到e:/test/etl/transfor.ktr  这个后缀是kettle专用的


    2.2从左侧选择【输入】->【表输入】,拖拽到右侧的空白区域,双击【表输入】




    新建一个mysql连接,并点击【获取sql查询语句】获得trade的select语句


    2.3右侧选择【查询】-【数据库查询】拖拽到空白区域,双击选择数据库连接后,浏览选择account表




    如图上,需要填写的部分已经标注出来,中间需要将account表通过account.id = trade.account_id关联起来




    2.4再次添加一个【数据库查询】,将account表与customer表关联起来,如下图:



    2.5添加【Flow】->【过滤记录】,双击打开,选择status字段,点击下面灰黑色框,弹出【输入一个值】的小界面,输入值:1

    表示当status=1的时候为true



    2.6 添加两个常量值【转换】->【增加常量】


    一个输入false,一个输入true,变量的名称都是一样的“value”,值不一样,分别是:“这里是false值哦”,“这里是true值哦”。


    2.7添加表输出【输出】->【表输出】






    这里有一部需要注意的是Specify database fields 需要打上钩,刚才忘了打钩了哈

    确定后


    2.8最后的transform图如下:



    大功告成,点击启动运行试试看有没有数据输出到trade_detail去,如下图





    乱码用前面文章的方法可以解决哈





  • 相关阅读:
    Chrome cookies folder
    Fat URLs Client Identification
    User Login Client Identification
    Client IP Address Client Identification
    HTTP Headers Client Identification
    The Personal Touch Client Identification 个性化接触 客户识别
    购物车 cookie session
    购物车删除商品,总价变化 innerHTML = ''并没有删除节点,内容仍存在
    453
    购物车-删除单行商品-HTMLTableElement.deleteRow()
  • 原文地址:https://www.cnblogs.com/fuhaots2009/p/3503181.html
Copyright © 2011-2022 走看看