kettle使用教程-1


第1章 kettle概述

1.1 什么是kettle

Kettle是一款開源的ETL工具,純java編寫,可以在Window、Linux、Unix上運行,綠色無需安裝,數據抽取高效穩定。

1.2 Kettle核心知識點

1.2.1 Kettle工程存儲方式

1) 以XML形式存儲

2) 以資源庫方式存儲(數據庫資源庫和文件資源庫)

1.2.2 Kettle的兩種設計

簡述:Transformation(轉換):完成針對數據的基礎轉換。

Job(作業):完成整個工作流的控制。

區別:(1)作業是步驟流,轉換是數據流,這是作業和轉換的最大區別

(2)作業的每一個步驟,必須等到前面的步驟都跑完了,后面的步驟才會執行;而轉換會一次性把所有控件全部先啟動(一個空間對應啟動一個線程),然后數據流會從第一個控件開始,一條記錄,一條記錄地流向最后的控件。

 

1.2.3 Kettle的組成

勺子(spoon.bat/spoon.sh):是一個圖形化的界面,可以讓我們用圖形化的方式開發轉換和作業。Windows選擇spoon.bat;Linux選擇spoon.sh
煎鍋(pan.bat/pan.sh):利用pan可以用命令行的形式調用Trans
廚房(kitchen.bat/kitchen.sh):利用kitchen可以使用命令調用Job
菜單(carte.bat/carte.sh):carte是一個輕量級的web容器,用於建立專用、遠程的ETL Server
1.3 kettle特點

免費開源:基於Java的免費開源的軟件,對商業用戶也沒有限制

易配置:可以在window、Linux、unix上運行,綠色無需安裝,數據抽取高效穩定

不同數據庫:ETL工具集,它允許你管理來自不同數據庫的數據

兩種腳本文件:transformation和job,transformation完成針對數據的基礎轉換,job則完成整個工作流的控制

圖形化界面設計:通過圖形化設計實現做什么業務,無需寫代碼去實現

定時功能:在job下的start模塊,有一個定時功能,可以每日、每周等方式進行定時。

第2章 kettle安裝部署和使用
2.1 kettle安裝地址

官網地址

https://community.hitachivantara.com/docs/DOC-1009855

下載地址

https://sourceforge.net/projects/pentaho/files/Data%20Integration/

kettle各版本國內鏡像下載地址:http://mirror.bit.edu.cn/pentaho/(下載速度相對快一些)

2.2 Windows下安裝使用

2.2.1 概述

在實際企業開發中,都是在本地環境下進行kettle的job和Transformation開發的,可以在本地運行,也可以連接遠程機器運行

2.2.2 安裝

1) 安裝jdk

2) 下載kettle壓縮包,因kettle為綠色軟件,解壓縮到任意本地路徑即可

3) 雙擊Spoon.bat,啟動圖形化界面工具,就可以直接使用了

2.2.3 案例

1) 案例一 把stu1的數據按id同步到stu2,stu2有相同id則更新數據

(1)在mysql中創建兩張表

mysql> create database kettle;

mysql> use kettle;

mysql> create table stu1(id int,name varchar(20),age int);

mysql> create table stu2(id int,name varchar(20));

 

 

 

 

(2)往兩張表中插入一些數據

mysql> insert into stu1 values(1001,'zhangsan',20),(1002,'lisi',18), (1003,'wangwu',23);

mysql> insert into stu2 values(1001,'wukong');

 

 

 

 

(3)在kettle中新建轉換

 

 

 

4、然后新建兩個數據庫的連接

 

 

 

kettle通過域名或者IP連接Oracle,因為今天客戶要求把數據庫由原來的MySQL切換到Oracle,歷史數據的遷移。本篇博客主要講解kettle連接Oracle數據庫。本機不需要安裝Oracle,但是要把Oracle的驅動jar包復制到kettle的lib目錄下:

Oracle驅動jar包:(包括:ojdbc5.jar、ojdbc6.jar、ojdbc7.jar、ojdbc8.jar、ojdbc10.jar、ojdbc14.jar)

鏈接: https://pan.baidu.com/s/1DMB8vF_iFqJsyi7YoJnvHA

提取碼: zdm6

我這里用的是:ojdbc6.jar

准備工作完成,下面連接Oracle:

 

 

 

主機名稱:不用填

數據庫名稱:填寫域名或者IP:端口/服務名

數據表空間:不用填

索引表空間:不用填

