Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared dimension in a cube returns cached value for other dimension #1010

Open
stuart007donald opened this issue Jan 24, 2018 · 0 comments
Open

Comments

@stuart007donald
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant