Snowflake dimension with multiple levels mondrian - mondrian

My tables structure is as follows
dim_question_tbl table with primary key dim_question_id_i(pk)
dim_grade_tbl -> dim_grade_id_i(pk), grade_name_c
dim_level_tbl -> dim_level_id_i(pk), level_name_c
dim_grade_question_tbl -> dim_grade_question_id_i(pk), dim_grade_id_i(fk), dim_level_id_i(fk)
Now i have to have the grade and level as the levels in dimension.
The cube written on the 'dim_question_tbl' table.
I have written the dimension as
<Dimension name="Grade" foreignKey="dim_question_id_i" highCardinality="false">
<Hierarchy hasAll="true" primaryKey="dim_question_id_i" primaryKeyTable="dim_grade_question_tbl">
<join leftKey="dim_grade_id_i" rightKey="dim_grade_id_i">
<table name="dim_grade_question_tbl" />
<join leftKey="dim_level_id_i" rightKey="dim_level_id_i">
<table name="dim_grade_tbl" />
<table name="dim_level_tbl" />
</join>
</join>
<Level name="EnterpriseID" column="dim_enterprise_id_i" table="dim_grade_tbl" uniqueMembers="true" visible="false"/>
<Level name="Grade" column="grade_name_c" table="dim_grade_tbl" uniqueMembers="true"/>
<Level name="Level" column="level_name_c" table="dim_level_tbl" uniqueMembers="true"/>
</Hierarchy>
</Dimension>
This does not working. The exception i am getting is '[Grade]' must have at least one level.
I have tried it with sql query also as
<Dimension name="Grade" foreignKey="dim_question_id_i" highCardinality="false">
<Hierarchy hasAll="true" primaryKey="dim_question_id_i" primaryKeyTable="dim_grade_question_tbl">
<Query name="test">
<SQL dialect="generic">
SELECT *
FROM dim_grade_question_tbl, dim_grade_tbl, dim_level_tbl
WHERE dim_grade_question_tbl.dim_grade_id_i = dim_grade_tbl.dim_grade_id_i
and dim_grade_question_tbl.dim_level_id_i = dim_level_tbl.dim_level_id_i
</SQL>
</Query>
<Level name="Grade" column="grade_name_c" table="dim_grade_tbl" uniqueMembers="true"/>
<Level name="Level" column="level_name_c" table="dim_level_tbl" uniqueMembers="true"/>
</Hierarchy>
</Dimension>
With the sql query also the same exception i am getting.
Could any one help me how can i get the multiple levels with the snowflake schema?

Related

How to avoid scentific notation in Saiku Attribute

I define saiku(3.8) schema as below:
<?xml version="1.0" encoding="utf-8"?>
<Schema name="Zeus Offline Data" metamodelVersion='4.0'>
<PhysicalSchema>
<Table name="ZEUS_OFFLINE_DATA">
<Key>
<Column name='FB_ACCOUNT_ID'/>
</Key>
</Table>
</PhysicalSchema>
<Cube name="OfflineData">
<Dimensions>
<Dimension name="AdAccount" table="ZEUS_OFFLINE_DATA">
<Attributes>
<Attribute name="account_id" keyColumn="FB_ACCOUNT_ID" hasHierarchy="true"/>
</Attributes>
</Dimension>
<Dimension name="BM" table="ZEUS_OFFLINE_DATA">
<Attributes>
<Attribute name="bm_id" keyColumn="BM_ID" hasHierarchy="true"/>
</Attributes>
</Dimension>
</Dimensions>
<MeasureGroups>
<MeasureGroup name="Stats" table="ZEUS_OFFLINE_DATA">
<Measures>
<Measure name="clicks" column="CLICKS" aggregator="sum" formatString="#,###"/>
</Measures>
<DimensionLinks>
<FactLink dimension="AdAccount"/>
<FactLink dimension="BM"/>
</DimensionLinks>
</MeasureGroup>
</MeasureGroups>
It contains two dimension "bm_id" and "fb_account_id", and one measure "clicks".In database backend, bm_id and fb_account_id are int type. When I make query in Saiku, the result of bm_id and fb_account_id are shown in scientific notation mode, which I don't want.
Result:
bm_id clicks
1.71141391154125E14 1,091,234
Which I want:
171141391154125 1,091,234
I don't know which attribute should be changed for that, any help appreaciated
Thanks

Mondrian: Slicer axis ignored in query against a VirtualCube

