开源ETL:kettle使用总结【持续更新】

1、kettle 维度更新
代理关键字 增加的时候 ,其 FID类型最大只能设置 NUMBER(17),否则报错 ,数据库:ORACLE

2、利用kettle发邮件附件,下面是流程图:

mail

add

mail3

3、利用kettle jar包执行kettle生成的ktr和kjb文件,这里给大家一个我配置好的java工程,大家可以通过TestRunKettle执行kettle生成的文件,   点击下载kettle演示工程

4、支持jasper图形邮件发送的EMAIL插件修改

//start html email 将HMTL文件写入邮件流里面
                  InputStream is = file.getContent().getInputStream();
                  if(is!=null && file.getName().getExtension().equals("html")){
//                  System.out.println(file.getName().getExtension()); 

                  //set html  to a string
                      MimeBodyPart htmlContent = new MimeBodyPart();
                      byte[] bytes = new byte[1024];
                      String html = "";
                      int c;
                      while((c=is.read(bytes))!=-1){
                      html = html + new String(bytes,0,c);
                      }
//                    System.out.println(html); 

  //replace the image url with new cid url
                      String IMG_REGEX = "<\s*img\s+(?:[^\s>]\s*){0,}src\s*=\s*["']\s*([^"'\s>]*)\s*["'](?:\s*[^\s>]){0,}\s*>";
                      String PREFIX_IMG = "img_";
              Map urlMap = new HashMap();
              Pattern p = Pattern.compile(IMG_REGEX);
              Matcher m = p.matcher(html);
              String url = null;
              String cid = null;
              int i = 1;
              // replace image url
              while (m.find()) {
            url = m.group(1);
            if (StringUtils.hasText(url)) {
            if (!urlMap.containsKey(url)) {
            cid = PREFIX_IMG+(i++);
            urlMap.put(url, cid);
              html = html.replaceAll(url, "cid:"+cid);
            }
            }
               }
            //add html into email
            htmlContent.setContent(html, "text/html; " + "charset=utf-8");
                     parts.addBodyPart(htmlContent); 

            //add html's image  into email
            Iterator urlIterator = urlMap.keySet().iterator();
            while (urlIterator.hasNext()) {
            url = urlIterator.next();
            cid = urlMap.get(url); 

            MimeBodyPart imageFile = new MimeBodyPart(); 

            byte [] imageBytes = file2byte(url);
            DataHandler dh = new DataHandler(new ByteArrayDataSource((byte[])imageBytes,"application/octet-stream")); 

          imageFile.setDataHandler(dh);
            imageFile.setFileName(cid);
//             imageFile.setHeader("Content-ID", "IMG" + new Integer(i).toString());
            parts.addBodyPart(imageFile); 

//             System.out.println(html);
//             System.out.println(cid);
              } 

                  }
                  //end html email

5、关于kettle使用的数据源,这里面会涉及到2个数据源,一个是全局数据源,还有一个是XML中自身的数据源,其中全局的会覆盖XML自身的。记住这个规则就可以了

Ps:KETTLE演示下载:演示1 演示2

已有7 条评论

  1. 你好,从您的博文中学到了很多,谢谢。

    我在使用kettle 4.4 与hive创建连接的时候,
    遇到了窗口弹出式的错误。

    我的hadoop版本是apache0.23.5
    hive是0.81的。

    很想请教如果您遇到类似错误,是如何解决的。谢谢。

    • 连接hive我没有玩过,不知道你弹出来的错误是什么? 你可以贴出来看看。另外,可以看看连接hive的驱动是不是在文件夹libextJDBC里面,你可以找连接hive 0.81的驱动jar包替换kettle里面的试试。

  2. 你好,

    十分感谢,
    报错的信息其中几条是:
    Error connecting to database :
    (using class org.apache.hadoop.hive.jdbc.HiveDriver)
    org/apache/hadoop/hive/metastore/api/MetaException

    org.pentaho.di.core.exception.KettleDatabaseException:
    Error occured while trying to connect to the database

    我已经把包相应的加载到相应的路径下了,

    但是,并不解决问题。

    我想应该是底层hadoop版本不兼容吧。

    我想请问能否使用从新写一个插件的方式来进行加载。

    能否可行呢?您能说说您的思路吗?

    谢谢 ^-^

    • 企业hadoop应用建议使用1.0.3 ,hive 本身其实是有写数据的API,不推荐使用jdbc的方式,如果你要写kettle的插件,我给个例子你:http://www.ahuoo.com/?p=418

发表评论

电子邮件地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>