Kettle实战指南:配置、转换与任务创建详解

需积分: 50 20 下载量 163 浏览量 更新于2024-09-10 收藏 816KB DOC 举报
Kettle,全称为Pentaho Data Integration(简称PDI),是一个开源的ETL(Extract, Transform, Load)工具,用于数据集成、数据转换和数据加载。本文档提供了一个简化的Kettle使用指南,主要针对实际项目中如何利用该工具进行数据处理。 首先,Kettle的使用涉及以下几个关键步骤: 1. **创建资源库**: - 在Kettle的登录界面上,通过点击新建按钮进入配置界面,配置存储转换、任务和相关元数据的数据库。建议建立独立的数据库用户,如用户名`admin`和密码`admin`,专门用于Kettle数据管理。 2. **创建转换**: - 新建转换用于将数据从源库A的表A1转移到目标库B的表B1。具体操作包括: - 添加"表输入"作为数据源,设置数据库连接。 - 编辑SQL提取语句,确保字段别名与目标表一致且无标点符号。 - 添加"表输出"作为数据目标,配置目标数据库连接和表名。 - 连接表输入和表输出,可以设置数据批量导入。 - 保存并测试转换,可能需要使用"执行SQL脚本"预处理操作。 3. **创建任务**: - 任务用于串联多个操作,如转换、任务和脚本,形成一个自动化的工作流程。创建任务步骤如下: - 新建任务,任务中可以包含多个转换,这些转换按照序列执行。 - 可以调整任务的调度、依赖关系等高级特性。 在整个使用过程中,需要注意以下几点: - SQL编写规范:确保SQL语句正确,字段别名与目标表匹配,没有多余标点,如有参数需启用变量替换。 - 数据处理优化:对于大数据量,注意设置合适的批量导入大小以提高效率。 - 脚本执行:在转换前后可能需要运行脚本,确保数据准备和清理工作顺利进行。 - 安全性:在实际生产环境中,可能需要对数据库连接进行加密和权限管理。 Kettle是一个强大而灵活的工具,熟练掌握其使用可以帮助团队高效地进行数据集成和管理工作。通过本文档提供的步骤,用户能够快速上手并构建复杂的ETL流程。
2012-02-09 上传
目录 Kettle 3.0 用户手册 ...................................................................................................................... 1 Kettle 3.0 用户手册 ...................................................................................................................... 6 1. Kettle 介绍 ................................................................................................................................ 6 1.1 什么是kettle ............................................................................................................. 6 1.2 Kettle 的安装 ............................................................................................................ 6 1.3 运行Spoon ............................................................................................................... 6 1.4 资源库 ....................................................................................................................... 6 1.5 资源库自动登录 ....................................................................................................... 7 1.6 定义 ........................................................................................................................... 8 1.6.1 转换 ................................................................................................................... 8 1.6.2 任务 ................................................................................................................... 8 1.7 选项 ........................................................................................................................... 9 1.7.1 General 标签 ................................................................................................... 10 1.7.2 Look Feel 标签 ............................................................................................... 11 1.8 搜索元数据 ............................................................................................................. 12 1.9 设置环境变量 ......................................................................................................... 13 2. 创建一个转换或任务 ............................................................................................................. 13 3. 数据库连接(Database Connections) ...................................................................................... 14 3.1 描述 ......................................................................................................................... 14 3.2 设置窗口 ................................................................................................................. 14 3.3 选项 ......................................................................................................................... 14 3.4 数据库用法 ............................................................................................................. 15 4. SQL 编辑器(SQL Editor) ....................................................................................................... 16 4.1 描述 ......................................................................................................................... 16 4.2 屏幕截图 ................................................................................................................. 16 4.3 局限性 ..................................................................................................................... 16 5. 数据库浏览器(Database Explorer) ........................................................................................ 17 5.1 屏幕截图 ................................................................................................................. 17 5.2 描述 ......................................................................................................................... 17 6. 节点连接(Hops) ................................................................................................................ 18 6.1 描述 ......................................................................................................................... 18 6.2 转换连接 ................................................................................................................. 18 6.3 任务连接 ................................................................................................................. 18 6.4 屏幕截图 ................................................................................................................. 18 6.5 创建一个连接 ......................................................................................................... 19 6.6 拆分一个连接 ......................................................................................................... 19 6.7 转换连接颜色 ......................................................................................................... 19 7. 变量(Variables) .................................................................................................................. 20 技术资料,【Kette3.0 用户手册】 ©深圳市神盾信息技术有限公司,2008 第2 页/共202 页 7.1 变量使用 ................................................................................................................. 20 7.2 变量范围 ................................................................................................................. 20 7.2.1 环境变量 ......................................................................................................... 20 7.2.2 Kettle 变量 ...................................................................................................... 21 7.2.3 内部变量 ......................................................................................................... 21 8. 转换设置(Transformation Settings) .................................................................................. 22 8.1 描述 ......................................................................................................................... 22 8.2 屏幕截图 ................................................................................................................. 22 8.3 选项 ......................................................................................................................... 25 8.4 其它 ......................................................................................................................... 26 9. 转换步骤(Transformation steps) ....................................................................................... 27 9.1 描述 ......................................................................................................................... 27 9.2 运行步骤的多个副本 ............................................................................................. 27 9.3 分发或者复制 ......................................................................................................... 28 9.4 常用错误处理 ......................................................................................................... 29 9.5 Apache 虚拟文件系统(VFS)支持 .................................................................... 31 9.6 转换步骤类型 ......................................................................................................... 33 9.6.1 文本文件输入(Text Input) ........................................................................ 33 9.6.2 表输入(Table Input) ................................................................................... 45 9.6.3 获取系统信息(Get System Info) ............................................................... 47 9.6.4 生成行(Generate Rows) ............................................................................ 51 9.6.5 文件反序列化(De-serialize from file)(原来名称为Cube 输入) .......... 52 9.6.6 XBase 输入(XBase input) ......................................................................... 53 9.6.7 Excel 输入(Excel Input) ............................................................................ 54 9.6.8 XML 输入(XML input) .................................................................................. 58 9.6.9 获取文件名(Get File Names) ......................................................................... 61 9.6.10 文本文件输出(Text File Output) .................................................................... 62 9.6.11 表输出(Table output) ...................................................................................... 65 9.6.12 插入/更新(Insert/Update) ............................................................................... 68 9.6.13 更新(Update) ............................................................................................. 70 9.6.14 删除(Delete) .................................................................................................... 71 9.6.15 序列化到文件(Serialize to file)(以前是Cube Output) .................................. 72 9.6.16 XML 输出(XML output) ........................................................................... 73 9.6.17 Excel 输出(Excel Output) ............................................................................... 76 9.6.18 Access 输出(Microsoft Access Output) ..................................................... 78 9.6.19 数据库查询(Database lookup) ....................................................................... 80 9.6.20 流查询(Stream lookup) ............................................................................. 81 9.6.21 调用数据库存储过程(Call DB Procedure) .................................................... 83 9.6.22 HTTP 客户端(HTTP Cient) ............................................................................ 84 9.6.23 字段选择 (Select values) ............................................................................... 86 9.6.24 过滤记录(Filter rows) ..................................................................................... 89 9.6.25 排序记录(Sort rows) ................................................................................. 90 9.6.26 添加序列(Add sequence) ................................................................................ 91 9.6.27 空操作-什么都不做(Dummy-do nothing) ..................................................... 93 技术资料,【Kette3.0 用户手册】 ©深圳市神盾信息技术有限公司,2008 第3 页/共202 页 9.6.28 行转列(Row Normaliser) ................................................................................ 95 9.6.29 拆分字段(Split Fields)............................................................................... 97 9.6.30 去除重复记录(Unique rows) .......................................................................... 98 9.6.31 分组(Group By) ............................................................................................ 100 9.6.32 设置为空值(Null if) ...................................................................................... 101 9.6.33 计算器(Calculator) .................................................................................. 102 9.6.34 增加XML(XML Add) ............................................................................. 104 9.6.35 增加常量(Add constants) ........................................................................ 106 9.6.36 行转列(Row Denormaliser) ..................................................................... 107 9.6.37 行扁平化(Flattener) ................................................................................. 108 9.6.38 值映射(Value Mapper) ............................................................................ 110 9.6.39 被冻结的步骤(Blocking step) ................................................................. 111 9.6.40 记录关联(笛卡尔输出)(Join Rows-Cartesian Product)....................... 112 9.6.41 数据库连接(Database Join) ..................................................................... 114 9.6.42 合并记录(Merge rows) ............................................................................ 115 9.6.43 存储合并(Stored Merge) ......................................................................... 116 9.6.44 合并连接(Merge Join) .................................................................................. 117 9.6.45 JavaScript 值(JavaScript Value) ............................................................. 119 9.6.46 改进的JavaScript 值(Modified JavaScript Value) ................................ 127 9.6.47 执行SQL 语句(Execute SQL script) ...................................................... 129 9.6.48 维度更新/查询(Dimension lookup/update) ............................................ 132 9.6.49 联合更新/查询(Combination lookup/update) ......................................... 133 9.6.50 映射(Mapping) ........................................................................................ 134 9.6.51 从结果获取记录(Get rows from result) .................................................. 135 9.6.52 复制记录到结果(Copy rows to result) .................................................... 135 9.6.53 设置变量(Set Variable) ........................................................................... 136 9.6.54 获取变量(Get Variable) ........................................................................... 137 9.6.55 从以前的结果获取文件(Get files from result) ....................................... 138 9.6.56 复制文件名到结果(Set files in result) .................................................... 139 9.6.57 记录注射器(Injector) .............................................................................. 140 9.6.58 套接字读入器(Socket Reader) ................................................................ 141 9.6.59 套接字输写器(Socket Writer) ................................................................. 141 9.6.60 聚合行(Aggregate Rows) ........................................................................ 142 9.6.61 流XML 输入(Streaming XML Input) .................................................. 143 9.6.62 中止(Abort) ............................................................................................. 149 9.6.63 Oracle 批量装载(Oracle bulk loader) ...................................................... 151 10. 任务设置(Job Settings) ........................................................................................... 153 10.1 描述 ....................................................................................................................... 153 10.2 屏幕截图 ............................................................................................................... 153 10.3 选项 ....................................................................................................................... 153 10.4 其它 ....................................................................................................................... 154 11. 任务条目(Job Entries) ............................................................................................. 154 11.1 描述 ....................................................................................................................... 154 11.2 任务条目类型 ....................................................................................................... 155 技术资料,【Kette3.0 用户手册】 ©深圳市神盾信息技术有限公司,2008 第4 页/共202 页 11.2.1 特殊的任务条目 ........................................................................................... 155 11.2.2 转换 ............................................................................................................... 157 11.2.3 任务 ............................................................................................................... 159 11.2.4 Shell .............................................................................................................. 161 11.2.5 Mail ............................................................................................................... 163 11.2.6 SQL ............................................................................................................... 165 11.2.7 FTP ................................................................................................................ 166 11.2.8 Table Exists ................................................................................................... 168 11.2.9 File Exists ...................................................................................................... 169 11.2.10 Evaluation(javascript) ................................................................................... 170 11.2.11 SFTP .............................................................................................................. 171 11.2.12 HTTP ............................................................................................................. 173 11.2.13 Create file ...................................................................................................... 175 11.2.14 Delete file ...................................................................................................... 176 11.2.15 Wait for file ................................................................................................... 177 11.2.16 File compare .................................................................................................. 178 11.2.17 Put files with secureFTP ............................................................................... 180 11.2.18 Ping a host ..................................................................................................... 181 11.2.19 Wait for .......................................................................................................... 182 11.2.20 Display Msgbox info ..................................................................................... 183 11.2.21 Abort job ....................................................................................................... 184 11.2.22 XSL transformation ....................................................................................... 185 11.2.23 Zip files ......................................................................................................... 186 12. 图形界面(Graphical View) ...................................................................................... 187 12.1 描述 ....................................................................................................................... 187 12.2 添加步骤或者任务条目 ....................................................................................... 188 12.2.1 拖放创建步骤 ............................................................................................... 188 12.2.2 从步骤类型树创建步骤 ............................................................................... 188 12.2.3 在你想要的位置创建步骤 ........................................................................... 189 12.3 隐藏步骤 ............................................................................................................... 189 12.4 转换步骤选项(右键上下文菜单) ................................................................... 189 12.4.1 编辑步骤 ....................................................................................................... 189 12.4.2 编辑步骤描述 ............................................................................................... 189 12.4.3 数据迁移 ....................................................................................................... 189 12.4.4 复制 ............................................................................................................... 189 12.4.5 复制步骤 ....................................................................................................... 189 12.4.6 删除步骤 ....................................................................................................... 190 12.4.7 显示输入字段 ............................................................................................... 190 12.4.8 显示输出字段 ............................................................................................... 190 12.5 任务条目选项(右键上下文菜单) ................................................................... 190 12.5.1 打开转换/任务 .............................................................................................. 190 12.5.2 编辑任务入口 ............................................................................................... 190 12.5.3 编辑任务入口描述 ....................................................................................... 190 12.5.4 复制任务入口 ............................................................................................... 190 技术资料,【Kette3.0 用户手册】 ©深圳市神盾信息技术有限公司,2008 第5 页/共202 页 12.5.5 复制选择的任务入口到剪贴板 ................................................................... 190 12.5.6 排列/分布 ...................................................................................................... 191 12.5.7 拆开节点 ....................................................................................................... 191 12.5.8 删除所有任务入口的副本 ........................................................................... 191 12.6 添加节点连接 ....................................................................................................... 191 12.7 运行转换 ............................................................................................................... 191 12.8 屏幕截图 ............................................................................................................... 191 12.9 执行选项 ............................................................................................................... 192 12.9.1 在哪里执行 ................................................................................................... 192 12.9.2 预览 ............................................................................................................... 192 12.9.3 使用安全模式 ............................................................................................... 192 12.9.4 日志级别 ....................................................................................................... 192 12.9.5 重放日期 ....................................................................................................... 192 12.9.6 参数 ............................................................................................................... 192 12.9.7 变量 ............................................................................................................... 192 12.10 设置远程或者从属服务器 ................................................................................... 193 12.10.1 概述 ....................................................................................................... 193 12.10.2 屏幕截图 ............................................................................................... 193 13. 日志(Logging) ......................................................................................................... 193 13.1 日志描述 ............................................................................................................... 193 13.2 屏幕截图 ............................................................................................................... 194 13.3 日志网格 ............................................................................................................... 194 13.3.1 转换日志网格 ............................................................................................... 194 13.3.2 任务日志网格 ............................................................................................... 195 13.4 按钮 ....................................................................................................................... 195 13.4.1 转换按钮 ....................................................................................................... 195 13.4.2 任务按钮 ....................................................................................................... 197 14. 网格(Grids) .............................................................................................................. 198 14.1 描述 ....................................................................................................................... 198 14.2 功能 ....................................................................................................................... 198 14.3 导航 ....................................................................................................................... 199 15. 资源库浏览器(Repository Explorer) ...................................................................... 199 15.1 描述 ....................................................................................................................... 199 15.2 屏幕截图 ............................................................................................................... 200 15.3 右键单击功能 ....................................................................................................... 200 15.4 备份/资源库 .......................................................................................................... 200 16. 共享对象(Share objects) ......................................................................................... 201