I created a VirtualCube, combining two other Cubes in my schema.
However, it seems that the slicer axis on queries made against this VirtualCube is being ignored.
This query returns the expected results:
SELECT
NON EMPTY {
[Measures].[FOB],
[Measures].[CIF]
} ON 0,
NON EMPTY [Date].[Year].Members ON 1
FROM [exports_and_imports]
This one returns the same results as the previous one, which is incorrect:
SELECT
NON EMPTY {
[Measures].[FOB],
[Measures].[CIF]
} ON 0,
NON EMPTY [Date].[Year].members ON 1
FROM [exports_and_imports]
WHERE (
[Geography].[Washington]
)
However, a slicer applied to the Date dimension does work:
SELECT
NON EMPTY {
[Measures].[FOB],
[Measures].[CIF]
} ON 0
FROM [exports_and_imports]
WHERE (
[Date].[Year].&[2005]:date.year.&[2014]
)
Edited version of my schema:
<Schema name="datachile">
<Dimension name="Date" type="TimeDimension">...</Dimension>
<Dimension name="Geography">...</Dimension>
<Dimension name="Country">...</Dimension>
<Dimension name=“HS”>...</Dimension>
<Cube name="exports">
<DimensionUsage name="Date" source="Date" foreignKey="date_id" />
<DimensionUsage name="Destination Country" source="Country" foreignKey="country_dest_id" />
<DimensionUsage name="Export Geography" source="Geography" foreignKey="exporter_comuna_id" />
<DimensionUsage name="Export HS" source="HS" foreignKey="hs_level3" />
<Measure name="FOB US" column="fob_us" aggregator="sum" />
</Cube>
<Cube name="imports">
<DimensionUsage name="Date" source="Date" foreignKey="date_id" />
<DimensionUsage name="Origin Country" source="Country" foreignKey="country_origin_id" />
<DimensionUsage name="Import Geography" source="Geography" foreignKey="importer_comuna_id" />
<DimensionUsage name="Import HS" source="HS" foreignKey="hs_6digits" />
<Measure name="CIF US" column="cif_us" aggregator="sum" />
</Cube>
<VirtualCube name="exports_and_imports">
<CubeUsages>
<CubeUsage cubeName="exports" ignoreUnrelatedDimensions="true" />
<CubeUsage cubeName="imports" ignoreUnrelatedDimensions="true" />
</CubeUsages>
<VirtualCubeDimension name="Date" />
<VirtualCubeDimension name="Geography" />
<VirtualCubeDimension name="HS" />
<VirtualCubeMeasure cubeName="exports" name="[Measures].[FOB US]" />
<VirtualCubeMeasure cubeName="imports" name="[Measures].[CIF US]" />
<CalculatedMember name="FOB" dimension="Measures">
<Formula>ValidMeasure([Measures].[FOB US])</Formula>
</CalculatedMember>
<CalculatedMember name="CIF" dimension="Measures">
<Formula>ValidMeasure([Measures].[CIF US])</Formula>
</CalculatedMember>
</VirtualCube>
</Schema>
There's no such thing as a dimension called "Geography" in any of your cubes. There's one called "Import Geography" and another one called "Export Geography". Your virtual cube is trying to use the Geography dimension, which neither cube has, but as the hierarchy is defined with hasAll="true", then the dimension defaults to the allMember in both cubes.
You need to define both Export and Import geography dimensions in your virtual cube and your slicer has to be
Union( [Import Geography].[Washington] * [Export Geography].[All], [Import Geography].[All] * [Export Geography].[Washington] )
(if what you're after is something like "show me total value in OR out of Washington).

Aggregating by Day of Week in Mondrian

I am trying to extend the Pentaho example of a simple TimeDimension to aggregate by Day Of Week
This is the example provided:
<Dimension name="Time" type="TimeDimension">
<Hierarchy hasAll="true" allMemberName="All Periods" primaryKey="dateid">
<Table name="datehierarchy"/>
<Level name="Year" column="year" uniqueMembers="true" levelType="TimeYears" type="Numeric"/>
<Level name="Quarter" column="quarter" uniqueMembers="false" levelType="TimeQuarters"/>
<Level name="Month" column="month" uniqueMembers="false" ordinalColumn="month" nameColumn="month_name" levelType="TimeMonths" type="Numeric"/>
<Level name="Week" column="week_in_month" uniqueMembers="false" levelType="TimeWeeks"/>
<Level name="Day" column="day_in_month" uniqueMembers="false" ordinalColumn="day_in_month" nameColumn="day_name" levelType="TimeDays" type="Numeric"/>
</Hierarchy>
</Dimension>
(Reference here)
My modified Dimension looks like this:
<Dimension name="Time" type="TimeDimension">
<Hierarchy hasAll="true" allMemberName="All Periods" primaryKey="date_id">
<Table name="dates"/>
<Level name="Year" column="year" uniqueMembers="true" levelType="TimeYears" type="Numeric"/>
<Level name="Month" column="month" uniqueMembers="false" ordinalColumn="month" nameColumn="month" levelType="TimeMonths" type="Numeric"/>
<Level name="Week" column="week" uniqueMembers="false" levelType="TimeWeeks"/>
<Level name="Day" column="day" uniqueMembers="true" ordinalColumn="day_in_week" nameColumn="day_of_week" levelType="TimeDays" type="Numeric"/>
</Hierarchy>
</Dimension>
I am running up against a challenge whereby Saiku (using as front end to the Mondrian Cube) insists that my Day column should always be based on the hierarchy of Year-Month-Week which is obviously fine for drill down but not if I just want aggregates by day (e.g. Average sales on a Monday versus a Tuesday). I've tried adding another dimension but no matter what I do I end up with N * day name records where N is the number of records I have (ideally I'd have 7 rows returned based on the relevant Measure)
Did you try separate dimension with single level?
<Dimension name="Time" type="TimeDimension">
<Hierarchy hasAll="true" allMemberName="All Periods" primaryKey="date_id">
<Table name="dates"/>
<Level name="Day" column="day" uniqueMembers="true" nameColumn="day_of_week" levelType="TimeDays" type="Numeric"/>
</Hierarchy>
</Dimension>
I think this could be solved with Mondrian4 and Saiku3, but currently I don't think there are other options.

