Showing posts with label OUTER JOIN. Show all posts
Showing posts with label OUTER JOIN. Show all posts

Thursday, November 20, 2008

OBIEE Understanding Outerjoins Part 2

In a previous article I showed the basics of working with OBIEE Outerjoins: (http://obiee101.blogspot.com/2008/11/obiee-understanding-outerjoins-part-1.html).

image

This works fine until you add a filter :

image

image

From the log:

select T26.D_YEAR as c1,
     sum(T31.F_FACT_VAL) as c2
from
          DIM_YEAR_MONTH_DAY T26 left outer join
          F_FACTS T31 On T26.D_YEAR_MONTH_DAY = T31.D_DATE
group by T26.D_YEAR
having 440000 < sum(T31.F_FACT_VAL)
order by c1

This "kills" the outerjoin.... I hear think why not add "OR IS NULL". Let's do that:

image 

image

From the log:

select T26.D_YEAR as c1,
     sum(T31.F_FACT_VAL) as c2
from
          DIM_YEAR_MONTH_DAY T26 left outer join
          F_FACTS T31 On T26.D_YEAR_MONTH_DAY = T31.D_DATE
group by T26.D_YEAR
having 440000 < sum(T31.F_FACT_VAL) or sum(T31.F_FACT_VAL) is null
order by c1

We still  are missing a couple off years.

Let try an in view filter: change F_FACT_VAL to:

CASE WHEN SUM(F_FACTS.F_FACT_VAL by DIM_YEAR_MONTH_DAY.D_YEAR )> 440000 then SUM(F_FACTS.F_FACT_VAL by DIM_YEAR_MONTH_DAY.D_YEAR ) else NULL end

image

This give us all the years back:

image

From the log:

SET VARIABLE QUERY_SRC_CD='Report';SELECT DIM_YEAR_MONTH_DAY.D_YEAR saw_0, CASE WHEN SUM(F_FACTS.F_FACT_VAL by DIM_YEAR_MONTH_DAY.D_YEAR )> 440000 then SUM(F_FACTS.F_FACT_VAL by DIM_YEAR_MONTH_DAY.D_YEAR ) else NULL end saw_1 FROM BM_OUTER_JOIN ORDER BY saw_0

select T26.D_YEAR as c1,
     sum(T31.F_FACT_VAL) as c4
from
          DIM_YEAR_MONTH_DAY T26 left outer join
          F_FACTS T31 On T26.D_YEAR_MONTH_DAY = T31.D_DATE
group by T26.D_YEAR
order by c1

As you can see OBIEE did the case when logic internally.

Till Next Time

This article is orignally written for the ciber knowledge blog:

Saturday, November 15, 2008

OBIEE Understanding Outerjoins Part 1

First of all in an "ideal" DWH you wouldn't have a need for outerjoins, but sometimes you need to make data visible which you don't have.

Outerjoins in OBIEE can be a bit tricky and don't always give you the result you would expect. In this article I will get trough the basics, in a next trough some pittfalls....

Creating an outerjoin

Wednesday, November 12, 2008

OBIEE Outerjoin workaround?

(Direct answer: No :-( )

Have a look at this table:

image

What I'm looking for is this:

image

But I don't want to use outerjoins, since obiee messes them up anyway when you try do filtering later on.

Here is a small Q&D trick

Add an extra fact column and multiply it with a random number:

image

Next hide the column:

image

What is happening?

If we look in the log we see that OBIEE isn't executing the RAND() function on the Database side but internally. For that it first gets only the dimension columns from the database:

select T26.D_YEAR as c2,
T26.D_YEAR_MONTH as c3
from
DIM_YEAR_MONTH_DAY T26
where ( T26.D_YEAR = '2013' )

Next it will get the facts:

select D2.c2 as c1,
D2.c3 as c2,
D2.c1 as c3
from
(select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3
from
(select sum(T31.F_FACT_VAL) as c1,
T26.D_YEAR as c2,
T26.D_YEAR_MONTH as c3,
ROW_NUMBER() OVER (PARTITION BY T26.D_YEAR_MONTH ORDER BY T26.D_YEAR_MONTH ASC) as c4
from
DIM_YEAR_MONTH_DAY T26,
F_FACTS T31
where ( T26.D_YEAR = '2013' and T26.D_YEAR_MONTH_DAY = T31.D_DATE )
group by T26.D_YEAR, T26.D_YEAR_MONTH
) D1
where ( D1.c4 = 1 )
) D2
order by c2

After that it stitches the query's together.

Till Next Time