Skip to content

Commit

Permalink
MONDRIAN: fixing bug MONDRIAN-715
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian-release/3.2/": change = 13501]
  • Loading branch information
Matt Campbell authored and Matt Campbell committed Mar 22, 2010
1 parent 440b581 commit c868c71
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 5 deletions.
59 changes: 58 additions & 1 deletion src/main/mondrian/olap/fun/NativizeSetFunDef.java
Expand Up @@ -105,7 +105,13 @@ public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
}
return calc;
} else if (substitutionMap.isEmpty()) {
return funArg.accept(compiler);
Calc calc = funArg.accept(compiler);
if (calc instanceof TupleIterCalc) {
return new NonNativeTupleIterCalc((TupleIterCalc) calc);
} else if (calc instanceof TupleListCalc) {
return new NonNativeTupleListCalc((TupleListCalc) calc);
}
return calc;
} else {
if (isFirstCompileCall) {
isFirstCompileCall = false;
Expand Down Expand Up @@ -246,6 +252,57 @@ public Iterable evaluateIterable(final Evaluator evaluator) {
}
}

static class NonNativeTupleIterCalc extends NonNativeCalc
implements TupleIterCalc
{
protected NonNativeTupleIterCalc(TupleIterCalc parent) {
super(parent, false);
}

TupleIterCalc parent() {
return (TupleIterCalc) parent;
}

public SetType getType() {
return parent().getType();
}

public Iterable<Member[]> evaluateTupleIterable(Evaluator evaluator) {
evaluator.setNativeEnabled(nativeEnabled);
return parent().evaluateTupleIterable(evaluator);
}

public Iterable evaluateIterable(Evaluator evaluator) {
evaluator.setNativeEnabled(nativeEnabled);
return parent().evaluateIterable(evaluator);
}
}

static class NonNativeTupleListCalc extends NonNativeCalc
implements TupleListCalc
{
protected NonNativeTupleListCalc(TupleListCalc parent) {
super(parent, false);
}

TupleListCalc parent() {
return (TupleListCalc) parent;
}

public Type getType() {
return parent().getType();
}

public List<Member[]> evaluateTupleList(Evaluator evaluator) {
evaluator.setNativeEnabled(nativeEnabled);
return parent().evaluateTupleList(evaluator);
}

public List evaluateList(Evaluator evaluator) {
evaluator.setNativeEnabled(nativeEnabled);
return parent().evaluateList(evaluator);
}
}

public static class NativeTupleListCalc extends AbstractTupleListCalc {
private final SubstitutionMap substitutionMap;
Expand Down
8 changes: 5 additions & 3 deletions src/main/mondrian/rolap/sql/CrossJoinArgFactory.java
Expand Up @@ -124,9 +124,11 @@ List<CrossJoinArg[]> checkCrossJoinArg(
return Collections.singletonList(cjArgs);
}

cjArgs = checkConstrainedMeasures(evaluator, fun, args);
if (cjArgs != null) {
return Collections.singletonList(cjArgs);
if (returnAny) {
cjArgs = checkConstrainedMeasures(evaluator, fun, args);
if (cjArgs != null) {
return Collections.singletonList(cjArgs);
}
}

List<CrossJoinArg[]> allArgs =
Expand Down
2 changes: 1 addition & 1 deletion testsrc/main/mondrian/olap/fun/NativizeSetFunDefTest.java
Expand Up @@ -492,7 +492,7 @@ public void testNoSubstitutionsArityOne() {
}

public void testNoSubstitutionsArityTwo() {
checkNative(
checkNotNative(
"SELECT NativizeSet(CrossJoin("
+ "{Gender.F, Gender.M}, "
+ "{ [Marital Status].M } "
Expand Down
30 changes: 30 additions & 0 deletions testsrc/main/mondrian/rolap/NonEmptyTest.java
Expand Up @@ -3935,6 +3935,36 @@ public void testNonUniformConstraintsAreNotUsedForOptimization() {
getTestContext(), mdx, new SqlPattern[]{pattern},true, false, true);
}

public void testMeasureConstraintsInACrossjoinHaveCorrectResults() {
//http://jira.pentaho.com/browse/MONDRIAN-715
propSaver.set(MondrianProperties.instance().EnableNativeNonEmpty, true);
String mdx =
"with "
+ " member [Measures].[aa] as '([Measures].[Store Cost],[Gender].[M])'"
+ " member [Measures].[bb] as '([Measures].[Store Cost],[Gender].[F])'"
+ " select"
+ " non empty "
+ " crossjoin({[Store].[All Stores].[USA].[CA]},"
+ " {[Measures].[aa], [Measures].[bb]}) on columns,"
+ " non empty "
+ " [Marital Status].[Marital Status].members on rows"
+ " from sales";
assertQueryReturns(
mdx,
"Axis #0:\n"
+ "{}\n"
+ "Axis #1:\n"
+ "{[Store].[All Stores].[USA].[CA], [Measures].[aa]}\n"
+ "{[Store].[All Stores].[USA].[CA], [Measures].[bb]}\n"
+ "Axis #2:\n"
+ "{[Marital Status].[All Marital Status].[M]}\n"
+ "{[Marital Status].[All Marital Status].[S]}\n"
+ "Row #0: 15,339.94\n"
+ "Row #0: 15,941.98\n"
+ "Row #1: 16,598.87\n"
+ "Row #1: 15,649.64\n");
}

public void testContextAtAllWorksWithConstraint() {
TestContext ctx = TestContext.create(
null,
Expand Down

0 comments on commit c868c71

Please sign in to comment.