I m new to the mdx query.
I have spatial properties that i want to visualize in a geomondrian table, this is the schema of simple_geofoodmart.xml :
<!-- spatial store dimension -->
<Dimension name="Store" foreignKey="store_id">
<Hierarchy hasAll="true" primaryKey="store_id" primaryKeyTable="geostore_store">
<Join leftKey="store_city_id_fk" rightKey="store_city_id"
rightAlias="geostore_city">
<Table name="geostore_store" />
<Join leftKey="store_state_id_fk" rightKey="store_state_id"
rightAlias="geostore_state">
<Table name="geostore_city" />
<Join leftKey="store_country_id_fk" rightKey="store_country_id">
<Table name="geostore_state" />
<Table name="geostore_country" />
</Join>
</Join>
</Join>
<Level name="Store Country" table="geostore_country" column="store_country_name"
uniqueMembers="true">
<Property name="geom" column="store_country_geom" type="Geometry" />
</Level>
<Level name="Store State" table="geostore_state" column="store_state_name"
uniqueMembers="true">
<Property name="geom" column="store_state_geom" type="Geometry" />
</Level>
<Level name="Store City" table="geostore_city" column="store_city_name"
uniqueMembers="false">
<Property name="geom" column="store_city_geom" type="Geometry" />
</Level>
<Level name="Store Name" table="geostore_store" column="store_name"
uniqueMembers="true">
<Property name="Store Type" column="store_type"/>
<Property name="Store Manager" column="store_manager"/>
<Property name="Store Sqft" column="store_sqft" type="Numeric"/>
<Property name="Street address" column="store_street_address" type="String"/>
</Level>
</Hierarchy>
</Dimension>
I want to get the "geom" proporty in columns and the products in rows
Usually you do it like that:
SELECT
[Measure] ON COLUMNS,
NON EMPTY [Store].MEMBERS
DIMENSION PROPERTIES
[Store].[geom] ON ROWS
FROM [Cube]
You list the DIMENSION PROPERTIES in the dimension axis
Actually i found a solution by tricking the mdx examples given in the Basic interface for ad hoc GeoMDX queries in localhost index
with member Measures.geo as [Store].CurrentMember.Properties("geom")
select {[Measures].geo} ON rows,
{[Store].[All Stores].[USA]} ON columns
from [Sales]
I have a sample star schema made in this way:
author (id, name)
book (id, name)
sample_fact_table (id, authorfk, bookfk, quantity)
where obiouvsly authorfk is a FK to author.id and bookfk is FK to book.id.
Dimensions are: "author", "book". Measure is "quantity".
I made this configuration for the cube, using Pentaho Schema Workbench tool:
<Schema name="MySchema">
<Dimension type="StandardDimension" visible="true" name="Author">
<Hierarchy visible="true" hasAll="true" allMemberName="All Authors" primaryKey="id">
<Table name="author">
</Table>
<Level name="Name" visible="true" table="author" column="id" nameColumn="name" uniqueMembers="false">
</Level>
</Hierarchy>
</Dimension>
<Dimension type="StandardDimension" visible="true" name="Book">
<Hierarchy visible="true" hasAll="true" allMemberName="All Books" primaryKey="id">
<Table name="book">
</Table>
<Level name="Name" visible="true" table="book" column="id" nameColumn="name" uniqueMembers="false">
</Level>
</Hierarchy>
</Dimension>
<Cube name="TestCube" visible="true" cache="true" enabled="true">
<Table name="sample_fact_table">
</Table>
<DimensionUsage source="Author" name="Author" visible="true" foreignKey="authorfk">
</DimensionUsage>
<DimensionUsage source="Book" name="Book" visible="true" foreignKey="bookfk">
</DimensionUsage>
<Measure name="quantity" column="quantity" aggregator="sum" visible="true">
</Measure>
</Cube>
</Schema>
If I try to execute the MDX query:
select
Measures.quantity ON COLUMNS,
NON EMPTY Author.Children ON ROWS
from [TestCube]
I have a good result:
Axis #0:
{}
Axis #1:
{[Measures].[quantity]}
Axis #2:
{[author].[Al]}
{[author].[John]}
{[author].[Jack]}
Row #0: 3
Row #1: 9
Row #2: 1
But if instead of Author I query on Book, like this:
select
Measures.quantity ON COLUMNS,
NON EMPTY Book.Children ON ROWS
from [TestCube]
I get this error:
Mondrian Error:Failed to parse query 'select
Measures.quantity ON COLUMNS,
NON EMPTY Book.Children ON ROWS
from [TestCube]'
Mondrian Error:MDX object 'Book' not found in cube 'TestCube'
What I'm doing wrong?
Author and Book are both Dimensions, both declared in the same way, both referenced into the Cube.
Thank you!
I have following Dimension in mondrian schema. Mondrian on creating connection says
mondrian.olap.MondrianException: Mondrian Error:Internal error: Hierarchy '[Product]' not found
<Dimension name="Product" foreignKey="item_id">
<Hierarchy hasAll="true" primaryKey="item_code" primaryKeyTable="m_item_master">
<Join leftKey="item_code" rightKey="item_code">
<Table name="m_item_master"/> <!--dummy_master--> <!--m_item_master-->
<Table name="m_item_relation"/>
</Join>
<Level name="Department" table="m_item_relation" column="department"/>
<Level name="Class" table="m_item_relation" column="category"/>
<Level name="Item" table="m_item_master" column="item_code" ordinalColumn="item_code" nameColumn="name" uniqueMembers="true" type="Numeric"/>
</Hierarchy>
<Hierarchy name="Base Item" hasAll="false" primaryKey="item_code" primaryKeyTable="m_item_master">
<Join leftKey="item_code" rightKey="item_code">
<Table name="m_item_master"/> <!--dummy_master--> <!--m_item_master-->
<Table name="m_item_relation"/>
</Join>
<Level name="Department" table="m_item_relation" column="department" captionColumn="department"/>
<Level name="Item" table="m_item_master" column="item_code" ordinalColumn="item_code" nameColumn="name" uniqueMembers="true" captionColumn="name" type="Numeric"/>
<Property name="Price" table="m_item_master" column="price" />
</Hierarchy>
</Dimension>
I am using Mondrian-4.0.0-SNAPSHOT version and tried the same with latest mondrian 4.2.0.0-204 version as well.
Note:
Moreover I am getting this Error during mondrian connection creation itself. So it doesn't concern with any MDX query passed to it.
Ok. This is the what the mistake I found. For the clarification, Mondrian do support multiple hierarchy, but to the above schema we seems to have a different problem with the associated roles.
<Role name="myrole">
<SchemaGrant access="none">
<CubeGrant cube="Transaction" access="all">
<HierarchyGrant hierarchy="[Product]" access="custom" rollupPolicy="partial">
<MemberGrant member="[Product].[Cottage Foods]" access="all"/>
<MemberGrant member="[Product].[Vegetables]" access="all"/>
....
</HierarchyGrant>
....
</CubeGrant>
</SchemaGrant>
</Role>
In the above role, though the default hierarchy takes the name of the dimension in mondrian, we have to specify them as [Dimension.Hierarchy] in roles but not just Hierarchy name if you have multiple hierarchy within the Dimension. In our case, it should be as below.
<Role name="myrole">
<SchemaGrant access="none">
<CubeGrant cube="Transaction" access="all">
<HierarchyGrant hierarchy="[Product.Product]" access="custom" rollupPolicy="partial">
<MemberGrant member="[Product.Product].[Cottage Foods]" access="all"/>
<MemberGrant member="[Product.Product].[Vegetables]" access="all"/>
....
</HierarchyGrant>
....
</CubeGrant>
</SchemaGrant>
</Role>
This solves the above problem.
i have converted sql analysis to mdx analysis and found that mdx is far more expensive in term of execution time than sql. below is the sql which i am trying to convert to mdx
select inc.incident_id,inc.incident_start_time, inc.incident_end_time,inc_type.incident_type,inc.incident_desc,st_x(inc.the_geom) as incident_lon, st_y(inc.the_geom) as incident_lat,inc_type.class_name as incident_class, inc_type.incident_image ,fir.modus_operandi, fir.fir_status, fir.fir_serial_no as fir_id from analyst_mdx.incident as inc join analyst_mdx.incident_types as inc_type on inc.incident_type = inc_type.incident_type_id left outer join analyst_mdx.fir_details as fir on inc.fir_no = fir.fir_no join analyst_mdx.district on (st_contains(district.the_geom, inc.the_geom) and district.district_id=1) where inc.incident_type in ('10','8','14','11','5','9','19','21','6','7','16','3','4','12','20','13','1','2','23','17','18') and ((inc.incident_start_time between '2012-01-29T00:00:00' and '2014-12-29T23:59:59')) order by incident_start_time, incident_end_time
and this is the fact tables are interconnected
now let me show you the mdx which i have made
with member [Measures].[incident_type] as '[incident].CurrentMember.Properties("incident_type")'
member [Measures].[incident_desc] as '[incident].CurrentMember.Properties("incident_desc")'
member [Measures].[incident_class] as '[incident].CurrentMember.Properties("incident_class")'
member [Measures].[incident_image] as '[incident].CurrentMember.Properties("incident_image")'
member [Measures].[modus_operandi] as '[incident].CurrentMember.Properties("modus_operandi")'
member [Measures].[fir_status] as '[incident].CurrentMember.Properties("fir_status")'
member [Measures].[fir_id] as '[incident].CurrentMember.Properties("fir_id")'
member [Measures].[date_start_time] as '[incident].CurrentMember.Properties("date_start_time")'
member [Measures].[the_geom] as '[incident].CurrentMember.Properties("the_geom")'
member [Measures].[date_end_time] as '[incident].CurrentMember.Properties("date_end_time")'
member [time].[newtime] as 'Aggregate({([time].[all periods].[2012].[4].[15] : [time].[all periods].[2012].[4].[30]),([time].[all periods].[2012].[5]:[time].[all periods].[2012].[12]) ,([time].[all periods].[2013]),([time].[all periods].[2014].[1] : [time].[all periods].[2014].[6]),([time].[all periods].[2014].[7].[1] : [time].[all periods].[2014].[7].[15])})'
select {[Measures].[incident_type], [Measures].[incident_desc], [Measures].[incident_class],[Measures].[incident_image], [Measures].[modus_operandi], [Measures].[fir_status],[Measures].[fir_id], [Measures].[the_geom], [Measures].[date_start_time],[Measures].[date_end_time], [Measures].[incident_count]} ON COLUMNS,
NON EMPTY Filter([incident].[incident_id].Members, ST_Contains([district].[all district].[1].Properties("the_geom"),[incident].CurrentMember.Properties("the_geom"))) ON ROWS
from [pin_mapping]
where ([time].[newtime])
maximum record for a table is 65 thousand, sql executes in not more than 3 seconds and mdx takes more than 10 minutes. my entire olap concepts fails with it. can anyone explain me where i am going wrong ?
this is the cube that i am using...
<Schema name="analyst_haryana">
<Cube name="pin_mapping" cache="true" enabled="true">
<Table name="pin_mapping_fact_table" schema="analyst_mdx"></Table>
<Dimension type="StandardDimension" foreignKey="incident_id" name="incident">
<Hierarchy hasAll="true" allMemberName="all incident" primaryKey="incident_id">
<Table name="incident" schema="analyst_mdx"> </Table>
<Level name="incident_id" column="incident_id" type="Numeric" uniqueMembers="true" levelType="Regular" hideMemberIf="Never">
<Property name="the_geom" column="the_geom" type="Geometry"></Property>
<Property name="incident_type" column="incident_desc" type="String"></Property>
<Property name="incident_desc" column="incident_desc" type="String"></Property>
<Property name="fir_status" column="fir_status" type="String"></Property>
<Property name="incident_image" column="incident_image" type="String"></Property>
<Property name="modus_operandi" column="incident_desc" type="String"></Property>
<Property name="incident_class" column="incident_desc" type="String"></Property>
<Property name="date_start_time" column="date_start_time" type="String"></Property>
<Property name="date_end_time" column="date_end_time" type="String"></Property>
</Level>
</Hierarchy>
</Dimension>
<Dimension type="TimeDimension" foreignKey="time_id" name="time">
<Hierarchy hasAll="true" allMemberName="all periods" primaryKey="time_id">
<Table name="aux_dates" schema="analyst_mdx"></Table>
<Level name="year" column="the_year" type="Numeric" uniqueMembers="true" levelType="TimeYears" hideMemberIf="Never"></Level>
<Level name="quarter" column="the_quarter" type="String" uniqueMembers="false" levelType="TimeQuarters" hideMemberIf="IfParentsName"></Level>
<Level name="month" column="the_month" type="Numeric" uniqueMembers="false" levelType="TimeMonths" hideMemberIf="IfParentsName"></Level>
<Level name="day" column="the_day" type="Numeric" uniqueMembers="false" levelType="TimeDays" hideMemberIf="IfParentsName"></Level>
</Hierarchy>
</Dimension>
<Dimension type="StandardDimension" foreignKey="district_id" name="district">
<Hierarchy hasAll="true" allMemberName="all district" primaryKey="district_id">
<Table name="district" schema="analyst_mdx"></Table>
<Level name="district_id" column="district_id" type="Numeric" uniqueMembers="true" levelType="Regular" hideMemberIf="IfParentsName">
<Property name="the_geom" column="the_geom" type="Geometry"></Property>
</Level>
</Hierarchy>
</Dimension>
<Dimension type="StandardDimension" foreignKey="incident_type_id" name="incident_type">
<Hierarchy hasAll="true" allMemberName="all incident _types" primaryKey="incident_type_id">
<Table name="incident_types" schema="analyst_mdx"></Table>
<Level name="incident_type_id" column="incident_type_id" type="Numeric" uniqueMembers="true" levelType="Regular" hideMemberIf="Never"></Level>
</Hierarchy>
</Dimension>
<Dimension type="StandardDimension" foreignKey="fir_serial_no" name="fir_details">
<Hierarchy hasAll="true" allMemberName="all status" primaryKey="fir_serial_no">
<Table name="fir_details" schema="analyst_mdx"></Table>
<Level name="fir_status" column="fir_status" type="String" uniqueMembers="false" levelType="Regular" hideMemberIf="Never"></Level>
</Hierarchy>
</Dimension>
<Measure name="incident_count" column="incident_count" datatype="Numeric" aggregator="count" visible="true"></Measure>
</Cube>
</Schema>
Well, not exactly sure, since I don't have the execution plans, but here goes nothing..
You have a well tuned SQL query on top which is doing set computation, which SQL Server is good at. And since the size of table is relatively small, it is bound to be fast. On the other hand, in the MDX query, you are actually doing cell-by-cell computation(due to use of CURRENTMEMBER function. The analysis engine sucks at it! Thus it is bound to be slow.
You are using the NON EMPTY function, which basically iterates through each and every row and filters out the EMPTY ones. This adds to the overhead on the engine. Run the query by removing the NON EMPTY clause, and see if it brings down the execution time(Though, I have observed that sometimes NON EMPTY clause actually improves rendering time)
The cube design must be revisited here. All the calculated members must be tried to be put as attributes of the dimensions involved, if possible.
Enable the mondrian slow sql query log (done in log4j.xml) and see which query is the issue.
See if it is one query, or simply that mondrian is executing 1000's.
If the latter review your approxRowCount options in the schema as well as uniqueMembers options. Possibly post the schema and results of the above changes so we can understand more. There's also the (deprecated) highcardinality option.
I have a virtual dimension. Results are right when I query cube, but when I query trhough virtual cube, members are not showed.
Queries:
--From cube:
SELECT
NON EMPTY {Hierarchize({[Measures].[MyMeasure]})} ON COLUMNS,
NON EMPTY {Hierarchize({{[MyVirtualDim Usage 0.New Hierarchy 0].[All MyVirtualDim Usage 0.New Hierarchy 0s]}, {[MyVirtualDim Usage 0.New Hierarchy 0].[New Level 0].Members}, {[MyVirtualDim Usage 0.New Hierarchy 0].[curs].Members}})} ON ROWS
FROM [MyCube]
--From virtual cube:
SELECT
NON EMPTY {Hierarchize({[Measures].[MyMeasure]})} ON COLUMNS,
NON EMPTY {Hierarchize({{[MyVirtualDim.New Hierarchy 0].[All MyVirtualDim.New Hierarchy 0s]}, {[MyVirtualDim.New Hierarchy 0].[New Level 0].Members}, {[MyVirtualDim.New Hierarchy 0].[curs].Members}})} ON ROWS
FROM [MyVirtualCube]
Results:
--from cube (right)
Axis #0:
{}
Axis #1:
{[Measures].[MyMeasure]}
Axis #2:
{[MyVirtualDim Usage 0.New Hierarchy 0].[All MyVirtualDim Usage 0.New Hierarchy 0s]}
{[MyVirtualDim Usage 0.New Hierarchy 0].[1]}
{[MyVirtualDim Usage 0.New Hierarchy 0].[1].[1]}
{[MyVirtualDim Usage 0.New Hierarchy 0].[1].[2]}
Row #0: 5
Row #1: 5
Row #2: 3
Row #3: 2
--from virtual cube (bad)
Axis #0:
{}
Axis #1:
{[Measures].[MyMeasure]}
Axis #2:
{[MyVirtualDim.New Hierarchy 0].[All MyVirtualDim.New Hierarchy 0s]}
Row #0: 5
Here schema definition:
<Schema name="New Schema1">
<Dimension visible="true" name="MyVirtualDim">
<Hierarchy name="New Hierarchy 0" visible="true" hasAll="true">
<Table name="dim2" schema="public" alias="">
</Table>
<Level name="New Level 0" visible="true" table="dim2" column="id_nivell" nameColumn="id_nivell" type="Integer" internalType="int" uniqueMembers="false" levelType="Regular" caption="nivell" captionColumn="nom_nivell">
<Property name="nivell" column="nom_nivell" type="String" description="nivell">
</Property>
</Level>
<Level name="curs" visible="true" table="dim2" column="id_curs" nameColumn="id_curs" type="Integer" internalType="int" uniqueMembers="false" levelType="Regular" captionColumn="nom_curs">
<Property name="curs" column="nom_curs" type="String" description="curs">
</Property>
</Level>
</Hierarchy>
</Dimension>
<Cube name="MyCube" visible="true" cache="true" enabled="true">
<Table name="facts" schema="public">
</Table>
<DimensionUsage source="MyVirtualDim" name="MyVirtualDim Usage 0" visible="true" foreignKey="fk_dim2" >
</DimensionUsage>
<Measure name="MyMeasure" column="id" datatype="Integer" aggregator="count" visible="true">
</Measure>
</Cube>
<VirtualCube enabled="true" name="MyVirtualCube" visible="true">
<CubeUsages>
<CubeUsage cubeName="MyCube" >
</CubeUsage>
</CubeUsages>
<VirtualCubeDimension visible="true" name="MyVirtualDim">
</VirtualCubeDimension>
<VirtualCubeMeasure cubeName="MyCube" name="[Measures].[MyMeasure]" visible="true">
</VirtualCubeMeasure>
</VirtualCube>
</Schema>
Somebody can see where the issue is?
Solved,
Virtual dimensions and virtual cubes runs as expected. To solve my issue it is enough to change dimension name:
<Cube name="MyCube" visible="true" cache="true" enabled="true">
<Table name="facts" schema="public">
</Table>
<DimensionUsage source="MyVirtualDim" name="MyVirtualDim Usage 0" <--here!
Should be named: MyVirtualDim instead MyVirtualDim Usage 0 because is the name of the dimension in the cube.