Skip to content

June 20, 2010
by kdevendr
3 Comments

Categories: How to , Logic , ODI , Reports , Tips and Tricks

Tags: ,

Single Post View


Writing SQL counts using Jython

Hi everyone , few post back we have shown how to get the count in Operator but there are many time you may want to get the count of records by email once the data got loaded. To solve this we have written a simple jython procedure to get and count and attach the file as Email and set up the process

Here is a simple Jython Procedure to  do that  .

import string
import java.sql as sql
import java.lang as lang
import re
sourceConnection = odiRef.getJDBCConnection("SRC")
output_write=open('c:/count_write.txt','w')
sqlstring = sourceConnection.createStatement()
print >> output_write, " The counts are .... 'n'"
#---------------------------------------------------------------
# QUERY 1 COUNT
#---------------------------------------------------------------

sqlstmt="select count(*) as rowcount from all_tables where owner='ODI_TEMP'"
result=sqlstring.executeQuery(sqlstmt)
while result.next():
count=result.getInt("rowcount")
rs='n'+str(sqlstmt)+'nn'+str(count)

print >> output_write ,rs

#---------------------------------------------------------------
# QUERY 2 COUNT
#---------------------------------------------------------------

sqlstmt="select count(*) as rowcount from all_tables where owner='ODI_WORK'"
result=sqlstring.executeQuery(sqlstmt)
while result.next():
count=result.getInt("rowcount")
rs='n'+str(sqlstmt)+'nn'+str(count)

print >> output_write ,rs

#---------------------------------------------------------------
# QUERY 3 COUNT
#---------------------------------------------------------------

sqlstmt="select count(*) as rowcount from all_tables where owner='SYSTEM'"
result=sqlstring.executeQuery(sqlstmt)
while result.next():
count=result.getInt("rowcount")
rs='n'+str(sqlstmt)+'nn'+str(count)

print >> output_write ,rs

sourceConnection.close()
output_write.close()

and you get the output in similar form.

image

Just replace the  sql count query according to your requirement.

and provide the  schema in the ‘Command on Source ‘ which have the select permission on the required table for which the counts are being retrieved.

image

Download the Codes here

Download XML

April 12, 2010
by Cezar Santos
21 Comments

Categories: Architecture , How to , Logic , ODI , Tips and Tricks

Tags: , , , , , , , , ,

Single Post View


Getting one or several unknown files from a directory

Hi Friends…

Today I would like to share with you a way that I have been using for several years, to get unknown files from a directory in Oracle Data Integrator.

For instance, if you have files in a directory that had no controlled names but needs to be load by ODI, here there are an option:

The hole idea is based in create a file with contains all file names and read it from ODI.

(Windows example but pretty much the same at Unix/Linux)

  1. Create an ODI Procedure with a single step.
    • Source Tab
    • Technology: OS Command
    • Code:  cmd /c dir c:my_directory*.* /b /a:-d > c:my_directoryAll_Files_Names.txt
  2. Now use the technique describe at: http://odiexperts.com/?p=273 to read each line at time  using the All_Files_Names.txt as source.

So simple like that… all you need to do is, before go to the next line (loop) use the variable in the way that you want!

An example is use it as name for a datastore that is used as source in an interface, than you can call the interface once to each variable value allowing to load all files from that directory.

I hope this technique could help you guys…

Best Regards,

Cezar Santos

April 9, 2010
by Cezar Santos
32 Comments

Categories: Administration , Architecture , How to , ODI , Tips and Tricks

Tags: , , , , , , , , , ,

Single Post View


Interface Parallel Execution – A new solution

Hi Friends,

Two days ago Devendra talk to me about parallel executions in ODI and we are discussing the solution from Oracle Metalink that works but, at true, I never was stopped to analyse.

In face of that, I decided try something in a  new way and it worked fine!

Let me share my 2 minutes approach.

Problem Description:

Oracle Data Integrator uses the target table name to build the work tables (I$, E$, C$) and, because of that if more then one interface that loads the same target table is executed at same time the work tables creation, insert and drop process got mixed and nothing works.

Solution:

The solution is pretty obvious… It is necessary to make the work table name variable and linked to each execution. The ODI path for that is the Session Number.

My approach:

All solutions that I saw until today uses an Oracle Data Integrator variable but got problems if the table name is near to the maximum name length allowed for the technology.

In face of that, I decide to use the ODI natural behavior to manage the lenght.

