Skip to content

Commit

Permalink
MONDRIAN - NativizetSet, turning off native evaluation if the arg has…
Browse files Browse the repository at this point in the history
… arity of 1

[git-p4: depot-paths = "//open/mondrian/": change = 13138]
  • Loading branch information
Matt Campbell authored and Matt Campbell committed Oct 28, 2009
1 parent d01301d commit 6aa4385
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
44 changes: 42 additions & 2 deletions src/main/mondrian/olap/fun/NativizeSetFunDef.java
Expand Up @@ -6,6 +6,7 @@
import mondrian.olap.*;
import static mondrian.olap.fun.NativizeSetFunDef.NativeElementType.*;
import mondrian.olap.type.SetType;
import mondrian.olap.type.Type;
import mondrian.resource.MondrianResource;
import org.apache.log4j.Logger;

Expand Down Expand Up @@ -106,8 +107,8 @@ public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
throw new IllegalArgumentException(
"unexpected value for .getArity() - " + arity);
} else if (arity == 1) {
compiler.getEvaluator().setNonEmpty(false);
return funArg.accept(compiler);
Calc calc = funArg.accept(compiler);
return new NonNativeMemberListCalc((MemberListCalc) calc);
} else if (substitutionMap.isEmpty()) {
return funArg.accept(compiler);
} else {
Expand All @@ -125,6 +126,45 @@ public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
}
}

public static class NonNativeMemberListCalc implements MemberListCalc {
private final MemberListCalc parent;

protected NonNativeMemberListCalc(MemberListCalc parent) {
this.parent = parent;
}

public Object evaluate(final Evaluator evaluator) {
evaluator.setNativeEnabled(false);
return parent.evaluate(evaluator);
}

public boolean dependsOn(final Hierarchy hierarchy) {
return parent.dependsOn(hierarchy);
}

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

public void accept(final CalcWriter calcWriter) {
parent.accept(calcWriter);
}

public ResultStyle getResultStyle() {
return parent.getResultStyle();
}

public List<Member> evaluateMemberList(final Evaluator evaluator) {
evaluator.setNativeEnabled(false);
return parent.evaluateMemberList(evaluator);
}

public List evaluateList(final Evaluator evaluator) {
evaluator.setNativeEnabled(false);
return parent.evaluateMemberList(evaluator);
}
}

public static class NativeTupleListCalc extends AbstractTupleListCalc {
private final SubstitutionMap substitutionMap;
private final TupleListCalc simpleCalc;
Expand Down
5 changes: 3 additions & 2 deletions src/main/mondrian/rolap/RolapEvaluator.java
Expand Up @@ -106,6 +106,8 @@ protected RolapEvaluator(
if (parent == null) {
depth = 0;
nonEmpty = false;
nativeEnabled =
MondrianProperties.instance().EnableNativeNonEmpty.get();
evalAxes = false;
cellReader = null;
final int hierarchyCount = root.cube.getHierarchies().size();
Expand All @@ -117,6 +119,7 @@ protected RolapEvaluator(
} else {
depth = parent.depth + 1;
nonEmpty = parent.nonEmpty;
nativeEnabled = parent.nativeEnabled;
evalAxes = parent.evalAxes;
cellReader = parent.cellReader;
currentMembers = parent.currentMembers.clone();
Expand All @@ -131,8 +134,6 @@ protected RolapEvaluator(
}
expandingMember = parent.expandingMember;
}
nativeEnabled =
MondrianProperties.instance().EnableNativeNonEmpty.get();
}

/**
Expand Down
29 changes: 29 additions & 0 deletions testsrc/main/mondrian/olap/fun/NativizeSetFunDefTest.java
Expand Up @@ -1244,6 +1244,35 @@ public void testCalculatedLevelsDoNotCauseException() {
checkNotNative(mdx);
}

public void testAxisWithArityOneIsNotNativelyEvaluated() {
SqlPattern[] patterns = {
new SqlPattern(
Dialect.DatabaseProduct.ACCESS,
"select `promotion`.`media_type` as `c0` "
+ "from `promotion` as `promotion`, `sales_fact_1997` as `sales_fact_1997` "
+ "where `sales_fact_1997`.`promotion_id` = `promotion`.`promotion_id` "
+ "group by `promotion`.`media_type` "
+ "order by Iif(`promotion`.`media_type` IS NULL, 1, 0), "
+ "`promotion`.`media_type` ASC", 296)
};
String query =
"select "
+ " NON EMPTY "
+ " NativizeSet("
+ " Except("
+ " {[Promotion Media].[Promotion Media].Members},\n"
+ " {[Promotion Media].[All Media].[Bulk Mail],[Promotion Media].[All Media].[Daily Paper]}"
+ " )"
+ " ) ON COLUMNS,"
+ " NON EMPTY "
+ " {[Measures].[Unit Sales]} ON ROWS "
+ "from [Sales] \n"
+ "where [Time].[1997]";
assertQuerySqlOrNot(
getTestContext(), query, patterns, true, false, true);
}


private void checkNotNative(String mdx) {
NonEmptyTest.checkNotNative(mdx, getResult(removeNativize(mdx)));
}
Expand Down

0 comments on commit 6aa4385

Please sign in to comment.