Skip to content

Commit

Permalink
Fix bug 3030772, "DrilldownLevelTop parser error" by adding support f…
Browse files Browse the repository at this point in the history
…or empty

expressions in argument list. Copied from mondrian change 10047.


git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@325 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Jul 18, 2010
1 parent 9f80214 commit 8f72d8b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/org/olap4j/mdx/CallNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public CallNode(
case Internal:
assert name.startsWith("$");
break;
case Empty:
assert name.equals("");
break;
default:
assert !name.startsWith("$")
&& !name.equals("{}")
Expand Down
22 changes: 21 additions & 1 deletion src/org/olap4j/mdx/Syntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,27 @@ public void unparse(
* Defines syntax for expression invoked <code>object&#46;[&PROPERTY]</code>
* (a variant of {@link #Property}).
*/
AmpersandQuotedProperty;
AmpersandQuotedProperty,

/**
* Defines the syntax for an empty expression. Empty expressions can occur
* within function calls, and are denoted by a pair of commas with only
* whitespace between them, for example
*
* <blockquote>
* <code>DrillDownLevelTop({[Product].[All Products]}, 3, ,
* [Measures].[Unit Sales])</code>
* </blockquote>
*/
Empty {
public void unparse(
String operatorName,
List<ParseTreeNode> argList,
ParseTreeWriter writer)
{
assert argList.size() == 0;
}
};

/**
* Converts a call to a function of this syntax into source code.
Expand Down
10 changes: 9 additions & 1 deletion src/org/olap4j/mdx/parser/impl/DefaultMdxParser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ non terminal ParseTreeNode
case_expression,
else_clause_opt,
expression,
expression_or_empty,
factor,
filter_specification,
term,
Expand Down Expand Up @@ -1244,6 +1245,13 @@ expression ::=
:}
| value_expression
;
expression_or_empty ::=
expression
| /* empty */ {:
final ParseRegion region = createRegion(0, 0);
RESULT = new CallNode(region, "", Syntax.Empty);
:}
;
exp_list_opt ::=
/* empty */ {:
RESULT = new LinkedList();
Expand All @@ -1255,7 +1263,7 @@ exp_list ::=
RESULT = new LinkedList();
RESULT.add(e);
:}
| expression:e COMMA exp_list:list {:
| expression_or_empty:e COMMA exp_list:list {:
list.add(0, e); RESULT = list;
:}
;
Expand Down
31 changes: 31 additions & 0 deletions testsrc/org/olap4j/test/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,37 @@ public void testIdentifier() {
}
}

/**
* Test case for empty expressions. Test case for <a href=
"http://sf.net/tracker/?func=detail&aid=3030772&group_id=168953&atid=848534"
* > bug 3030772, "DrilldownLevelTop parser error"</a>.
*/
public void testEmptyExpr() {
assertParseQuery(
"select NON EMPTY HIERARCHIZE(\n"
+ " {DrillDownLevelTop(\n"
+ " {[Product].[All Products]},3,,[Measures].[Unit Sales])}"
+ " ) ON COLUMNS\n"
+ "from [Sales]\n",
"SELECT\n"
+ "NON EMPTY HIERARCHIZE({DrillDownLevelTop({[Product].[All Products]}, 3.0, , [Measures].[Unit Sales])}) ON COLUMNS\n"
+ "FROM [Sales]");

// more advanced; the actual test case in the bug
assertParseQuery(
"SELECT {[Measures].[NetSales]}"
+ " DIMENSION PROPERTIES PARENT_UNIQUE_NAME ON COLUMNS ,"
+ " NON EMPTY HIERARCHIZE(AddCalculatedMembers("
+ "{DrillDownLevelTop({[ProductDim].[Name].[All]}, 10, ,"
+ " [Measures].[NetSales])}))"
+ " DIMENSION PROPERTIES PARENT_UNIQUE_NAME ON ROWS "
+ "FROM [cube]",
"SELECT\n"
+ "{[Measures].[NetSales]} DIMENSION PROPERTIES PARENT_UNIQUE_NAME ON COLUMNS,\n"
+ "NON EMPTY HIERARCHIZE(AddCalculatedMembers({DrillDownLevelTop({[ProductDim].[Name].[All]}, 10.0, , [Measures].[NetSales])})) DIMENSION PROPERTIES PARENT_UNIQUE_NAME ON ROWS\n"
+ "FROM [cube]");
}

/**
* Parses an MDX query and asserts that the result is as expected when
* unparsed.
Expand Down

0 comments on commit 8f72d8b

Please sign in to comment.