ODI 11g - Dynamic and Flexible Code Generation
Posted
by David Allan
on Oracle Blogs
See other posts from Oracle Blogs
or by David Allan
Published on Mon, 10 Dec 2012 16:39:02 +0000
Indexed on
2012/12/10
17:14 UTC
Read the original article
Hit count: 403
/Oracle
ODI supports conditional branching at execution time in its code generation framework. This is a little used, little known, but very powerful capability - this let's one piece of template code behave dynamically based on a runtime variable's value for example. Generally knowledge module's are free of any variable dependency. Using variable's within a knowledge module for this kind of dynamic capability is a valid use case - definitely in the highly specialized area.
The example I will illustrate is much simpler - how to define a filter (based on mapping here) that may or may not be included depending on whether at runtime a certain value is defined for a variable. I define a variable V_COND, if I set this variable's value to 1, then I will include the filter condition 'EMP.SAL > 1' otherwise I will just use '1=1' as the filter condition. I use ODIs substitution tags using a special tag '<$' which is processed just prior to execution in the runtime code - so this code is included in the ODI scenario code and it is processed after variables are substituted (unlike the '<?' tag).
So the lines below are not equal ...
- <$ if ( "#V_COND".equals("1") ) { $> EMP.SAL > 1 <$ } else { $> 1 = 1 <$ } $>
- <? if ( "#V_COND".equals("1") ) { ?> EMP.SAL > 1 <? } else { ?> 1 = 1 <? } ?>
When the <? code is evaluated the code is executed without variable substitution - so we do not get the desired semantics, must use the <$ code. You can see the jython (java) code in red is the conditional if statement that drives whether the 'EMP.SAL > 1' or '1=1' is included in the generated code. For this illustration you need at least the ODI 11.1.1.6 release - with the vanilla 11.1.1.5 release it didn't work for me (may be patches?). As I mentioned, normally KMs don't have dependencies on variables - since any users must then have these variables defined etc. but it does afford a lot of runtime flexibility if such capabilities are required - something to keep in mind, definitely.
© Oracle Blogs or respective owner