LOOKUP TRANSFORMATION的使用點評:
LOOKUP基本用法不熟的話請參考下附屬信息。
用法感受:
1 LOOKUP的作用跟我們以前在EXCEL的函數功能類似,就是隔表取值。優點就是用ETL工具可以設置CACHE,大量的 數據也可以實現這個功能。數據量大的話要設置CACHE ENABLE並調高CACHE SIZE的值。
2 LOOKUP 有CONNECTED 和UNCONNECTED的兩種,根據需要而用,如果很多字段要取對應的這個值的話,就用UNCONNECTED.在具體項目中要小心LOOKUP來處理維度列的情況,我目前項目中就發現,在LOOKUP中根據幾列來取出主鍵,結果數據並不完全能唯一區別,最后要做數據清理或引入代理鍵。
3 關於緩慢變化維處理,用LOOKUP加UPDATESTRATERY組件就可實現緩慢變化維的更新或插入,這是數據倉庫項目中處理緩慢變化維比較經典的用法,我認為。
順帶粘貼些關於LOOKUP的參考信息,了解的,請忽略以下信息,呵呵:
Lookup
概要描述
獲得一個關聯的值。例如:源里包含employee ID,但你還需要employee name。用於計算的植。例如:只是匯率或者個人所得稅之類的固定數值,不是計算得出來的數據。Update slowly changing dimension tables。主要是根據條件查出原表,若查出了,就把自己添加的標志位設為真,否則就設置為假。
Connected or unconnected
Connected 和 unconnected 的transformations的輸入和輸出是不同的,不同點如表2列出的。
表2
| Connected Lookup |
Unconnected Lookup |
| 從 pipeline獲得輸入。 |
從另一個transformation的:LKP的表達式獲得輸入。 |
| 使用靜態或者動態cache。 |
使用靜態cache。 |
| Cache中包括所有的 mapping中使用到的lookup columns(就是condition中的和被標記為輸出的columns)。 |
Cache中包括所有condition中的、被標記為輸出的columns以及被標記為return port的。 |
| 同行能夠返回多個columns 或者加載到動態lookup cache中。 |
每行只能返回一個return port (R)。 |
| 如果沒有匹配的數據,Integration Service會返回一個默認值。如果是動態緩存(cache),會加入一個新的行或者放着他不管。 |
如果沒有匹配的數據,Integration Service會返回一個NULL。 |
| 如果有匹配的數據,Integration Service回返回一個結果包括所有被設置為輸出的值。如果是動態緩存,Integration Service會任意的修改一行或者放着它不管。 |
如果有匹配的數據,Integration Service會返回一個被設置為return port的值。 |
| 輸出所有的被標記為output的符合條件的數據。 |
返回一個值到使用:LKP調用它的表達式。 |
| 用戶可以設置默認值。 |
用戶不可以設置默認值。 |
Connected
下面是Integration Service處理connected Lookup transformation的過程:
- 一個connected Lookup transformation通過pipeline從其他的transformation獲得輸入值。
- 為每個輸入行,Integration Service會通過lookup ports 和 condition從源或者緩存中查詢。
- 如果組件沒有使用緩存或者使用的靜態緩存,Integration Service會使用lookup query來返回值。
- 如果組件使用的動態緩存,當Integration Service在緩存找不到這行,它會把這行插入到緩存中。當Integration Service找到這行,它會修改這行在緩存中或者什么都不做。它標記這行是插入、修改或者是不做變動。
- Integration Service從查詢中返回值到下一個transformation。
如果transformation使用動態緩存,你可以把這行通過Filter 或者 Router transformation來過濾后在到目標中。
unconnected
- 可以在一個mapping中調用這個Lookup transformation多次。
- 下面的步驟描述了Integration Service處理一個unconnected Lookup transformation的過程:
1. 一個unconnected Lookup transformation從另一個transformation的一個:LKP表達式的結果中獲得輸入值,例如一個Update Strategy transformation。
2. Integration Service通過transformation 中的lookup ports 和 condition來查詢。
3. Integration Service返回一個值到Lookup transformation 的return port 中。
4. Integration Service把值返回到:LKP表達式中。
- 步驟
-
- 添加input ports。
- 添加查詢條件。
- 指定返回值。
- 從其他的組件中調用該lookup。
- 用途
unconnected lookups多數用於:
- 在一個表達式測試一個lookup的值。
- 在查詢的基礎上過濾。
- 標記行基於查詢的結果,例如:updating slowly changing dimension tables。
- 調用同一個查找多次在一個mapping中。
Relational or flat file lookup
當你在建立一個Lookup transformation時,你可以選擇查詢flat file或者relational table。
Relational
可以通過SQL的來override默認的SQL,這樣可以你可以加where或者查詢多個表。
flat file
使用下面選項在使用flat file時:
- 指定源是indirect files的。
- 使用sorted輸入。
Tips
- 使用這些技巧在你配置一個Lookup transformation的時候:
- 給被用於查詢條件的列加一個索引。
- 把=號放在條件的第一位。
- 查詢的時候,完全加載小的表。
- 在數據庫中Join tables比使用查詢要高校的多。
- 為靜態cache設置固定的大小。
- 使用:LKP來調用unconnected Lookup transformations。
Cached or uncached
有時,你可以在使用lookup組件查詢表的時候,把組件設置成Cached 的來提高session的速度。如果你選擇了Cached ,你可以選擇使用動態的還是靜態的。默認的是使用靜態的。
Cached
可以在一個lookup組件中為要查詢的表配置cache。當第一行數據進入lookup組件的時候,Integration Service會在內存為它建立一個cache。它分配內存基於你在組件或者session的屬性中配置的數量。Integration Service把條件值保存索引cache,把output值保存在數據cache。Integration Service會為每一條進入這個組件的行查詢cache。
Integration Service也同樣會建立cache files用$PMCacheDir(相對路徑,在consol中可以配置)中默認的。如果數據不適合內存cache時,Integration Service把超出的數據保存到cache files中。當seesion結束,Integration Service會釋放cache記憶和刪除cache files,除非你配置組件使用持久化的cache。
如果你使用flat file lookup,Integration Service總是會把它放在cache中。如果你配置flat file lookup為sorted input,Integration Service不會把它放入cache,如果條件類不是分組的。如果這些列是分組的,但是沒有sorted,Integration Service會處理這個查詢的方式和沒有配置sorted input一樣。
當你配置了lookup cache,你可以配置如下cache選項:
Building caches:你可以配置session建立多個cache用串行或者並行。當你建立串行的cache時,Integration Service會按照源行進入的順序建立cache。當你建立並行的cache時,Integration Service不會等第一行進入Lookup transformation,就會建立cache。代替的是建立多個並行的cache。
Persistent cache:你可以保存lookup cache files並重用他們在Integration Service調用一個配置使用該cache的Lookup transformation。
Integration Service 對Persistent Caches的處理:
| Mapping or Session Changes Between Sessions |
Named Cache |
Unnamed Cache |
| Integration Service cannot locate cache files. |
Rebuilds cache. |
Rebuilds cache. |
| Enable or disable the Enable High Precision option in session properties. |
Fails session. |
Rebuilds cache. |
| Edit the transformation in the Mapping Designer, Mapplet Designer, or Reusable Transformation Developer.* |
Fails session. |
Rebuilds cache. |
| Edit the mapping (excluding Lookup transformation). |
Reuses cache. |
Rebuilds cache. |
| Change database connection or the file location used to access the lookup table. |
Fails session. |
Rebuilds cache. |
| Change the Integration Service data movement mode. |
Fails session. |
Rebuilds cache. |
| Change the sort order in Unicode mode. |
Fails session. |
Rebuilds cache. |
| Change the Integration Service code page to a compatible code page. |
Reuses cache. |
Reuses cache. |
| Change the Integration Service code page to an incompatible code page. |
Fails session. |
Rebuilds cache. |
| *Editing properties such as transformation description or port description does not affect persistent cache handling. |
||
Recache from source:當持久化的cache不是同步的時候,你可以配置Lookup transformation重新建立新的cache。
Static cache:你可以為所有的lookup source配置一個靜態,或者只讀的cache。默認的,Integration Service建立靜態的cache。它為所有進入組件的lookup file或者 table 以及 looks up values建立cache。當條件為真的時候,Integration Service從cache中返回一個值。
Dynamic cache:為一個target table或者flat file source建立cache,並且向cache中插入新的行或者修改現有的行,當使用動態cache。在cache中, Integration Service動態的插入或者修改數據並且把數據傳到目標中。
Shared cache:你可以共享cache在多個組件之間。你可以共享一個匿名的cache在一張mapping中。你可以共享一個有名的cache在同一個或者不同的mapping中。
當你沒有為Lookup transformation配置cache,Integration Service為每一個輸入行查詢查詢表。結果和處理過程是同樣的,不論你是否設置cache。然而,使用cache可以改善session的性能。當被查詢的表很大的時候可以使用cache最大的優化性能。
Cache Comparison
uncached lookup, static cache, dynamic cache的區別:
| Uncached |
Static Cache |
Dynamic Cache |
| 你不可以向cache中插入或者修改。 |
你不可以向cache中插入或者修改。 |
你可以向cache中插入或者修改,並且可以向目標傳輸。 |
| 不可以進行flat file的查詢。 |
可以進行relational 或者 flat file的查詢。 |
可以進行relational 或者 flat file的查詢。 |
| 當條件為真的時候,Integration Service從表或者cache中返回一個值。 當條件為假的時候,Integration Service返回一個默認值或者為非連接組件返回NULL。 |
當條件為真的時候,Integration Service從表或者cache中返回一個值。 當條件為假的時候,Integration Service返回一個默認值或者為非連接組件返回NULL。 |
當條件為真的時候,Integration Service會根據行的類型來修改或者放着它不管。你可以向目標傳輸修改后的行。 當條件為假的時候,the Integration Service會根據行的類型來插入或者放着它不管。這意味着行不在cache或目標中。你可以把插入的行傳給目標表。 |
