Pentaho MDX roles - pentaho

I try to create some restriction in pentaho jpivot
1. i have 2 users (user1 - role1 and user2 - role2)
2. i have a pivot with this values
store | owner | sales
---------------------
s1 | user1 | 1235
| user2 | 2684
s2 | user1 | 1628
| user2 | 1002
s3 | user1 | 1111
| user2 | 1596
...
my schema look like this one:
<Schema name="asimov1">
<Dimension type="StandardDimension" visible="true" foreignKey="owner" name="owner">
<Hierarchy name="owner" visible="true" hasAll="false" primaryKey="owner" primaryKeyTable="storeTable">
<Level name="owner" visible="true" table="storeTable" column="owner" uniqueMembers="false">
</Level>
</Hierarchy>
</Dimension>
<Dimension type="StandardDimension" visible="true" foreignKey="store1" name="store1">
<Hierarchy name="store1" visible="true" hasAll="true" primaryKey="store1" primaryKeyTable="storeTable">
<Level name="store1" visible="true" table="storeTable" column="store1" uniqueMembers="false">
</Level>
</Hierarchy>
</Dimension>
<Cube name="asimov1" caption="asimov1" visible="true" description="asimov1" cache="true" enabled="true">
<Table name="storeTable">
</Table>
<DimensionUsage source="store1" name="store1" visible="true" foreignKey="store1">
</DimensionUsage>
<DimensionUsage source="owner" name="owner" visible="true" foreignKey="owner">
</DimensionUsage>
<Measure name="sales" column="sales" formatString="#" aggregator="sum">
</Measure>
</Cube>
</Schema>
my select:
select NON EMPTY Crossjoin({[owner].[owner].Members}, {[Measures].[sales]}) ON COLUMNS,
NON EMPTY {[store].[store].Members} ON ROWS
from [role_test]
I want when i login as user1 to see just user1 values and so for user2.
I made this using xaction who add a where clause, but user1 stil can see values of user2 if access the jpivot OLAP navigator.
I added visible="false" to dimension owner, but no effect.
I made roles with no effect.
<Role name="user1">
<SchemaGrant access="none">
<CubeGrant cube="asimov1" access="all">
<HierarchyGrant hierarchy="owner" topLevel="owner" bottomLevel="owner" access="custom">
<MemberGrant member="[owner].[user1]" access="all">
</MemberGrant>
<MemberGrant member="[owner].[user2]" access="none">
</MemberGrant>
</HierarchyGrant>
</CubeGrant>
</SchemaGrant>
....
That's all, so please gime some guidance.
Best regards,
dga

All was good, except this:
Before use roles must uncomment this line in biserver-ce/pentaho-solutions/system/pentahoObjects.spring.xml
<bean id="Mondrian-UserRoleMapper"
name="Mondrian-One-To-One-UserRoleMapper"
class="org.pentaho.platform.plugin.action.mondrian.mapper.MondrianOneToOneUserRoleListMapper"
scope="singleton" />

Related

Simple Olap Cube and simple query MDX

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!

MONDRIAN MDX query for period of time

I need to create an OLAP View just from one table in MySQL.
I need to get information from the following columns in my table: Date, Machine, Level, Item, Code, Comment, Downtime.
So I created this Mondrian Schema:
<Schema name="ExampleSchema">
<Cube name="ExampleCube">
<Table name="example_table"/>
<Dimension name="Date">
<Hierarchy hasAll="true" allMemberName="All Date">
<Level name="Date" column="date" uniqueMembers="true"/>
</Hierarchy>
</Dimension>
<Dimension name="Machine">
<Hierarchy hasAll="true" allMemberName="All Machine">
<Level name="Machine" column="machine" uniqueMembers="true"/>
</Hierarchy>
</Dimension>
<Dimension name="Level">
<Hierarchy hasAll="true" allMemberName="All Level">
<Level name="Level" column="level" uniqueMembers="true"/>
</Hierarchy>
</Dimension>
<Dimension name="Item">
<Hierarchy hasAll="true" allMemberName="All Item">
<Level name="Item" column="item" uniqueMembers="true"/>
</Hierarchy>
</Dimension>
<Dimension name="Code">
<Hierarchy hasAll="true" allMemberName="All Code">
<Level name="Code" column="code" uniqueMembers="true"/>
</Hierarchy>
</Dimension>
<Dimension name="Comment">
<Hierarchy hasAll="true" allMemberName="All">
<Level name="Comment" column="comment" uniqueMembers="true"/>
</Hierarchy>
</Dimension>
<Measure name="Downtime" column="downtime" aggregator="sum" formatString="Standard" visible="true"/>
</Cube>
</Schema>
My query looks like follows:
{[Item].[All Item]} * {[Measures].[Downtime]}
ON columns,
{[Code].[All Code]} * {[Comment].[All Comment]}
ON rows
from [ExampleCube]
WHERE
{([Date].[2011-11-31], [Machine].[1500], [Level].[AB])}
It works, but I want to have measures not for a single date, but for a period of time (from the start date till the end date).
Try using the range operator :
{[Item].[All Item]} * {[Measures].[Downtime]}
ON columns,
{[Code].[All Code]} * {[Comment].[All Comment]}
ON rows
from [ExampleCube]
WHERE
(
{[Date].[2011-11-31]:[Date].[2015-06-25]}
, [Machine].[1500], [Level].[AB]
)
Both dates [Date].[2011-11-31]:[Date].[2015-06-25] must exist within your cube.