All that is necessary to do is:

1. Edit all your KM (IKM and LKM if some) and add a new step (move it to be the first step)

Step Name: Parallel Setup

Technology:  Java Bean Shell

Code:  <? String vSess = odiRef.getSession(“SESS_NO”); ?>

Importante note: this change can be done to any KM that will not interfier with process not parallel

2. Go to Topology Module, in the Physical Schema that will have parallel execution (or in all if you wish) and change the Work Table Prefix to:

E$_<?=vSess?>

C$_<?=vSess?>

I$_<?=vSess?>

Well my friends… that is all! Any Parallel or Single execution can be executed with no conflicts between work table name or length name  problem will be raise.

The best about it is be very simple!!!

See you all in next post!

Regards,

Cezar Santos

April 4, 2010
by kdevendr
5 Comments

Categories: How to , Logic , ODI , Tips and Tricks

Tags: , ,

Single Post View


Displaying SQL results in Operator

Few posts back i have shown ,how to display the value of the variable using Jython and today i am showing how to display  SQL  Query result  in the operator.

— Displays the Sql results of query into Operator –

import string
import java.sql as sql
import java.lang as lang
sourceConnection = odiRef.getJDBCConnection("SRC")
sqlstring = sourceConnection.createStatement()
result=sqlstring.executeQuery("select table_name,owner from all_tables where owner='ODI_TEMP'")
i=0
rs=[]
while (result.next()):
    rs.append(str(i)+'t'+str(result.getString("table_name"))+'tt'+str(result.getString("owner"))+' , ')
    i=i+1

res='n'.join(map(string.strip,rs))
raise res
sourceConnection.close()

In  sourceConnection = odiRef.getJDBCConnection(“SRC”), the connection details are retrieved from ODI , to do so in the ‘ command on  Source tab’  – Select the Technology and required Schema so that ODI can retrieve the connection details.

image

