Skip to content

Commit

Permalink
MONDRIAN: Fix for bug # 1732824, Cube getTimeDimension use when Cube …
Browse files Browse the repository at this point in the history
…has no Time dimension. Also added test case to test with member order function.

[git-p4: depot-paths = "//open/mondrian/": change = 10515]
  • Loading branch information
Will Gorman committed Feb 4, 2008
1 parent ff6b1f2 commit 0042705
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 18 deletions.
15 changes: 12 additions & 3 deletions src/main/mondrian/olap/fun/LastPeriodsFunDef.java
Expand Up @@ -14,6 +14,7 @@
import mondrian.olap.type.SetType;
import mondrian.olap.type.MemberType;
import mondrian.olap.type.TypeUtil;
import mondrian.resource.MondrianResource;
import mondrian.calc.Calc;
import mondrian.calc.ExpCompiler;
import mondrian.calc.MemberCalc;
Expand Down Expand Up @@ -49,9 +50,13 @@ public Type getResultType(Validator validator, Exp[] args) {
if (args.length == 1) {
// If Member is not specified,
// it is Time.CurrentMember.
Hierarchy hierarchy = validator.getQuery()
.getCube().getTimeDimension()
.getHierarchy();
Dimension defaultTimeDimension =
validator.getQuery().getCube().getTimeDimension();
if (defaultTimeDimension == null) {
throw MondrianResource.instance().
NoTimeDimensionInCube.ex(getName());
}
Hierarchy hierarchy = defaultTimeDimension.getHierarchy();
return new SetType(MemberType.forHierarchy(hierarchy));
} else {
Type type = args[1].getType();
Expand All @@ -69,6 +74,10 @@ public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
Dimension timeDimension =
compiler.getEvaluator().getCube()
.getTimeDimension();
if (timeDimension == null) {
throw MondrianResource.instance().
NoTimeDimensionInCube.ex(getName());
}
memberCalc = new DimensionCurrentMemberCalc(
timeDimension);
} else {
Expand Down
28 changes: 22 additions & 6 deletions src/main/mondrian/olap/fun/OpeningClosingPeriodFunDef.java
Expand Up @@ -68,8 +68,13 @@ public Type getResultType(Validator validator, Exp[] args) {
// With no args, the default implementation cannot
// guess the hierarchy, so we supply the Time
// dimension.
Hierarchy hierarchy = validator.getQuery()
.getCube().getTimeDimension()
Dimension defaultTimeDimension =
validator.getQuery().getCube().getTimeDimension();
if (defaultTimeDimension == null) {
throw MondrianResource.instance().
NoTimeDimensionInCube.ex(getName());
}
Hierarchy hierarchy = defaultTimeDimension
.getHierarchy();
return MemberType.forHierarchy(hierarchy);
}
Expand All @@ -80,16 +85,27 @@ public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final Exp[] args = call.getArgs();
final LevelCalc levelCalc;
final MemberCalc memberCalc;
Dimension defaultTimeDimension = null;
switch (args.length) {
case 0:
memberCalc = new DimensionCurrentMemberCalc(
compiler.getEvaluator().getCube().getTimeDimension());
defaultTimeDimension =
compiler.getEvaluator().getCube().getTimeDimension();
if (defaultTimeDimension == null) {
throw MondrianResource.instance().
NoTimeDimensionInCube.ex(getName());
}
memberCalc = new DimensionCurrentMemberCalc(defaultTimeDimension);
levelCalc = null;
break;
case 1:
defaultTimeDimension =
compiler.getEvaluator().getCube().getTimeDimension();
if (defaultTimeDimension == null) {
throw MondrianResource.instance().
NoTimeDimensionInCube.ex(getName());
}
levelCalc = compiler.compileLevel(call.getArg(0));
memberCalc = new DimensionCurrentMemberCalc(
compiler.getEvaluator().getCube().getTimeDimension());
memberCalc = new DimensionCurrentMemberCalc(defaultTimeDimension);
break;
default:
levelCalc = compiler.compileLevel(call.getArg(0));
Expand Down
14 changes: 11 additions & 3 deletions src/main/mondrian/olap/fun/ParallelPeriodFunDef.java
Expand Up @@ -43,9 +43,13 @@ public Type getResultType(Validator validator, Exp[] args) {
// With no args, the default implementation cannot
// guess the hierarchy, so we supply the Time
// dimension.
Hierarchy hierarchy = validator.getQuery()
.getCube().getTimeDimension()
.getHierarchy();
Dimension defaultTimeDimension =
validator.getQuery().getCube().getTimeDimension();
if (defaultTimeDimension == null) {
throw MondrianResource.instance().
NoTimeDimensionInCube.ex(getName());
}
Hierarchy hierarchy = defaultTimeDimension.getHierarchy();
return MemberType.forHierarchy(hierarchy);
}
return super.getResultType(validator, args);
Expand All @@ -68,6 +72,10 @@ public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final Dimension timeDimension =
compiler.getEvaluator().getCube()
.getTimeDimension();
if (timeDimension == null) {
throw MondrianResource.instance().
NoTimeDimensionInCube.ex(getName());
}
memberCalc = new DimensionCurrentMemberCalc(
timeDimension);
break;
Expand Down
19 changes: 16 additions & 3 deletions src/main/mondrian/olap/fun/PeriodsToDateFunDef.java
Expand Up @@ -46,9 +46,13 @@ public Type getResultType(Validator validator, Exp[] args) {
if (args.length == 0) {
// With no args, the default implementation cannot
// guess the hierarchy.
Hierarchy hierarchy = validator.getQuery()
.getCube().getTimeDimension()
.getHierarchy();
Dimension defaultTimeDimension =
validator.getQuery().getCube().getTimeDimension();
if (defaultTimeDimension == null) {
throw MondrianResource.instance().
NoTimeDimensionInCube.ex(getName());
}
Hierarchy hierarchy = defaultTimeDimension.getHierarchy();
return new SetType(
MemberType.forHierarchy(hierarchy));
}
Expand All @@ -72,11 +76,16 @@ public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
null;
final Dimension timeDimension = compiler
.getEvaluator().getCube().getTimeDimension();

return new AbstractListCalc(call, new Calc[] {levelCalc, memberCalc}) {
public List evaluateList(Evaluator evaluator) {
final Member member;
final Level level;
if (levelCalc == null) {
if (timeDimension == null) {
throw MondrianResource.instance().
NoTimeDimensionInCube.ex(getName());
}
member = evaluator.getContext(timeDimension);
level = member.getLevel().getParentLevel();
} else {
Expand All @@ -100,6 +109,10 @@ public boolean dependsOn(Dimension dimension) {
} else if (levelCalc != null) {
return levelCalc.getType().usesDimension(dimension, true) ;
} else {
if (timeDimension == null) {
throw MondrianResource.instance().
NoTimeDimensionInCube.ex(getName());
}
return dimension == timeDimension;
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/mondrian/olap/fun/XtdFunDef.java
Expand Up @@ -68,9 +68,13 @@ public Type getResultType(Validator validator, Exp[] args) {
if (args.length == 0) {
// With no args, the default implementation cannot
// guess the hierarchy.
Hierarchy hierarchy = validator.getQuery()
.getCube().getTimeDimension()
.getHierarchy();
Dimension defaultTimeDimension =
validator.getQuery().getCube().getTimeDimension();
if (defaultTimeDimension == null) {
throw MondrianResource.instance().
NoTimeDimensionInCube.ex(getName());
}
Hierarchy hierarchy = defaultTimeDimension.getHierarchy();
return new SetType(MemberType.forHierarchy(hierarchy));
}
final Type type = args[0].getType();
Expand Down
4 changes: 4 additions & 0 deletions src/main/mondrian/resource/MondrianResource.xml
Expand Up @@ -256,6 +256,10 @@
<text>Function does not support two NULL member parameters</text>
</exception>

<exception id="350600" name="NoTimeDimensionInCube">
<text>Cannot use the function ''{0}'', no time dimension is available for this cube.</text>
</exception>

<!-- ====================================================================== -->
<!-- Connectivity errors -->

Expand Down
40 changes: 40 additions & 0 deletions testsrc/main/mondrian/olap/fun/FunctionTest.java
Expand Up @@ -5421,6 +5421,32 @@ public void testOrderCalc() {
"{}(Sublist(ContextCalc([Measures].[Store Sales], Order(Filter(Children(CurrentMember([Product])), >(MemberValueCalc([Measures].[Unit Sales]), 1000.0)), MemberValueCalc([Gender].[All Gender].[M]), ASC))))");
}


/**
* This test case verifies that the order function works with a defined member.
* See this forum post for additional information:
* http://forums.pentaho.org/showthread.php?p=179473#post179473
*/
public void testOrderWithMember() {
assertQueryReturns("with member [Measures].[Product Name Length] as 'LEN([Product].CurrentMember.Name)'\n" +
"select {[Measures].[Product Name Length]} ON COLUMNS,\n" +
"Order([Product].[All Products].Children, [Measures].[Product Name Length], BASC) ON ROWS\n" +
"from [Sales]",
fold(
"Axis #0:\n" +
"{}\n" +
"Axis #1:\n" +
"{[Measures].[Product Name Length]}\n" +
"Axis #2:\n" +
"{[Product].[All Products].[Food]}\n" +
"{[Product].[All Products].[Drink]}\n" +
"{[Product].[All Products].[Non-Consumable]}\n" +
"Row #0: 4\n" +
"Row #1: 5\n" +
"Row #2: 14\n"));

}

/**
* test case for bug # 1797159, Potential MDX Order Non Empty Problem
*
Expand Down Expand Up @@ -7979,6 +8005,20 @@ public void testExcelPower() {
public void testBug1881739() {
assertExprReturns("LEFT(\"TEST\", LEN(\"TEST\"))", "TEST");
}

/**
* Test for Bug #1732824, Cube getTimeDimension use when Cube has no Time dimension
*/
public void testCubeTimeDimensionFails() {
assertThrows("select LastPeriods(1) on columns from [Store]", "'LastPeriods', no time dimension");
assertThrows("select OpeningPeriod() on columns from [Store]", "'OpeningPeriod', no time dimension");
assertThrows("select OpeningPeriod([Store Type]) on columns from [Store]", "'OpeningPeriod', no time dimension");
assertThrows("select ClosingPeriod() on columns from [Store]", "'ClosingPeriod', no time dimension");
assertThrows("select ClosingPeriod([Store Type]) on columns from [Store]", "'ClosingPeriod', no time dimension");
assertThrows("select ParallelPeriod() on columns from [Store]", "'ParallelPeriod', no time dimension");
assertThrows("select PeriodsToDate() on columns from [Store]", "'PeriodsToDate', no time dimension");
assertThrows("select Mtd() on columns from [Store]", "'Mtd', no time dimension");
}
}

// End FunctionTest.java

0 comments on commit 0042705

Please sign in to comment.