Skip to content

Commit

Permalink
MONDRIAN: Fix MONDRIAN-831, "Failure parsing queries with member iden…
Browse files Browse the repository at this point in the history
…tifiers

    beginning with '_' and not expressed between brackets".

[git-p4: depot-paths = "//open/mondrian-release/3.2/": change = 13902]
  • Loading branch information
julianhyde committed Nov 9, 2010
1 parent 5f416e2 commit 5676624
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/main/mondrian/olap/Scanner.java
Expand Up @@ -612,6 +612,7 @@ public Symbol next_token() throws IOException {
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
case '_': case '$':
/* parse an identifier */
id = new StringBuilder();
for (;;) {
Expand All @@ -630,7 +631,7 @@ public Symbol next_token() throws IOException {
case 'Y': case 'Z':
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '_':
case '_': case '$':
break;
default:
String strId = id.toString();
Expand Down
48 changes: 43 additions & 5 deletions testsrc/main/mondrian/olap/ParserTest.java
Expand Up @@ -18,7 +18,6 @@

import java.io.StringWriter;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

/**
Expand Down Expand Up @@ -92,22 +91,61 @@ public void testNegativeCases() throws Exception {
+ "from [sales]\n");
}

/**
* Test case for bug <a href="http://jira.pentaho.com/browse/MONDRIAN-831">
* MONDRIAN-831, "Failure parsing queries with member identifiers beginning
* with '_' and not expressed between brackets"</a>.
*
* <p>According to the spec
* <a href="http://msdn.microsoft.com/en-us/library/ms145572.aspx">
* Identifiers (MDX)</a>, the first character of a regular identifier
* must be a letter (per the unicode standard 2.0) or underscore. Subsequent
* characters must be a letter, and underscore, or a digit.
*/
public void testScannerPunc() {
// '$' is OK inside brackets but not outside
assertParseQuery(
"with member [Measures].__Foo as 1 + 2\n"
+ "select __Foo on 0\n"
+ "from _Bar_Baz",
"with member [Measures].__Foo as '(1.0 + 2.0)'\n"
+ "select __Foo ON COLUMNS\n"
+ "from [_Bar_Baz]\n");

// # is not allowed
assertParseQueryFails(
"with member [Measures].#_Foo as 1 + 2\n"
+ "select __Foo on 0\n"
+ "from _Bar#Baz",
"Unexpected character '#'");
assertParseQueryFails(
"with member [Measures].Foo as 1 + 2\n"
+ "select Foo on 0\n"
+ "from Bar#Baz",
"Unexpected character '#'");

// The spec doesn't allow $ but SSAS allows it so we allow it too.
assertParseQuery(
"with member [Measures].$Foo as 1 + 2\n"
+ "select $Foo on 0\n"
+ "from Bar$Baz",
"with member [Measures].$Foo as '(1.0 + 2.0)'\n"
+ "select $Foo ON COLUMNS\n"
+ "from [Bar$Baz]\n");
// '$' is OK inside brackets too
assertParseQuery(
"select [measures].[$foo] on columns from sales",
"select [measures].[$foo] ON COLUMNS\n"
+ "from [sales]\n");
assertParseQueryFails(
"select [measures].$foo on columns from sales",
"Unexpected character '$'");

// ']' unexcpected
assertParseQueryFails(
"select { Customers].Children } on columns from [Sales]",
"Unexpected character ']'");
}

public void testUnderscore() {
}

public void testUnparse() {
checkUnparse(
"with member [Measures].[Foo] as ' 123 '\n"
Expand Down
6 changes: 3 additions & 3 deletions testsrc/main/mondrian/test/BasicQueryTest.java
Expand Up @@ -2480,16 +2480,16 @@ public void testDynamicFormat() {

public void testFormatOfNulls() {
assertQueryReturns(
"with member [Measures].[Foo] as '([Measures].[Store Sales])',\n"
"with member [Measures]._Foo as '([Measures].[Store Sales])',\n"
+ " format_string = '$#,##0.00;($#,##0.00);ZERO;NULL;Nil'\n"
+ "select\n"
+ " {[Measures].[Foo]} on columns,\n"
+ " {[Measures].[_Foo]} on columns,\n"
+ " {[Customers].[Country].members} on rows\n"
+ "from Sales",
"Axis #0:\n"
+ "{}\n"
+ "Axis #1:\n"
+ "{[Measures].[Foo]}\n"
+ "{[Measures].[_Foo]}\n"
+ "Axis #2:\n"
+ "{[Customers].[Canada]}\n"
+ "{[Customers].[Mexico]}\n"
Expand Down

0 comments on commit 5676624

Please sign in to comment.