Shared dimension in a cube returns cached value for other dimension
stuart007donald opened this issue · comments
stuart007donald commented
It seems when using a shared dimension, the values get cached for one of the dimensions, causing the results for the other dimension to be wrong.
This occurs in Mondrian 4.x, but seems ok in Mondrian 3.x. I tested this on 4.7.0.0-12.
Consider the following data
CREATE TABLE people (id INT AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL);
CREATE TABLE sales (id INT AUTO_INCREMENT PRIMARY KEY, amount INT, manager INT, assistant INT);
INSERT INTO people (firstname) values ('amber'),('ben'),('sam');
INSERT INTO sales (amount,manager,assistant) values (100,1,2),(200,2,3),(150,2,1);
And the following Mondrian Schema
<?xml version="1.0"?>
<Schema name="mondrian_test">
<Dimension name="People">
<Hierarchy hasAll="true" primaryKey="id">
<Table name="people"/>
<Level name="Name" column="firstname" uniqueMembers="true"/>
</Hierarchy>
</Dimension>
<!-- Sales -->
<Cube name="Sales">
<Table name="sales">
</Table>
<DimensionUsage name="Manager" source="People" foreignKey="manager"/>
<DimensionUsage name="Assistant" source="People" foreignKey="assistant"/>
<Measure name="Unit Sales" column="amount" aggregator="sum" formatString="Standard"/>
</Cube>
</Schema>
And the following sample code
public class MondrianTest {
@Test
public void testMondrianSchema() throws IOException, SQLException {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource(new com.mysql.jdbc.Driver(), "jdbc:mysql://localhost/mondrian_test", "sa", "");
CatalogLocator locator = new CatalogLocatorImpl();
PropertyList properties = new PropertyList();
String model = FileUtils.readFileToString(new File("c:/tmp/mondrian_test.xml"));
properties.put("CatalogContent", model);
Connection c = DriverManager.getConnection(properties, locator, dataSource);
for (String dim : new String[] { "Manager", "Assistant", "Manager", "Assistant" }) {
Query q = c.parseQuery("SELECT {[Measures].[Unit Sales]} ON COLUMNS FROM [Sales] WHERE {[" + dim + "].[Name].[ben]}");
System.out.println(dim + ":" + c.execute(q).getCell(new int[] { 0 }).getValue());
}
}
}
The output of which is:
Manager:350.0
Assistant:100.0
Manager:100.0
Assistant:100.0
We can see that after the Assistant dimension is used, filtering by the Manager dimension starts returning the wrong results.