How to add level to column to result MDX in mondrian

I have the following table created by the following MDX
SELECT
{
[Measures].numTickets
}ON COLUMNS,
{
Descendants(DateCreacion.Children, DateCreacion.Month)
}ON ROWS
FROM tickets
The thing is that i want to add another column to the numTickets but every time i add a dimension to the column, i get an empty column.
select {[Clinica].Children} ON COLUMNS,
{Descendants([DateCreacion].Children, [DateCreacion.YQMD].[Month])} ON ROWS
from [tickets]
How would i show the same data as the first picture but in the second format?
<Schema name="New Schema1">
<Cube name="tickets" visible="true" cache="true" enabled="true">
<Table name="fact">
</Table>
<Dimension type="TimeDimension" visible="true" foreignKey="fecha_tickets_id" name="DateCreacion">
<Hierarchy name="YQMD" visible="true" hasAll="true">
<Table name="dim_fecha_creacion_tickets" alias="">
</Table>
<Level name="Year" visible="true" column="año" type="Numeric" uniqueMembers="false" levelType="TimeYears">
</Level>
<Level name="Quarter" visible="true" column="cuarto" type="Numeric" uniqueMembers="false" levelType="TimeQuarters">
</Level>
<Level name="Month" visible="true" column="mes" type="Numeric" uniqueMembers="false" levelType="TimeMonths">
</Level>
<Level name="Day" visible="true" column="dia" type="Numeric" uniqueMembers="false" levelType="TimeDays">
<Property name="date_iso" column="date_iso" type="Numeric">
</Property>
</Level>
</Hierarchy>
</Dimension>
<Dimension type="StandardDimension" visible="true" foreignKey="clinica_id" name="Clinica">
<Hierarchy name="New Hierarchy 0" visible="true" hasAll="true">
<Table name="dim_posicion" alias="">
</Table>
<Level name="Posicion" visible="true" column="sigla" type="String" uniqueMembers="false">
</Level>
</Hierarchy>
</Dimension>
<Measure name="numTickets" column="idTicket" datatype="Numeric" aggregator="count" visible="true">
</Measure>
</Cube>
</Schema>
When adding the [Clinica].Children to the columns, you removed the measures.
You probably want to keep them, using a cross join, which can be stated using the * operator in MDX: Either
select {[Clinica].Children}
*
{ [Measures].numTickets }
ON COLUMNS,
...
or
select { [Measures].numTickets }
*
{[Clinica].Children}
ON COLUMNS,
...
depending on the order of columns you want to see.

How to call measures on Mondrian?

