mondrian连接mysql报异常:Error while instantiating dialect

注意观察java exception stack:

 Caused by: java.util.regex.PatternSyntaxException: Unclosed group near index 19
^.*(\\Q(.*)\\E).*$
                   ^
        at java.util.regex.Pattern.error(Pattern.java:1700)
        at java.util.regex.Pattern.accept(Pattern.java:1558)
        at java.util.regex.Pattern.group0(Pattern.java:2494)
        at java.util.regex.Pattern.sequence(Pattern.java:1793)
        at java.util.regex.Pattern.expr(Pattern.java:1739)
        at java.util.regex.Pattern.compile(Pattern.java:1447)
        at java.util.regex.Pattern.(Pattern.java:1130)
        at java.util.regex.Pattern.compile(Pattern.java:822)
        at mondrian.spi.impl.MySqlDialect.(MySqlDialect.java:30)
        ... 52 more

在MySqlDialect.java第30行找到出错的代码:

private final String escapeRegexp = "^.*(\\\\Q(.*)\\\\E).*$";
private final Pattern escapePattern = Pattern.compile(escapeRegexp);

一番尝试后,发现原来\Q在java正则表达式里有特殊作用,导致Pattern compile异常。

改成以下等价表达式即能解决

private final String escapeRegexp = "^.*(\\\\[Q](.*)\\\\E).*$";
private final Pattern escapePattern = Pattern.compile(escapeRegexp);

重新编译MySqlDialect.java, 用winrar等压缩工具打开mondrian.jar,删除classesmondrianspiimpl下MySqlDialect.class三个相关文件,然后再把新编译好的三个class文件拖进去替换完即可。

此bug上报pentaho了,竟然没人理,全世界只有我碰到这个问题吗? http://jira.pentaho.com/browse/MONDRIAN-1380

Comments