Pentaho Analysis - Mondrian

NPE in Query with Crossjoin Descendants of Unknown Member - Testcase + Fix included

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Severe Severe
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: Native SQL
  • Labels:
    None

Description

Unfortunately the patch is against a snapshot about 2 years ago, not sure which version it is.

The following query throws NPE when IgnoreInvalidMembersDuringQuery is true:

select {[Measures].[Unit Sales]} on columns,
NON EMPTY CrossJoin(
  Descendants([Product].[All Products], [Product].[Product Family]),
  Descendants([Store].[All Stores].[Foo], [Store].[Store State])) on rows
from [Sales]

My fix was to add a special treatment to SqlConstraintUtils.generateSingleValueInExpr():
            RolapMember m = c.iterator().next();
            if (m.isAll()) {
                continue;
            }
            if (m.isNull()) {
              return "1 = 0";
            }
            if (m.isCalculated()) {


Complete patch:
### Eclipse Workspace Patch 1.0
#P mondrian-3.1.1
Index: src/main/mondrian/rolap/SqlConstraintUtils.java
===================================================================
RCS file: /cvsroot/mondrian-3.1.1/src/main/mondrian/rolap/SqlConstraintUtils.java,v
retrieving revision 1.1
diff -u -r1.1 SqlConstraintUtils.java
--- src/main/mondrian/rolap/SqlConstraintUtils.java 25 May 2009 15:22:14 -0000 1.1
+++ src/main/mondrian/rolap/SqlConstraintUtils.java 10 Aug 2011 07:19:17 -0000
@@ -941,6 +941,9 @@
             if (m.isAll()) {
                 continue;
             }
+ if (m.isNull()) {
+ return "1 = 0";
+ }
             if (m.isCalculated()) {
                 if (restrictMemberTypes) {
                     throw Util.newInternal("addMemberConstraint: cannot " +
Index: testsrc/main/mondrian/test/BasicQueryTest.java
===================================================================
RCS file: /cvsroot/mondrian-3.1.1/testsrc/main/mondrian/test/BasicQueryTest.java,v
retrieving revision 1.2
diff -u -r1.2 BasicQueryTest.java
--- testsrc/main/mondrian/test/BasicQueryTest.java 29 May 2009 07:16:05 -0000 1.2
+++ testsrc/main/mondrian/test/BasicQueryTest.java 10 Aug 2011 07:19:17 -0000
@@ -5213,6 +5213,27 @@
             "select [Measures].[Sales Count] + 1 on 0, non empty [Store].[Store State].members on 1 from [Sales]",
             "Axis 'COLUMNS' expression is not a set");
     }
+
+ public void testCrossjoinWithDescendantsAndUnknownMemberBug() {
+ MondrianProperties conf = MondrianProperties.instance();
+ boolean previousValue = conf.IgnoreInvalidMembersDuringQuery.get();
+ conf.IgnoreInvalidMembersDuringQuery.set(true);
+ try {
+ assertQueryReturns(
+ "select {[Measures].[Unit Sales]} on columns,\n"
+ + "NON EMPTY CrossJoin(\n"
+ + " Descendants([Product].[All Products], [Product].[Product Family]),\n"
+ + " Descendants([Store].[All Stores].[Foo], [Store].[Store State])) on rows\n"
+ + "from [Sales]", "Axis #0:\n" +
+ "{}\n" +
+ "Axis #1:\n" +
+ "{[Measures].[Unit Sales]}\n" +
+ "Axis #2:\n" );
+ } finally {
+ conf.IgnoreInvalidMembersDuringQuery.set(previousValue);
+ }
+
+ }
 
     /**
      * It is illegal for a query to have the same dimension on more than

Activity

Hide
Julian Hyde added a comment - 10/Aug/11 2:59 PM
Fixed in change 14539.
Show
Julian Hyde added a comment - 10/Aug/11 2:59 PM Fixed in change 14539.

People

Vote (0)
Watch (1)

Dates

  • Created:
    10/Aug/11 3:50 AM
    Updated:
    10/Aug/11 2:59 PM
    Resolved:
    10/Aug/11 2:56 PM