I'm try to create simple Mondrian schema with OLAP connection, but I have a problem.
I have two Measures. But when I called it, it just call one measures. I'm new on Mondrian and OLAP.
My schema look like this.
<Schema name="Test">
<Cube name="Report1" visible="true" cache="true" enabled="true">
<Table name="mstjobs" schema="public">
</Table>
<Dimension type="StandardDimension" visible="true" foreignKey="regionid" highCardinality="false" name="Reg">
<Hierarchy name="hiReg" visible="true" hasAll="true" allMemberName="All Region" primaryKey="code1">
<Table name="mstlov" schema="public" alias="">
</Table>
<Level name="Category" visible="true" table="mstlov" column="cat" type="String" uniqueMembers="false" levelType="Regular" hideMemberIf="Never">
</Level>
<Level name="ListRegion" visible="true" table="mstlov" column="desc1" type="String" uniqueMembers="false" levelType="Regular" hideMemberIf="Never">
</Level>
</Hierarchy>
</Dimension>
<Dimension type="StandardDimension" visible="true" foreignKey="titleid" highCardinality="false" name="Title">
<Hierarchy visible="true" hasAll="true" allMemberName="All Title" primaryKey="code1">
<Table name="mstlov" schema="public">
</Table>
<Level name="Category" visible="true" column="cat" type="String" uniqueMembers="false" levelType="Regular" hideMemberIf="Never">
</Level>
<Level name="Title" visible="true" column="desc1" type="String" uniqueMembers="false" levelType="Regular" hideMemberIf="Never">
</Level>
</Hierarchy>
</Dimension>
<Measure name="mtot" column="mantotal" datatype="Integer" aggregator="sum" visible="true">
</Measure>
<Measure name="wtot" column="womantotal" aggregator="sum" visible="true">
</Measure>
</Cube>
</Schema>`
I'm just called it with simple MDX query
Select
Reg.[All Region].region on COLUMNS,
Title.[ALl Title].titlekhas on ROWS
from Report1
And the output look like this, with mtot measures.
| |City1 |City2 |City3 |
| |20 |30 |30 |
|Job1 |10 |20 |10 |
|Job2 |10 |10 |20 |
But I want to call all measures together. so, the output should look like.
| |City1 |City2 |City3 |
| |20 |10 |30 |20 |30 |25 |
|Job1 |10 |10 |20 |10 |10 |10 |
|Job2 |10 |0 |10 |10 |20 |15 |
What should I do? Should I change the schema?
If you don't specify your measure, it'll use the first one as the default.
Use
Select
[Reg].[region] on COLUMNS,
[Title].[titlekhas] on ROWS
from Report1
where [Measures].[wtot]
instead.
Alternatively, you can also use
Select
{[Reg].[region]} * {[Measures].[wtot]} on COLUMNS,
[Title].[titlekhas] on ROWS
from Report1
or
Select
[Reg].[region] * {[Measures].[wtot], [Measures].[mtot] } on COLUMNS,
[Title].[titlekhas] on ROWS
from Report1
to display both measures.
Remarks:
- Even when not required, you should always use brackets when refering to dimensions, levels or members;
- You don't need to add the All member name after the dimension, you can jump straight to the first level member;
- I don't recommend using such "coded" names for measures, levels or dimensions. [Measures].[wtot] is much harder to read than [Measures].[Women Total].

Selecting other hierarchies in dimensions

I've googled the error message and various other keywords, but haven't
found anything similar enough to my own problem that I could apply it.
In my schema, I have the following dimension:
<Dimension name="Chip">
<Hierarchy hasAll="true" primaryKey="chip_id">
<Table name="chip"/>
<Level name="Reference Designator" column="ux" type="Integer"/>
<Level name="Pad" column="pad" type="Integer"/>
<Level name="Chip" column="chip" type="Integer"/>
</Hierarchy>
<Hierarchy name="Flash Pack Hierarchy" hasAll="true" primaryKey="chip_id">
<Table name="chip"/>
<Level name="Flash Pack" column="fp" type="Integer"/>
<Level name="Pad" column="pad" type="Integer"/>
<Level name="Chip" column="chip" type="Integer"/>
</Hierarchy>
<Hierarchy name="Bank Hierarchy" hasAll="true" primaryKey="chip_id">
<Table name="chip"/>
<Level name="Bank" column="bank" type="Integer"/>
<Level name="Chip" column="chip" type="Integer"/>
</Hierarchy>
</Dimension>
and the cube:
<Cube name="Chip Facts">
<Table name="chip_facts"/>
<DimensionUsage name="Machine" source="Machine" foreignKey="machine_id"/>
<DimensionUsage name="Card" source="Card" foreignKey="card_id"/>
<DimensionUsage name="Chip" source="Chip" foreignKey="chip_id"/>
<DimensionUsage name="Failure" source="Failure" foreignKey="failure_id"/>
</Cube>
I can query:
select
[Chip].[Reference Designator].members on columns
from [Chip Facts]
but not:
select
[Chip].[Flash Pack].members on columns
from [Chip Facts]
I get:
Caused by: mondrian.olap.MondrianException: Mondrian Error:MDX object '[Chip].[Flash Pack]' not found in cube 'Chip Facts'
How do I select the other hierarchy?
Syntax mondrian Olap cube
select {[Measures.qty1],..} on rows,
{[dimension.heirrarchy].members} on columns
from cube
Perhaps:
select [Chip].[Flash Pack Hierarchy].[Flash Pack].members on 0 from [Chip Facts]
The first hierarchy has no name, this is the default hierarchy.
The second hierarchy is [Flash Pack Hierarchy], the name is required.