Visualizing relational data as Essbase/OLAP cubes – Partition Outer Joins and MODEL Clauses – Part 3
In a prior blog entry here, i had shown the advantages of using the MODEL clause. I also showed how the MODEL clause can be used to visualize the relational data in a multi-dimensional format. In most cases, using the MODEL clause alone can be sufficient. Just to recap, the MODEL clause divides your resultant data into 3 parts
- Partition By set of Dimensions – Similar to Index entries in Essbase (sparse dimensions)
- Dimension By set of Dimensions – Similar to Blocks of Essbase (dense dimensions)
- Measure Dimension
So, whenever you use MODEL, Oracle constructs a multidimensional array for each partition by the dimension(s) combination value. The multi-dimensional array would be dimensioned by the dimensions specified in the DIMENSION BY clause. Though a multi-dimensional array is created, the created array contains only the valid intersections present in the fact table and not every intersections that are possible. For example, consider the sql query below
SELECT FISCAL_YEAR_DSC,CHANNEL_DSC, UNITS FROM ( select sum(T10976.UNITS) as UNITS, T10939.FISCAL_YEAR_DSC as FISCAL_YEAR_DSC, T10881.CHANNEL_DSC as CHANNEL_DSC from CHANNEL_DIM T10881, TIME_DIM T10939, UNITS_FACT T10976 where ( T10881.CHANNEL_ID = T10976.CHANNEL_ID and T10939.MONTH_ID = T10976.MONTH_ID ) group by T10881.CHANNEL_DSC, T10939.FISCAL_YEAR_DSC) MODEL PARTITION BY (FISCAL_YEAR_DSC) DIMENSION BY (CHANNEL_DSC) MEASURES (UNITS) RULES (UNITS['Total'] = SUM(UNITS)[ANY]) ORDER BY 1,2
For example, lets say we have a requirement to show all the dimension values of Channel and only the transaction values of Fiscal year in our above report i.e. we need to bring in the Television Channel as well into our above report for Year.
SELECTA.FISCAL_YEAR_DSC FISCAL_YEAR_DSC,B.CHANNEL_DSC CHANNEL_DSC,NVL(A.UNITS,0) UNITSFROM
( select sum(T10976.UNITS) as UNITS, T10939.FISCAL_YEAR_DSC as FISCAL_YEAR_DSC, T10881.CHANNEL_DSC as CHANNEL_DSC
from
CHANNEL_DIM T10881,
TIME_DIM T10939,
UNITS_FACT T10976
where ( T10881.CHANNEL_ID = T10976.CHANNEL_ID and T10939.MONTH_ID = T10976.MONTH_ID )
group by T10881.CHANNEL_DSC, T10939.FISCAL_YEAR_DSC) A
RIGHT OUTER JOIN
(SELECT DISTINCT CHANNEL_DSC FROM CHANNEL_DIM) B ON (A.CHANNEL_DSC = B.CHANNEL_DSC)
SELECTA.FISCAL_YEAR_DSC FISCAL_YEAR_DSC,B.CHANNEL_DSC CHANNEL_DSC,NVL(A.UNITS,0) UNITSFROM
(
select
sum(T10976.UNITS) as UNITS,
T10939.FISCAL_YEAR_DSC as FISCAL_YEAR_DSC,
T10881.CHANNEL_DSC as CHANNEL_DSC
from
CHANNEL_DIM T10881,
TIME_DIM T10939,
UNITS_FACT T10976 where
( T10881.CHANNEL_ID = T10976.CHANNEL_ID and T10939.MONTH_ID = T10976.MONTH_ID )
group by T10881.CHANNEL_DSC, T10939.FISCAL_YEAR_DSC) A
PARTITION BY (A.FISCAL_YEAR_DSC)
RIGHT OUTER JOIN
(SELECT DISTINCT CHANNEL_DSC FROM CHANNEL_DIM) B
ON (A.CHANNEL_DSC = B.CHANNEL_DSC)
SELECTA.FISCAL_YEAR_DSC,B.CHANNEL_DSC,NVL(A.UNITS,0)FROM
(
SELECT B.FISCAL_YEAR_DSC FISCAL_YEAR_DSC, A.CHANNEL_DSC CHANNEL_DSC, NVL(A.UNITS,0) UNITS
FROM
(
select sum(T10976.UNITS) as UNITS, T10939.FISCAL_YEAR_DSC as FISCAL_YEAR_DSC, T10881.CHANNEL_DSC as CHANNEL_DSC
from
CHANNEL_DIM T10881,
TIME_DIM T10939,
UNITS_FACT T10976
where ( T10881.CHANNEL_ID = T10976.CHANNEL_ID and T10939.MONTH_ID = T10976.MONTH_ID )
group by T10881.CHANNEL_DSC, T10939.FISCAL_YEAR_DSC) A
PARTITION BY (A.CHANNEL_DSC)
RIGHT OUTER JOIN
(SELECT DISTINCT FISCAL_YEAR_DSC FROM TIME_DIM) B
ON (A.FISCAL_YEAR_DSC = B.FISCAL_YEAR_DSC)) A
PARTITION BY (A.FISCAL_YEAR_DSC)
RIGHT OUTER JOIN (SELECT DISTINCT CHANNEL_DSC FROM CHANNEL_DIM) B
ON (A.CHANNEL_DSC = B.CHANNEL_DSC)
SELECTFISCAL_YEAR_DSC,CHANNELS,NVL(UNITS,0)FROM
(SELECT B.FISCAL_YEAR_DSC FISCAL_YEAR_DSC, A.CHANNEL_DSC CHANNEL_DSC, NVL(A.UNITS,0) UNITS
FROM
(
select
sum(T10976.UNITS) as UNITS, T10939.FISCAL_YEAR_DSC as FISCAL_YEAR_DSC, T10881.CHANNEL_DSC as CHANNEL_DSC
from
CHANNEL_DIM T10881, TIME_DIM T10939, UNITS_FACT T10976
where
( T10881.CHANNEL_ID = T10976.CHANNEL_ID and T10939.MONTH_ID = T10976.MONTH_ID )
group by T10881.CHANNEL_DSC, T10939.FISCAL_YEAR_DSC) A
PARTITION BY (A.CHANNEL_DSC)
RIGHT OUTER JOIN
(SELECT DISTINCT FISCAL_YEAR_DSC FROM TIME_DIM) B
ON (A.FISCAL_YEAR_DSC = B.FISCAL_YEAR_DSC)) A
PARTITION BY (A.FISCAL_YEAR_DSC)
RIGHT OUTER JOIN (SELECT DISTINCT CHANNEL_DSC FROM CHANNEL_DIM) B
ON (A.CHANNEL_DSC = B.CHANNEL_DSC)
MODEL
PARTITION BY (FISCAL_YEAR_DSC)
DIMENSION BY (B.CHANNEL_DSC CHANNELS)
MEASURES (UNITS) RULES (UNITS['Total'] = SUM(UNITS)[ANY])
ORDER BY 1,2