Thursday, July 7, 2016

Java Beanshell and SQL Embedded Example in ODI

Scenario:
We need to get all the filenames inside a folder.
For Example:
Sample_Files (Folder)
      Sample_File.txt(File)
      Sample_File.csv(File)
      Sample_File.xls(File)

Output should be 'Sample_File.txt,Sample_File.csv,Sample_file.xls'

Steps:

Step1:
Create a procedure and select target technology as Oracle

Step2:
Copy below code and paste in target side and select technology as  Oracle and Logical Schema accordingly

<?
import java.io.File;
public class FileLists{
   public static String FileNames() {
     
      File f = null;
      String[] FileList;
   String fileNames="";
           
      try{     
        
         f = new File("<%=odiRef.getOption( "Dir" )%>");
         FileList = f.list();
         for(String FileName:FileList)
         {
           if(FileName.contains("."))
     {
   if (!fileNames.isEmpty())
    fileNames  = fileNames+','+ FileName ;
   else
    fileNames = FileName;
     }
         }
  
      }catch(Exception e){
         e.printStackTrace();
      }
    return fileNames;
   }
}
?>
select '<?=FileLists.FileNames()?>' from dual

Step 3:
Go to Option and create new option whose name is "Dir" , Data type as "Text" and Direct Value "<DIRECTORY_LOCATION>" (eg : C:/Sample_files)

Step 4:
Execute the procedure.
Completed Successfully!!!!!

      

Unable to Save Or Create Mapping in ODI (Strange Issue)

Recently I come cross one strange issue in ODI i.e., Our team and myself unable to save or create new mapping in ODI. After research a little I found the issue.

Solution:
We are unable to save or create mapping in ODI - For that we need to analyze, first we need to find out is there problem in Work Repository or Master Repository?
For that we checked when we are getting that issue - while we are creating mapping and saving mapping that means it belongs to work repository.

So we connected to work repository and execute below query:

select
   c.owner,
   c.object_name,
   c.object_type,
   b.sid,
   b.serial#,
   b.status,
   b.osuser,
   b.machine
from
   v$locked_object a ,
   v$session b,
   dba_objects c
where
   b.sid = a.session_id
and
   a.object_id = c.object_id
and c.object_name = 'SNP_MAPPING';
   and osuser  in ('root');

Output of the above query are locked Objects. So we need to kill those sessions. Then only ODI will support you for creating and saving mapping

Automatically trigger the process when we place the file in specific location

Scenario:
Integration team decided to place a file in particular location and they asked ETL team to pick that file and load into the Target data store.
They are not sure when they are going to place that file. But ETL team need to pick that file immediately once they place the file in that location and process it.

File Name: Sample.txt
File Type : Fixed Length File

Assumptions:
Aware of loading data from File (Fixed length) to Table using ODI

Step 1:
Follow my previous post (Fixed length File Load)

Step 2:
Create a package -- Drag and Drop ODIWaitFile (tool) from toolbox.

Step 3:
Select ODIWaitFile and go to properties.
Directory : Specified intergation team provided file Location (example : C:\Sample_files)
Filename Mask : Sample.txt
For remaining properties leave it as it is

Step 4:
Drag and Drop Mapping into your package. Select "Ok" and connect to ODIWaitFile and Mapping with that connector

Step 5:
Drag and Drop ODIFileMove (tool) from toolbox.
Filename : (C:\Sample_files\Sample.txt) Specify complete file location with file name)
Target File : Specify where you want to move that file (for Example : C:\Sample_files\ZIP)
For remaining properties leave it as it is

Step 5:
Select "Ok" and connect to ODIFileMove from Mapping and again connect ODIFileMove to ODIWaitFile as below:


It seems to be cyclic that means it is infinity loop. Whenever we place a file it pick it up and load into target data store and move into another folder and wait for next file

Step 6:
We need to execute only for one time
Completed Successfully !!!!!



How to load Fixed length file to Target Data store (Table) ?

File Name: Sample.txt
File Type : Fixed Length

File Data:


Assumption:
Aware of Topology Configuration for Oracle Technology and File Technology.
If your not aware of it then follow this link (step 1 to step 3)


Step 1:
Go to Designer Navigator -- Expand the Model Accordion -- Create New Folder -- Right click and create new model for Oracle and File
(Assumption Your aware of creating Oracle Model and File Model)

Step 2:
Right Click File Model and select New Data store. Select Resource name by clicking on Mirror image. (Sample.txt)

Step 3:
Go to File Tab.
File Format : FIXED
Select Heading : 1 (Because in our file first line is heading)

Go to Attributes Tab
Click on Reverse Engineering

Divide the column as mention above.

Step 4:
Go Designer Navigator -- Go to Project Accordion
Create new Mapping -- Drag and Drop Source Data store (File Data store) and Target Data store (Oracle Data Store) -- Connect output connector of Source to into input connector of Target and select automap true

Select Appropriate KM's (LKM File to SQL and IKM Oracle Simple insert)

Step 5:
Execute the Mapping (Completed Successfully)

Output:



Thursday, June 16, 2016

ODI TOOLS - ODIZIP AND ODIFILEDELETE

Scenario:

Everyday we will get three files (i.e., *_sysdate.csv) we need to load those files and then we need to zip those files and place in one specified folder after that we need to remove from source directory.

Procedure:

Step 1:
Upto loading those files, steps are explained in my previous post

Step 2:

  • Create a new package
  • Create a variable and go to refresh tab provide "SELECT TO_CHAR(SYSDATE,'DD_MM_YYYY') FROM DUAL" and select appropriate logical schema
  • Drag and drop variable two times -- Select first variable as declare and second variable as refresh variable.
  • Drag and drop procedure
  • Drag and drop ODIZip and ODIFileDelete from package toolbox