result=sqlstring.executeQuery(“select table_name,owner from all_tables where owner=’ODI_TEMP'”)

# Enter the query between the two double quotes or replace the above query .

rs.append(str(i)+’t’+str(result.getString(“table_name”))+’tt’+str(result.getString(“owner”))+’ , ‘)

# For every column you mention in the above query – get them under result.getString(“Column_Name”)

# as for my example i am having two column so iam calling getString twice , similarly do so for every column

# called in the Select statement

In the Target technology select  ‘  Jython ‘

image

Enable  the ‘ Ignore Errors’ option.

Sample Output

image

– Codes to display the Row count –

import string
import java.sql as sql
import java.lang as lang
sourceConnection = odiRef.getJDBCConnection("SRC")
sqlstring = sourceConnection.createStatement()
sqlstmt="select count(*) as rowcount from all_tables where owner='ODI_TEMP'"
result=sqlstring.executeQuery(sqlstmt)
while result.next():
    count=result.getInt("rowcount")

rs='n'+str(sqlstmt)+'nn'+str(count)
raise rs
sourceConnection.close()

Sample Output

image

April 4, 2010
by kdevendr
17 Comments

Categories: How to , ODI , Tips and Tricks

Tags: , , , ,

Single Post View


Flow Control and Static Control

Flow Control

– If enabled this option uses the CKM selected and applies before loading into the target thus avoiding wrong data to get loaded

clip_image001

What actually happening in the above flow is that , After loading the data into I$,

  • a check table is created (SNP_CHECK_TAB) , deleting previous error table  and previous errors as ODI generally does.
  • Now it creates a new Error table , and check for Primary key unique constraints , other constraints and conditions defined in Database or Model level ODI conditions and Not Null check for each column marked as Not null.
  • If records violate the above constraints and conditions, it  adds the required records into E$ table and add an entry of it into SNP_CHECK_TAB with information about schema, error message , count etc.
  • Finally the other records are inserted and updated as per the KM and logic.

E$ Table

clip_image002

In the E$ table , the completed columns and the error message including error count and constraint name is record with associated ROW_ID.

SNP_CHECK_TAB

image

Static Control

– If enabled this option used the CKM selected and applied after loading into the target.

clip_image004

Here being the PK constraint on Target table , Insert has failed .

Lets see an example where the target table has no constraint at the database level but we are applying at the ODI level

image

Key is applied on the Employee_ID at the ODI Level.

clip_image006

Here after inserting into the target table , it uses the CKM selected and check for all the constraints and conditions and finally loads the rejected records into E$ and SNP_CHECK_TAB.

clip_image007

Check at the Datastore Level.

To check for the constraint or mostly bad records at the source side , ODI have option called check at the Datastore and when checked run the CKM on that particular datastore and stores the values into the respective E$ table.

clip_image008

clip_image009

After fetching the required errors if found makes an E$ table and makes an entry at SNP_SCHECK_TAB.

Constraints , conditions and duplicated can be checked at the datastore level too

clip_image010

clip_image011

Checking duplicate –

clip_image012

Foreign Key Constraints

clip_image013

Or run Check at the datastore level for complete check for all the constraint using the CKM defined in the model.

clip_image014

Recycle Errors

ODI KM’s have an option called Recycle Errors , what actually happens is that ODI reads from the E$ tables and loads into the I$ capturing all the records which are not present in the I$ by matching on the Primary Key or Unique Keys.

Lets look at an example , here  i am having an two duplicate rows stored in my E$ table , now iam going to make remove one duplicate record.

image

I am making changes into the Source File ( for my Example) and saving and re run the interface

image

image

The new records is inserted and the records are also deleted from the error tables.

image

image

March 28, 2010
by kdevendr
3 Comments

Categories: Administration , Architecture , How to , ODI , Technology , Tips and Tricks

Tags: , , , , , ,

Single Post View


Export DWR to EWR [ Common Master Rep ]

This post explain the process of Exporting Scenarios from DWR to EWR .  As Cezar have suggested in previous post of how it is important to have one single DWR ( Developer Work Repository) and multiple EWR [ Execution Work Repository ] , As Multiple  DWR can lead to improper code maintains and improper synchronization between the multiple DWR.    Read more this post here

In this present example i am moving from my DWR to EWR [ Testing Environment ] .

Generally before the UAT , its important to have an Testing environment  where Scenarios functionality, code Testing , Data Validity  is tested. I strongly feel that it is import to have such an environment before releasing to UAT so that less codes fail at the UAT and multiple minor issues can be fixed at this stage thus avoiding more failure at the next stages.

In this example i am creating the EWR in the same Master Repository and using a different context and agent but its is not necesarry to do so,  if both are in the same box ,  the only draw back i see is that using the same agent for  Development and Testing can lead to performance degradation , but again its the architecture and the requirement which matter requiring to understand in  how to handle the resources.

Step 1

  –   Creating the Execution Work Repository  schema, tablespace and other Database permission for users.

Step 2

  –  Creating the EWR in ODI Topology Manager..

Right click – > Insert Work Repository .

Provide the required Meaningful name ,  EWR  schema user/password   created in step 1

image

Provide the  JDBC Driver, URL.

image

Click Test  and Once Successful Click Apply and OK.

Provide the new ID , make sure the ID different from the  other DWR created .  Select ‘ Execution ‘ type  and provide a meaningful Name as that will be your  Execution Work Repository Name.  click Ok once done.

image 

We have our  EWR created

image

As you can see that in EWR , mostly tables related to Scenarios , Sessions  , Sequence , Variables tables are created and the work tables in  EWR are less than the DWR since in EWR mostly information related to scenarios, sessions are mattered a lot.

image

Also  EWR  , access to  Operator , Topology  and Security Manager are allowed . As the name suggestion Execution Work Repository so only  Scenarios are allowed to be imported into this environment and so designer are not created in EWR .

Step 3

  –  Logging into EWR Operator.

image

image

Now we will move our Scenarios from DWR to EWR

Step 4

–  Transfer of Scenarios from DWR to EWR

Log into Operator  of DWR .

Right Click on the Scenario to be Exported and selected the Folder.

image

image

image

Always use the insert_update mode so the in the future when you try to insert or update ODI can automatically identify the scenario and make the necessary insertion and updation and less code corruption.

image

image

Using Solutions

Solution is great when the client or architecture demans to track each code flow from one environment and to the other ,as solution creates version for insertion and for every transfer so at the end there can be multiple version of the same objects . As i have said before its the requirement that matter , in case if solution have to be used use Description to provide as much details as possible

say for example

Description .

1. Fixed the Invalid_number issue

2. Logic for Data validation is changed by this example and so on.

Doing so can provide more help and information for the administrator or the user in  getting older and newer codes  into the other environment as the demand requires.

Go the DWR  operator  – > Insert Solution

image

Provide the Solution Name  and drag in the scenario  into Principal Elements.  Solution creates Version for every Insert you do .  Solution are great when you would like to track each scenario and roll back to previous versions.

image

image

Click yes on the above  warning and keep adding as many scenarios to the Solution.

image

image

Since  Solution are created in Master Repository[ SNP_VERSION] , you can find that in other Work Repository.

image

We are going to extract the scenarios from the Solution created above. To do so , Right click – > Restore All Elements and click yes for the below warnings

image

image

Once restored , all the scenarios are imported into the other environment.

image

Step 5

– create a new Context ‘ XMT_TEST’ 

[ NOTE : – Make sure you create a new Work Schema for Testing as it will be easy to Testing and Debugging the $ tables ]

image

step 6

– Creating Data Servers  and Physical Schema . [ Being a testing environment i am using the same development source box  and so only the target structure is replicated for the newer envrionment, thus creating the new Dataserver and Physical schema and link them to the respective Logical Schema  ]

image

Create the Physical schema and Link the to the already created Logical Schema using the new Context

image

image

Keep repeating the same steps for other physical schemas.

Step 7

– Create Agents for the new Testing environment.

image

Step 8

– Lets test the scenario using the newly created context.

image

image

image

March 28, 2010
by kdevendr
0 comments

Categories: ODI , Reports , Tips and Tricks

Tags: , ,

Single Post View


Scenario Report

This below query provide details about each scenario and its associated session  run details in the operator . This enables to get details about each run whether it was successful , record processed , inserted and updated and duration in hours and other statistical information about each scenario.

SELECT
SS.SCEN_NAME AS SCENARIO_NAME ,
SS.SCEN_VERSION AS SCEN_VERSION ,
SSR.SCEN_RUN_NO AS SESS_NO,
SSR.SESS_DUR AS DUR,
CASE
WHEN SSR.SESS_DUR <61 THEN SSR.SESS_DUR||' SEC'
WHEN SSR.SESS_DUR BETWEEN 61 AND 3600 THEN (SSR.SESS_DUR/60)||' MIN'
WHEN SSR.SESS_DUR > 3600 THEN (TRUNC(SSR.SESS_DUR/3600)||' HR '||TRUNC(MOD(SSR.SESS_DUR,3600)/60)||' MIN')
END AS DURATION,
-- The above CASE statement is to show the duraion in hrs , min and seconds
-- rather than manual calculating when the session run for multiple hours
DECODE(SSR.SESS_STATUS,'D','SUCCESSFUL'
,'E','FAILED')AS STATUS,
SSR.NB_ROW AS ROW_PROCESSED,
SSR.NB_INS AS ROWS_INSERTED,
SSR.NB_UPD AS ROWS_UPDATED,
SSR.NB_DEL AS ROWS_DELETED,
SSR.NB_ERR AS ERROR_RECORD,
CASE
WHEN TO_CHAR(SSR.SESS_END,'MM-DD-YYYY')=TO_CHAR(SSR.SESS_BEG,'MM-DD-YYYY')
THEN TO_CHAR(SSR.SESS_END,'MM-DD-YYYY')
ELSE TO_CHAR(SSR.SESS_BEG,'MM-DD-YYYY')||'-TO-'||TO_CHAR(SSR.SESS_END,'MM-DD-YYYY')
END AS SESSION_RAN_DATE
FROM SNP_SCEN SS
LEFT OUTER JOIN SNP_SCEN_REPORT SSR ON SS.SCEN_NO=SSR.SCEN_NO
WHERE SSR.SCEN_RUN_NO IS NOT NULL
ORDER BY SCENARIO_NAME,SSR.SESS_END

image

March 27, 2010
by kdevendr
4 Comments

Categories: ODI , Tips and Tricks

Tags: , ,

Single Post View


Asynchronous -Parallel Execution

In ODI interface can be called parallel through using  odistartscen.

Step 1 – Create Scenarios of the Interface.

Step 2 .  In the package ,drag the odistartscen and provide the following details as shown below.

[ Note ;- Version = –1 calls latest scenario , so keep it –1]

In the Synchronous / Asynchronous , select the Asynchronous .

Session Name – will be visible in the Operator.

image

Keep doing so for all the Interface to be executed parallel  and provide the following as defined above.

image

Step 3 –  Finally call the odiwaitforchildsession

image

The  odiwaitforchildsession checks till all the parallel scenarios are executed successful or failure. The odiwaitforchildsession has to be called after such parallel execution and before Asynchronous  started if there are  interface before it.

March 23, 2010
by kdevendr
2 Comments

Categories: How to , ODI , Tips and Tricks

Tags: , , ,

Single Post View


Dropping $ Tables

There are many development environment where the $ tables created in the ODI work schema are not removed at proper interval .As the development grows the more number of $ tables grow especially in the environment where dynamic $ tables created for every interface run .

This particular procedure drops all the $ tables.  Please use this first in your development and modify the codes according for your environment.

image

In the above step , we are dropping all the $ tables from Work Schema . My Work Schema is ODI_TEMP , Selected any required Schema which have the necessary permission to do the drop. Provide the Work_Schema in TEMP_SCHEMA option.

image

Download the procedure

http://cid-d7195c8badc40d0b.skydrive.live.com/embedicon.aspx/odiexperts.com/TRT_ODI_DROP_TEMP_TABLES.xml

March 23, 2010
by kdevendr
1 Comment

Categories: How to , Knowledge Modules , Logic , ODI , Tips and Tricks

Tags: , ,

Single Post View


KM FOR UNION BASED ON IKM SQL CNTRL APPEND

This KM is do UNION in ODI  which created based on IKM SQL Control Append and support Flow control too and is based on the full outer join concept

clip_image002

Map the column in this format

NVL( <SOURCE1.COLUMN1 , SOURCE2.COLUMN1>
NVL(<SOURCE1.COLUMN2,SOURCE2.COLUMN2>
and so on..

and do a simple join between the two source tables  and select this KM and execute the interface.

clip_image003

The codes are shown below.

INSERT FLOW INTO I$ TABLE

insert into <%=snpRef.getTable("L","INT_NAME","A")%>
(
<%=snpRef.getColList("", "[COL_NAME]", ",nt", "", "((INS and !TRG) and REW)")%>
)
select <%=snpRef.getPop("DISTINCT_ROWS")%>
<%=snpRef.getColList("", "[EXPRESSION]", ",nt", "", "((INS and !TRG) and REW)")%>
from <%=odiRef.getSrcTablesList("", "[SCHEMA].[TABLE_NAME]", " FULL OUTER JOIN ", "")%>
on <%=odiRef.getJoinList("","([EXPRESSION])"," and ","")%>
where <% if (snpRef.getPop("HAS_JRN").equals("0")) { %>
(1=1)
<%} else {%>
JRN_FLAG <> 'D'
<% } %>
<%=snpRef.getFilter()%>
<%=snpRef.getJrnFilter()%>
<%=snpRef.getGrpBy()%>
<%=snpRef.getHaving()%>

INSERT INTO NEW ROWS

<%if ( snpRef.getUserExit("FLOW_CONTROL").equals("1") ) { %>
insert into <%=snpRef.getTable("L","TARG_NAME","A")%>
(
<%=snpRef.getColList("", "[COL_NAME]", ",nt", "", "((INS and !TRG) and REW)")%>
<%=snpRef.getColList(",", "[COL_NAME]", ",nt", "", "((INS and TRG) and REW)")%>
)
select <%=snpRef.getColList("", "[COL_NAME]", ",nt", "", "((INS and !TRG) and REW)")%>
<%=snpRef.getColList(",", "[EXPRESSION]", ",nt", "", "((INS and TRG) and REW)")%>
from <%=snpRef.getTable("L","INT_NAME","A")%>
<% }
else { %>
insert into <%=snpRef.getTable("L","TARG_NAME","A")%>
(
<%=snpRef.getColList("", "[COL_NAME]", ",nt", "", "(INS and REW)")%>
)
select <%=snpRef.getPop("DISTINCT_ROWS")%>
<%=snpRef.getColList("", "[EXPRESSION]", ",nt", "", "(INS and REW)")%>
from <%=odiRef.getSrcTablesList("", "[SCHEMA].[TABLE_NAME]", " FULL OUTER JOIN ", "")%> on <%=odiRef.getJoinList("","([EXPRESSION])"," and ","")%>
where <% if (snpRef.getPop("HAS_JRN").equals("0")) { %>
(1=1)
<%} else {%>
JRN_FLAG <> 'D'
<% } %>
<%=snpRef.getFilter()%>
<%=snpRef.getJrnFilter()%>
<%=snpRef.getGrpBy()%>
<%=snpRef.getHaving()%>
<% } %>

Hope it does the work till latest ODI is released with UNION and MINUS logic.

Download the KM below.

Download XML