use of mondrian.olap.Evaluator in project mondrian by pentaho.
the class NonEmptyTest method testNonEmptyDescendants.
/**
* Ensures that NON EMPTY Descendants is optimized.
* Ensures that Descendants as a side effect collects MemberChildren that
* may be looked up in the cache.
*/
public void testNonEmptyDescendants() {
// 'level.getMembers()' which create false negatives in this test.
if (MondrianProperties.instance().TestExpDependencies.get() > 0) {
return;
}
Connection con = getTestContext().withSchemaPool(false).getConnection();
SmartMemberReader smr = getSmartMemberReader(con, "Customers");
MemberCacheHelper smrch = smr.cacheHelper;
clearAndHardenCache(smrch);
SmartMemberReader ssmr = getSmartMemberReader(con, "Customers");
MemberCacheHelper ssmrch = ssmr.cacheHelper;
clearAndHardenCache(ssmrch);
TestCase c = new TestCase(con, 45, 21, "select \n" + "{[Measures].[Unit Sales]} ON columns, " + "NON EMPTY {[Customers].[All Customers], Descendants([Customers].[All Customers].[USA].[CA], [Customers].[Name])} on rows " + "from [Sales] " + "where ([Store].[All Stores].[USA].[CA].[San Francisco].[Store 14], [Time].[1997].[Q1].[1])");
Result result = c.run();
// [Customers].[All Customers].[USA].[CA].[Burlingame].[Peggy Justice]
RolapMember peggy = (RolapMember) result.getAxes()[1].getPositions().get(1).get(0);
RolapMember burlingame = peggy.getParentMember();
peggy = ((RolapCubeMember) peggy).getRolapMember();
burlingame = ((RolapCubeMember) burlingame).getRolapMember();
// all children of burlingame are not in cache
MemberChildrenConstraint mcc = scf.getMemberChildrenConstraint(null);
assertNull(ssmrch.mapMemberToChildren.get(burlingame, mcc));
// but non empty children is
Evaluator evaluator = getEvaluator(result, new int[] { 0, 0 });
evaluator.setNonEmpty(true);
mcc = scf.getMemberChildrenConstraint(evaluator);
List<RolapMember> list = ssmrch.mapMemberToChildren.get(burlingame, mcc);
assertNotNull(list);
assertTrue(list.contains(peggy));
// now we run the same query again, this time everything must come out
// of the cache
RolapNativeRegistry reg = getRegistry(con);
reg.setListener(new Listener() {
public void foundEvaluator(NativeEvent e) {
}
public void foundInCache(TupleEvent e) {
}
public void executingSql(TupleEvent e) {
fail("expected caching");
}
});
try {
c.run();
} finally {
reg.setListener(null);
}
}
use of mondrian.olap.Evaluator in project mondrian by pentaho.
the class ExistingFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final IterCalc setArg = compiler.compileIter(call.getArg(0));
final Type myType = call.getArg(0).getType();
return new AbstractListCalc(call, new Calc[] { setArg }) {
public boolean dependsOn(Hierarchy hierarchy) {
return myType.usesHierarchy(hierarchy, false);
}
public TupleList evaluateList(Evaluator evaluator) {
TupleIterable setTuples = setArg.evaluateIterable(evaluator);
TupleList result = TupleCollections.createList(setTuples.getArity());
List<Member> contextMembers = Arrays.asList(evaluator.getMembers());
List<Hierarchy> argDims = null;
List<Hierarchy> contextDims = getHierarchies(contextMembers);
for (List<Member> tuple : setTuples) {
if (argDims == null) {
argDims = getHierarchies(tuple);
}
if (existsInTuple(tuple, contextMembers, argDims, contextDims, evaluator)) {
result.add(tuple);
}
}
return result;
}
};
}
use of mondrian.olap.Evaluator in project mondrian by pentaho.
the class HeadTailFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final ListCalc listCalc = compiler.compileList(call.getArg(0));
final IntegerCalc integerCalc = call.getArgCount() > 1 ? compiler.compileInteger(call.getArg(1)) : ConstantCalc.constantInteger(1);
if (head) {
return new AbstractListCalc(call, new Calc[] { listCalc, integerCalc }) {
public TupleList evaluateList(Evaluator evaluator) {
final int savepoint = evaluator.savepoint();
try {
evaluator.setNonEmpty(false);
TupleList list = listCalc.evaluateList(evaluator);
int count = integerCalc.evaluateInteger(evaluator);
return head(count, list);
} finally {
evaluator.restore(savepoint);
}
}
};
} else {
return new AbstractListCalc(call, new Calc[] { listCalc, integerCalc }) {
public TupleList evaluateList(Evaluator evaluator) {
final int savepoint = evaluator.savepoint();
try {
evaluator.setNonEmpty(false);
TupleList list = listCalc.evaluateList(evaluator);
int count = integerCalc.evaluateInteger(evaluator);
return tail(count, list);
} finally {
evaluator.restore(savepoint);
}
}
};
}
}
use of mondrian.olap.Evaluator in project mondrian by pentaho.
the class HierarchizeFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final ListCalc listCalc = compiler.compileList(call.getArg(0), true);
String order = getLiteralArg(call, 1, "PRE", prePost);
final boolean post = order.equals("POST");
return new AbstractListCalc(call, new Calc[] { listCalc }) {
public TupleList evaluateList(Evaluator evaluator) {
TupleList list = listCalc.evaluateList(evaluator);
return hierarchizeTupleList(list, post);
}
};
}
use of mondrian.olap.Evaluator in project mondrian by pentaho.
the class TupleToStrFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
if (TypeUtil.couldBeMember(call.getArg(0).getType())) {
final MemberCalc memberCalc = compiler.compileMember(call.getArg(0));
return new AbstractStringCalc(call, new Calc[] { memberCalc }) {
public String evaluateString(Evaluator evaluator) {
final Member member = memberCalc.evaluateMember(evaluator);
if (member.isNull()) {
return "";
}
StringBuilder buf = new StringBuilder();
buf.append(member.getUniqueName());
return buf.toString();
}
};
} else {
final TupleCalc tupleCalc = compiler.compileTuple(call.getArg(0));
return new AbstractStringCalc(call, new Calc[] { tupleCalc }) {
public String evaluateString(Evaluator evaluator) {
final Member[] members = tupleCalc.evaluateTuple(evaluator);
if (members == null) {
return "";
}
StringBuilder buf = new StringBuilder();
SetToStrFunDef.appendTuple(buf, members);
return buf.toString();
}
};
}
}
Aggregations