Some issues to make mondrian work with a parent-child hierarchy.
My table structure is as follows (simplified, as the Category table is actually a MPTT):
RESPONSE QUESTION CATEGORY
-------------- ------------------- ----------
id ¡---> identifier (String) ¡---> id <---¡
question_id ___| category_id _____| parent_id _|
value (Measure) title name_en
My closure table is a simple setup: child_id, parent_id, distance (with the primary key being the tuple (child_id, parent_id) ).
My cube's schema is as follows:
<Cube cache="true"
defaultMeasure="Value" enabled="true" name="mycube">
<Table name="response" schema="public"/>
<Dimension foreignKey="question_id" name="Category">
<Hierarchy allMemberName="All Categories" hasAll="true"
primaryKey="identifier" primaryKeyTable="question">
<Join leftKey="category_id" rightKey="id">
<Table name="question"/>
<Table name="category"/>
</Join>
<!-- works fine with the category itself: <Level column="name" type="String" name="Category Name" table="category" uniqueMembers="true"/> -->
<Level column="id" name="Category ID"
nameColumn="name_en" nullParentValue="NULL"
parentColumn="parent_id" table="category"
type="Numeric" uniqueMembers="true">
<!-- type="Numeric" ordinalColumn="lft" parentColumn="parent_id" nullParentValue="NULL" -->
<Closure childColumn="child_id" parentColumn="parent_id">
<Table name="category_closure"/>
</Closure>
</Level>
</Hierarchy>
</Dimension>
<Measure aggregator="avg" caption="Value"
column="actual_value" formatString="#,###.00" name="Value"/>
</Cube>
Now, based on the mondrian FoodMart test pages, I have set up a simple jsp pages for my cube, which I want to use as a starting point for my tests. It has the following MDX:
select {[Measures].[Value]} ON COLUMNS,
{( [Category] )} ON ROWS
from [mycube]
The result it shows at first is "All Categories". When I try to drill down or hierarchize in the Categories, it returns nothing but [All Categories]. I have tried also with Descendants() to no avail. Equally, when I try to list the members of Categories, it returns nothing.
I see that in the background it runs a query as follows to start the drilling down:
05/12/13 23:53:10,967 postgres: [3-1] LOG: execute : select "category"."id" as "c0", "category"."name_en" as "c1" from "question" as "question", "category" as "category" where "question"."category_id" = "category"."id" and "category"."parent_id" IS NULL group by "category"."id", "category"."name_en" order by "category"."id" ASC NULLS LAST
Obviously this query has an empty result because it joins question with root-level categories whilst only the leaves of my tree are attached some Questions. It also shows that the closure table is not used here.
Any clue on what I can do to fix this?
Thanks ahead lai