端口號:-1,因為再填寫數據庫名稱時已經填寫,所以這里填寫-1

用戶名:用戶名

密碼:密碼

點擊:測試

 

 

 

然后就是MySQL的

 

點擊測試

 

 

 

 

 

還有就是一開始沒導入MySQL的驅動也會報錯:如下

錯誤連接數據庫 [test] : org.pentaho.di.core.exception.KettleDatabaseException: 
Error occurred while trying to connect to the database

Driver class 'org.gjt.mm.mysql.Driver' could not be found, make sure the 'MySQL' driver (jar file) is installed.
org.gjt.mm.mysql.Driver


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

Driver class 'org.gjt.mm.mysql.Driver' could not be found, make sure the 'MySQL' driver (jar file) is installed.
org.gjt.mm.mysql.Driver


	at org.pentaho.di.core.database.Database.normalConnect(Database.java:472)
	at org.pentaho.di.core.database.Database.connect(Database.java:370)
	at org.pentaho.di.core.database.Database.connect(Database.java:341)
	at org.pentaho.di.core.database.Database.connect(Database.java:331)
	at org.pentaho.di.core.database.DatabaseFactory.getConnectionTestReport(DatabaseFactory.java:80)
	at org.pentaho.di.core.database.DatabaseMeta.testConnection(DatabaseMeta.java:2783)
	at org.pentaho.ui.database.event.DataHandler.testDatabaseConnection(DataHandler.java:597)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.pentaho.ui.xul.impl.AbstractXulDomContainer.invoke(AbstractXulDomContainer.java:313)
	at org.pentaho.ui.xul.impl.AbstractXulComponent.invoke(AbstractXulComponent.java:157)
	at org.pentaho.ui.xul.impl.AbstractXulComponent.invoke(AbstractXulComponent.java:141)
	at org.pentaho.ui.xul.swt.tags.SwtButton.access$500(SwtButton.java:43)
	at org.pentaho.ui.xul.swt.tags.SwtButton$4.widgetSelected(SwtButton.java:137)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
	at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
	at org.eclipse.swt.widgets.Display.sendEvent(Unknown Source)
	at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
	at org.eclipse.jface.window.Window.runEventLoop(Window.java:820)
	at org.eclipse.jface.window.Window.open(Window.java:796)
	at org.pentaho.di.ui.xul.KettleDialog.show(KettleDialog.java:80)
	at org.pentaho.di.ui.xul.KettleDialog.show(KettleDialog.java:47)
	at org.pentaho.di.ui.core.database.dialog.XulDatabaseDialog.open(XulDatabaseDialog.java:116)
	at org.pentaho.di.ui.core.database.dialog.DatabaseDialog.open(DatabaseDialog.java:60)
	at org.pentaho.di.ui.spoon.delegates.SpoonDBDelegate.editConnection(SpoonDBDelegate.java:96)
	at org.pentaho.di.ui.spoon.Spoon.doubleClickedInTree(Spoon.java:3108)
	at org.pentaho.di.ui.spoon.Spoon.doubleClickedInTree(Spoon.java:3043)
	at org.pentaho.di.ui.spoon.Spoon.access$2300(Spoon.java:361)
	at org.pentaho.di.ui.spoon.Spoon$26.widgetDefaultSelected(Spoon.java:6184)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
	at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
	at org.eclipse.swt.widgets.Display.sendEvent(Unknown Source)
	at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
	at org.pentaho.di.ui.spoon.Spoon.readAndDispatch(Spoon.java:1366)
	at org.pentaho.di.ui.spoon.Spoon.waitForDispose(Spoon.java:8022)
	at org.pentaho.di.ui.spoon.Spoon.start(Spoon.java:9277)
	at org.pentaho.di.ui.spoon.Spoon.main(Spoon.java:692)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.pentaho.commons.launcher.Launcher.main(Launcher.java:92)
Caused by: org.pentaho.di.core.exception.KettleDatabaseException: 
Driver class 'org.gjt.mm.mysql.Driver' could not be found, make sure the 'MySQL' driver (jar file) is installed.
org.gjt.mm.mysql.Driver

	at org.pentaho.di.core.database.Database.connectUsingClass(Database.java:515)
	at org.pentaho.di.core.database.Database.normalConnect(Database.java:456)
	... 47 more
Caused by: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at org.pentaho.di.core.database.Database.connectUsingClass(Database.java:490)
	... 48 moreqq'y'd

 

 

加入驅動是這個,放在目錄lib中

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM