Namaskaram Friends!
Here is a short post on how to write custom python code inside ODI.
What does this mean?
If you look at the concept of Procedures in ODI, you will find that the procedures can be written for a number of technologies, using the technology drop down.
This flexibility makes it a beautiful product, where you can write your procedure in any given technology if the integration project involves a lot of different technologies.
Python is a well known language these days, which is used in a number of industries because of its rich set of libraries.
In this post let's try to explore how to write Python code in ODI ( I am using ODI 11g version here).
Let's work on a very simple scenario:
Lets say we are working on a Data integration project where the client gives us a location to pick the file, and process it using Interfaces (file to table).
The step is,before we process the interface we need to check whether the file exist in the given location/path or not.
To accomplish this task we will write simple python code.
Create a Procedure name it CheckFile, select the Technology as Jython.
Don't get confused, Jython is Python language implementation that is tightly integrated with the Java Platform. So all the python code is still applicable here
Here is the python code: (take care of the indentation, because python works on the concept of indentation to define its scope, else the code will throw error)
import os
from os import path
def main():
file_path="D:\\empdata.txt"
#The above file_path can also be an odi variable which queries the location from some configuration table, that makes the solution even more configurable.
my_file = os.path.exists(file_path)
if my_file:
print("path does exist")
return 0
else:
raise
#You can write your custom python code here to do mitigations in the else section.
if __name__=="__main__":
main()
The procedure checks whether the file exists in the mentioned path or not.
Create a package like this:
When you execute the package, it will first check if the file exist or not, if the file does not exist it will perform the things that you would have mentioned in the else part of your python code.
Hope this would have been useful!!!
Peace
No comments:
Post a Comment