19 Nisan 2014 Cumartesi

ODI 12c Implementing Complex queries ( Analytic Functions & SubSelect Query )

Hi

In this entry i will implement more advance query over  ODI 12c.Again I am gonna use ODIDEMO environment  and implement following query.

select
sales.CUST_ID,CUST.CUST_NAME,
sales.PRODUCT,
sales.TOTAL_NUM_OF_ORDERS,
'%'||ROUND(   (SUM_QUANTITY*100)/SUM_QUANTITY_ALL  ) PER_QUANTITY
from
(
  select
  trg_customer.CUST_ID ,trg_customer.CUST_NAME
  from
  trg_customer where age>= 30  and  age<=50
) cust ,
(
  select
  trg_sales.CUST_ID,
  trg_product.PRODUCT ,
  SUM(trg_sales.QTY)  OVER (PARTITION BY trg_sales.CUST_ID) SUM_QUANTITY_ALL ,
  SUM(trg_sales.QTY)  OVER (PARTITION BY trg_sales.CUST_ID, trg_product.PRODUCT ) SUM_QUANTITY ,
  COUNT(trg_sales.CUST_ID)  OVER (PARTITION BY trg_sales.CUST_ID ) TOTAL_NUM_OF_ORDERS
  from
  trg_sales ,  trg_product
  where
  trg_sales.PRODUCT_ID = trg_product.PRODUCT_ID
) sales
where
sales.CUST_ID=cust.CUST_ID


At first we need prepare our datasource structure in mapping ( Sales and Customer )

Step1:
Prepare data source for sales subquery ( For this i will extract SALES and PRODUCT tables from MODEL--> SALES_ADMINISTRATION  into SALES dataset and define the Join )





Step2:
Again in Sales part  , we will gonna define our expressions
(  TOTAL_NUM_OF_ORDERS  ,SUM_QUANTITY  , SUM_QUANTITY_ALL ).
To do that , first i will drag the columns which  i need to use for calculation into expression object.
( CUST_ID , PRODUCT , QTY )






Step3:
Now i am gonna prepare CUSTOMER part of the query.For this i will extract TRG_CUSTOMER table from MODEL--> SALES_ADMINISTRATION into mapping and using filter object
( where age>= 30  and  age<=50  )


Step4:
Okay , Currently we have two different datasource  ( SALES , CUSTOMER) now according to query i will gonna merge these two set into one via join object.




Step5
As a final step , i will gonna map dataset into a target table.




Physical diagram as follows:



Note: For this example Source and Target tables are in same Oracle DB , so Default Oracle Knowledge Modules are used.

For Extraction: XKM Oracle Extract GLOBAL
For Integration: IKM  Oracle Insert  GLOBAL




13 Nisan 2014 Pazar

ODI 12c Subquery Filter

Hi

In this entry i am gonna show how to implement an oracle pl/sql statement with subquery condition in ODI 12c.


Environment : ODI 12c  & Oracle 11g

Sample Query which i will implement:

select  custid 
from src_customer
where
custid   in
(
select 
CUST_ID
from src_orders
group by CUST_ID
having count(order_id) >3
)

Tables that we are using for this implementation:

 Source table 1:
 Source table 2:

Target Table:

Mapping:

In above you can see the mapping we suppose use for this operation.Trick is hidden inside of the subquery filter object.


ODI  already automatically set SRC_ORDERS table as a subquery table.Now only thing we have to do is to set Subquery filter filter properly .( Check the image above).For KMs standart knowledge modules works fine , you dont have to do any change.( For this example LKM Exract and IKM Oracle Global Knowledge modules were used. )