Skip to content

Commit

Permalink
Implement the Caption MDX function.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 2966]
  • Loading branch information
ebb committed Dec 17, 2004
1 parent 13fc8f3 commit f0dbfdc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/main/mondrian/olap/fun/BuiltinFunTable.java
Expand Up @@ -1954,6 +1954,30 @@ public Object evaluate(Evaluator evaluator, Exp[] args) {
return getStringArg(evaluator, args, 2, null);
}
});
define(new FunDefBase("Caption", "<Dimension>.Caption", "Returns the caption of a dimension.", "pSd") {
public Object evaluate(Evaluator evaluator, Exp[] args) {
Dimension dimension = getDimensionArg(evaluator, args, 0, true);
return dimension.getCaption();
}
});
define(new FunDefBase("Caption", "<Hierarchy>.Caption", "Returns the caption of a hierarchy.", "pSh") {
public Object evaluate(Evaluator evaluator, Exp[] args) {
Hierarchy hierarchy = getHierarchyArg(evaluator, args, 0, true);
return hierarchy.getCaption();
}
});
define(new FunDefBase("Caption", "<Level>.Caption", "Returns the caption of a level.", "pSl") {
public Object evaluate(Evaluator evaluator, Exp[] args) {
Level level = getLevelArg(evaluator, args, 0, true);
return level.getCaption();
}
});
define(new FunDefBase("Caption", "<Member>.Caption", "Returns the caption of a member.", "pSm") {
public Object evaluate(Evaluator evaluator, Exp[] args) {
Member member = getMemberArg(evaluator, args, 0, true);
return member.getCaption();
}
});
define(new FunDefBase("Name", "<Dimension>.Name", "Returns the name of a dimension.", "pSd") {
public Object evaluate(Evaluator evaluator, Exp[] args) {
Dimension dimension = getDimensionArg(evaluator, args, 0, true);
Expand Down
27 changes: 24 additions & 3 deletions testsrc/main/mondrian/olap/fun/FunctionTest.java
Expand Up @@ -1623,7 +1623,28 @@ public void testIIf() {
Assert.assertEquals("Yes", s);
}


public void testDimensionCaption() {
String s = executeExpr("[Time].[1997].Dimension.Caption");
Assert.assertEquals("Time", s);
}

public void testHierarchyCaption() {
String s = executeExpr("[Time].[1997].Hierarchy.Caption");
Assert.assertEquals("Time", s);
}

public void testLevelCaption() {
String s = executeExpr("[Time].[1997].Level.Caption");
Assert.assertEquals("Year", s);
}

public void testMemberCaption() {
String s = executeExpr("[Time].[1997].Caption");
Assert.assertEquals("1997", s);
}


public void testDimensionName() {
String s = executeExpr("[Time].[1997].Dimension.Name");
Assert.assertEquals("Time", s);
Expand All @@ -1633,18 +1654,18 @@ public void testHierarchyName() {
String s = executeExpr("[Time].[1997].Hierarchy.Name");
Assert.assertEquals("Time", s);
}

public void testLevelName() {
String s = executeExpr("[Time].[1997].Level.Name");
Assert.assertEquals("Year", s);
}

public void testMemberName() {
String s = executeExpr("[Time].[1997].Name");
Assert.assertEquals("1997", s);
}


public void testDimensionUniqueName() {
String s = executeExpr("[Gender].DefaultMember.Dimension.UniqueName");
Assert.assertEquals("[Gender]", s);
Expand Down

0 comments on commit f0dbfdc

Please sign in to comment.