Skip to content

Commit

Permalink
MONDRIAN: Fix bug 1904496, "No implementation of caption attribute in…
Browse files Browse the repository at this point in the history
… DimensionUsage"

[git-p4: depot-paths = "//open/mondrian/": change = 10638]
  • Loading branch information
julianhyde committed Mar 3, 2008
1 parent b9d79f9 commit 8c8b236
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 32 deletions.
11 changes: 7 additions & 4 deletions src/main/mondrian/rolap/RolapCubeDimension.java
Expand Up @@ -39,7 +39,8 @@ public RolapCubeDimension(RolapCube parent, RolapDimension rolapDim,
this.rolapDimension = rolapDim;
this.cubeOrdinal = cubeOrdinal;
this.parent = parent;

this.caption = cubeDim.caption;

// create new hierarchies
hierarchies = new RolapCubeHierarchy[rolapDim.getHierarchies().length];

Expand Down Expand Up @@ -81,16 +82,18 @@ public boolean equals(Object o) {
RolapCubeDimension that = (RolapCubeDimension)o;
if (!parent.equals(that.parent)) {
return false;
} else {
return getUniqueName().equals(that.getUniqueName());
}
return getUniqueName().equals(that.getUniqueName());
}

RolapCubeHierarchy newHierarchy(String subName, boolean hasAll) {
throw new UnsupportedOperationException();
}

public String getCaption() {
if (caption != null) {
return caption;
}
return rolapDimension.getCaption();
}

Expand All @@ -100,7 +103,7 @@ public void setCaption(String caption) {
}
rolapDimension.setCaption(caption);
}

public DimensionType getDimensionType() {
return rolapDimension.getDimensionType();
}
Expand Down
81 changes: 53 additions & 28 deletions testsrc/main/mondrian/test/SchemaTest.java
Expand Up @@ -3,24 +3,23 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2006-2007 Julian Hyde
// Copyright (C) 2006-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.test;

import org.apache.log4j.*;
import org.apache.log4j.Level;
import org.apache.log4j.varia.LevelRangeFilter;

import mondrian.rolap.RolapCube;
import mondrian.rolap.aggmatcher.AggTableManager;
import mondrian.olap.*;
import mondrian.util.Bug;
import mondrian.olap.Cube;
import mondrian.olap.MondrianException;
import mondrian.olap.MondrianProperties;
import mondrian.olap.Result;

import java.io.StringWriter;
import java.util.List;
import java.util.ArrayList;

/**
* Unit tests for various schema features.
Expand Down Expand Up @@ -837,35 +836,45 @@ public void testDimensionUsageLevel() {
* dimension usage name is different then source name
*/
public void testAllMemberMultipleDimensionUsages() {
TestContext testContext = TestContext.create(
TestContext testContext =
TestContext.create(
null,

"<Cube name=\"Sales Two Sales Dimensions\">\n" +
" <Table name=\"sales_fact_1997\"/>\n" +
" <DimensionUsage name=\"Store\" source=\"Store\" foreignKey=\"store_id\"/>\n" +
" <DimensionUsage name=\"Store2\" source=\"Store\" foreignKey=\"product_id\"/>\n" +
" <DimensionUsage name=\"Store\" caption=\"First Store\" source=\"Store\" foreignKey=\"store_id\"/>\n" +
" <DimensionUsage name=\"Store2\" caption=\"Second Store\" source=\"Store\" foreignKey=\"product_id\"/>\n" +
" <Measure name=\"Unit Sales\" column=\"unit_sales\" aggregator=\"sum\" "+
" formatString=\"Standard\"/>\n" +
" <Measure name=\"Store Cost\" column=\"store_cost\" aggregator=\"sum\"" +
" formatString=\"#,###.00\"/>\n" +
"</Cube>",
null, null, null, null);

testContext.assertQueryReturns(
"select\n" +
" {[Store].[All Stores]} on columns,\n" +
" {[Store2].[All Store2s]} on rows\n" +
"From [Sales Two Sales Dimensions]",
fold(
"Axis #0:\n" +
"{}\n" +
"Axis #1:\n" +
"{[Store].[All Stores]}\n" +
"Axis #2:\n" +
"{[Store2].[All Store2s]}\n" +
"Row #0: 266,773\n"));

testContext.assertQueryReturns(
"select\n" +
" {[Store].[All Stores]} on columns,\n" +
" {[Store2].[All Store2s]} on rows\n" +
"From [Sales Two Sales Dimensions]",
fold(
"Axis #0:\n" +
"{}\n" +
"Axis #1:\n" +
"{[Store].[All Stores]}\n" +
"Axis #2:\n" +
"{[Store2].[All Store2s]}\n" +
"Row #0: 266,773\n"));

final Result result = testContext.executeQuery(
"select ([Store].[All Stores], [Store2].[All Store2s]) on 0\n"
+ "from [Sales Two Sales Dimensions]");
final Axis axis = result.getAxes()[0];
final Position position = axis.getPositions().get(0);
assertEquals(
"First Store", position.get(0).getDimension().getCaption());
assertEquals(
"Second Store", position.get(1).getDimension().getCaption());
}

/**
* This test displays an informative error message if someone uses
* an unaliased name instead of an aliased name
Expand Down Expand Up @@ -1658,8 +1667,7 @@ public void testUnionRoleIllegalForwardRef() {
"select from [Sales]", "Unknown role 'Role2'");
}

public void testVirtualCubeNamedSetSupportInSchema(){

public void testVirtualCubeNamedSetSupportInSchema() {
final TestContext testContext = TestContext.createSubstitutingCube(
"Warehouse and Sales", null,null, "<NamedSet name=\"Non CA State Stores\" " +
"formula=\"EXCEPT({[Store].[Store Country].[USA].children},{[Store].[Store Country].[USA].[CA]})\"/>");
Expand Down Expand Up @@ -1702,7 +1710,8 @@ public void testVirtualCubeNamedSetSupportInSchema(){
"Row #0: 266,773\n" +
"Row #0: 192,025\n"));
}
public void testVirtualCubeNamedSetSupportInSchemaError(){

public void testVirtualCubeNamedSetSupportInSchemaError() {

final TestContext testContext = TestContext.createSubstitutingCube(
"Warehouse and Sales", null,null, "<NamedSet name=\"Non CA State Stores\" " +
Expand Down Expand Up @@ -1733,6 +1742,22 @@ public void testVirtualCubeNamedSetSupportInSchemaError(){
assertTrue(e.getMessage().indexOf("bad formula") >= 0);
}
}

public void _testValidatorFindsNumericLevel() {
// In the real foodmart, the level has type="Numeric"
final TestContext testContext =
TestContext.createSubstitutingCube(
"Sales",
" <Dimension name=\"Store Size in SQFT\">\n"
+ " <Hierarchy hasAll=\"true\" primaryKey=\"store_id\">\n"
+ " <Table name=\"store\"/>\n"
+ " <Level name=\"Store Sqft\" column=\"store_sqft\" type=\"Numeric\" uniqueMembers=\"true\"/>\n"
+ " </Hierarchy>\n"
+ " </Dimension>");
final List<Throwable> list = new ArrayList<Throwable>();
// testContext.getConnection().getSchema().validate(list);
throw new RuntimeException("todo ");
}
}

// End SchemaTest.java

0 comments on commit 8c8b236

Please sign in to comment.