Step 3:
  • Select ODIZip Tool in the package and enter following details
  • SourceFileDirectory : <Directory Location>\*#<PROJECT_NAME>.<VARIABLE_NAME>.csv
  • ZIP File : <ZIP File Directory Location>\#<PROJECT_NAME>.<VARIABLE_NAME>.ZIP and leave remaining as it
Step 4:
  • Select ODIFileDelete tool in the package and enter following details
  • Directory: <Directory Location> and FileName : *#<PROJECT_NAME>.<VARIABLE_NAME>.csv and leave remaining as it
Step 5:
     Connect all the components in sequencial order variable_declare--variable_refresh--procedure--ODIZip--ODIFileDelete

Completed Successfully!!!

How to load multiple files(of same structure) to single target table using single interface/Mapping in ODI?

How to load multiple files (of same structure) to single target table using single interface/Mapping in ODI?

Pre-requisities:
File Structure of all the files to be same.
Naming conversion of the file should be decide earlier.

In this example, I am considering sample1,sample2 and sample3 as naming conversion of the file and File Structure as follows for all the files.

ID,PROJECT_NAME (.csv delimited with ',')

Procedure:

Step 1:
Topology Configuration
Create Physical Architecture for Target 
  • Expand Technologies -- Right click Oracle Technology -- Click on New Dataserver
  • Provide DB details and save it
  • Right click the Dataserver and select Select New Physical Schema and provide Schema details
Create Physical Architecture for Source
  • Expand Technologies -- Right click File Technology -- Click on New Dataserver
  • Provide File server details and save it
  • Right click the Dataserver and select Select New Physical Schema and provide Folder location
Step 2:
Create Logical Architecture for Target
  • Expand Technologies -- Right click Oracle Technology -- select New Logical Schema
  • Provide Logical Schema Name (whatever you want)
Create Logical Architecture for Source
  • Expand Technologies -- Right click FileTechnology -- select New Logical Schema
  • Provide Logical Schema Name (whatever you want)
Step 3:
Create Context
  • Click on New Context
  • Provide Context Name (whatever you want)
  • Go to Schemas tab and Select Physical Schema for appropriate Logical Schema(
Step 4:
Create Target Model 
  • Click New Model
  • Provide Name , Select Technology as Oracle and Select Logical Schema which you created earlier.
  • Go to Reverse Engineering Tab -- Select Context which we created earlier and provide table name for "Mask" input text box
  • Go to selective Reverse Engineering tab and select appropriate table and click on Reverse Engineering
  • Your datastore is created successfully
Create Source Model
  • Click New Model
  • Provide Name , Select Technology as File and Select Logical Schema which you created earlier.
  • Right on your Model and select New Datastore
  • Provide name and select the sample1.csv file
  • Go to Files tab -- File Format -- Delimited and Header -- 1
  • Under Field Separator -- Others -- provide ','
  • Go to Attributes and click on reverse Engineering
  • Go to Definition -- Resource Name : Sample#<PROJECT_NAME>.<VARIABLE_NAME>.csv and save it
Step 5:
Create Project
  • Create new mapping
  • Drag and drop both source and target datastores. Link the source output connector to target input connector. Do mappings as per your requirement
  • Go to Physical -- Select staging area and select KM as LKM File to SQL and Select Target datatstore and select KM as IKM SQL control Append
IMPORTANT (MAIN LOGIC)
Step 6:
Create Package
  • Create Variable in your project
  • Create Package and drag and drop your variable and mapping which you created earlier
  • Connect 'OK' from variable to Mapping
  • Generate Scenario to that package
Step 7:
Create Procedure
  • Create Proceudre, In target side select technology as ODI tools and for Source side select Oracle as technology and select logical schema as well.
  • Target side : OdiStartScen "-SCEN_NAME=PKG_MULTI_FILES_LOAD" "-SCEN_VERSION=001" -<PROJECT_NAME>.<VARIABLE_NAME>=#FN
  • Source Side : SELECT REGEXP_SUBSTR('1,2,3','[^,]+',1,LEVEL) FN FROM DUALCONNECT BY LEVEL <= LENGTH(REGEXP_REPLACE('1,2,3','[^,]+'))+1
  • Select appropriate logical Schema for Source Technology and save it
Completed Succesfully!!!

Input Files:

Sample1 
ID,PROJECT_NAME
1,QUOTING&CONTRACT
2,EMPR

Sample2
ID,PROJECT_NAME
3,CONVERSIONS
4,DWH

Sample3
ID,PROJECT_NAME
5,SUPPORT
6,EAM_DM

Output:
Sample




Monday, June 13, 2016

How to pass runtime value to a package in ODI?

For Example:
Organization : 'X'
Child Organization : 'A'
Second Child Organization : 'B'
Third Child Organization : 'C'
Requirement I need to pass runtime child Organization name to my package. That means whenever I am executing package I need to mention what is child Organization we are going to load now.

Solution:
Step 1:
Create a variable V_CHILD_ORGANIZATION

Step 2:
Create a mapping whose child_organization (i.e., target column name) mapping should be #V_CHILD_ORGANIZATION

Step 3:
Create a package and drag and drop that variable (V_CHILD_ORGANIZATION) and drag and drop Mapping

Step 4:
Select that variable and make it as declare variable and select 'ok' control flow and link the variable and mapping.

Step 5:
Generate Scenario for that package and select the variable which there in that package while generating scenario

Successfully Created!!!

Execution:
Execute that scenario with corresponding context and agent then it prompt for Variable value.
If you want to change the value then you need to disable the latest value check box and you can provide whatever value you want (i.e., 'A' or 'B' or 'C')