OLAP cube in schema workbench measures shows no data

Iv'e created a simple Schema in Jaspersoft OLAP designer. Now i want to publish my Cube in a view on jasperreport Server.
I managed to get this to work before with other Schemas but now i don't get any values out of my sum measures...
Can anyone see some Problem in here?
<Schema name="AbsatzView">
<Cube name="Budget" cache="true" enabled="true">
<Table name="vBudgetDetail" schema="dbo" alias="">
</Table>
<Dimension type="TimeDimension" foreignKey="ZeitID" name="GJahr">
<Hierarchy name="" hasAll="false" primaryKey="ID">
<Table name="vBudgetTimes" schema="dbo" alias="">
</Table>
<Level name="Gjahr" column="Gjahr" uniqueMembers="true" levelType="TimeYears">
</Level>
<Level name="Monat" column="Monat" uniqueMembers="false" levelType="TimeMonths">
</Level>
</Hierarchy>
</Dimension>
<Dimension type="StandardDimension" foreignKey="VersionID" name="Aktiv Version">
<Hierarchy hasAll="false" primaryKey="VersionID">
<Table name="vBudgetVersionAktiv" schema="dbo" alias="">
</Table>
<Level name="Version" column="version" type="String" uniqueMembers="false" levelType="Regular">
</Level>
</Hierarchy>
</Dimension>
<Dimension type="StandardDimension" foreignKey="VersionID" name="Vorherige Version">
<Hierarchy name="" hasAll="false" primaryKey="VersionID">
<Table name="vBudgetVersionV1" schema="dbo" alias="">
</Table>
<Level name="Version" column="version" type="String" uniqueMembers="false" levelType="Regular">
</Level>
</Hierarchy>
</Dimension>
<Measure name="Absatz Plan" column="PlanAbsatz" aggregator="sum" visible="true">
</Measure>
<Measure name="Umsatz Plan" column="PlanUmsatzLW" aggregator="sum" visible="true">
</Measure>
</Cube>
</Schema>
I know that this for example this mdx have to give me values in my measures but it's empty and i don't know why?
select {[Measures].[Absatz Plan]} ON COLUMNS,
{[GJahr].[2013], [GJahr].[2014], [GJahr].[2015]} ON ROWS
from [Budget]
If i use the same tables in SQL and asks exact for the same Thing i get correct values
SELECT b.Gjahr,SUM(a.PlanAbsatz) FROM vBudgetDetail a
INNER JOIN vBudgetTimes b ON b.ID = a.ZeitID
GROUP BY b.Gjahr
Try this query
select {[Measures].[Absatz Plan]} ON COLUMNS,
{[GJahr].&[2013], [GJahr].&[2014], [GJahr].&[2015]} ON ROWS
from [Budget]
Or this:
select {[Measures].[Absatz Plan]} ON COLUMNS,
{[GJahr].[GJahr].&[2013], [GJahr].[GJahr].&[2014], [GJahr].[GJahr].&[2015]} ON ROWS
from [Budget]

Can Solr join tables in-memory?

There is a table of n products, and a table of features of these products. Each product has many features. Given a Solr DataImportHandler configuration:
<document name="products">
<entity name="item" query="select id, name from item">
<field column="ID" name="id" />
<field column="NAME" name="name" />
<entity name="feature"
query="select feature_name, description from feature where item_id='${item.ID}'">
<field name="feature_name" column="description" />
<field name="description" column="description" />
</entity>
</entity>
</document>
Solr will run n + 1 queries to fetch this data. 1 for the main query, n for the queries to fetch the features. This is inefficient for large numbers of items. Is it possible to configure Solr such that it will run these queries separately and join them in-memory instead? All rows from both tables will be fetched.
This can be done using CachedSqlEntityProcessor:
<document name="products">
<entity name="item" query="select id, name from item">
<field column="ID" name="id" />
<field column="NAME" name="name" />
<entity name="feature"
query="select item_id, feature_name, description from feature"
cacheKey="item_id"
cacheLookup="item.ID"
processor="CachedSqlEntityProcessor">
<field name="feature_name" column="description" />
<field name="description" column="description" />
</entity>
</entity>
</document>
Since Solr's index is 'flat', feature_name and description are not connected in any way; each product will have multi-valued fields for each of these.
I am not sure if Solr can do this, but the database can. Assuming that you are using MySQL, use JOIN and GROUP_CONCAT to convert this into a single query. The query should look something like this:
SELECT id, name, GROUP_CONCAT(description) AS desc FROM item INNER JOIN feature ON (feature.item_id = item.id) GROUP BY id
Don't forget to use the RegexTransformer on desc to separate out the multiple values.

Resources