use of mondrian.calc.ListCalc in project mondrian by pentaho.
the class TopBottomPercentSumFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final ListCalc listCalc = compiler.compileList(call.getArg(0), true);
final DoubleCalc doubleCalc = compiler.compileDouble(call.getArg(1));
final Calc calc = compiler.compileScalar(call.getArg(2), true);
return new CalcImpl(call, listCalc, doubleCalc, calc);
}
use of mondrian.calc.ListCalc 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 Sorter.hierarchizeTupleList(list, post);
}
};
}
use of mondrian.calc.ListCalc in project mondrian by pentaho.
the class DrilldownLevelTopBottomFunDef method compileCall.
public Calc compileCall(final ResolvedFunCall call, ExpCompiler compiler) {
// Compile the member list expression. Ask for a mutable list, because
// we're going to insert members into it later.
final ListCalc listCalc = compiler.compileList(call.getArg(0), true);
final IntegerCalc integerCalc = compiler.compileInteger(call.getArg(1));
final LevelCalc levelCalc = call.getArgCount() > 2 && call.getArg(2).getCategory() != Category.Empty ? compiler.compileLevel(call.getArg(2)) : null;
final Calc orderCalc = call.getArgCount() > 3 ? compiler.compileScalar(call.getArg(3), true) : new ValueCalc(new DummyExp(new ScalarType()));
return new AbstractListCalc(call, new Calc[] { listCalc, integerCalc, orderCalc }) {
public TupleList evaluateList(Evaluator evaluator) {
// Use a native evaluator, if more efficient.
// TODO: Figure this out at compile time.
SchemaReader schemaReader = evaluator.getSchemaReader();
NativeEvaluator nativeEvaluator = schemaReader.getNativeSetEvaluator(call.getFunDef(), call.getArgs(), evaluator, this);
if (nativeEvaluator != null) {
return (TupleList) nativeEvaluator.execute(ResultStyle.LIST);
}
TupleList list = listCalc.evaluateList(evaluator);
int n = integerCalc.evaluateInteger(evaluator);
if (n == FunUtil.IntegerNull || n <= 0) {
return list;
}
Level level;
if (levelCalc == null) {
level = null;
} else {
level = levelCalc.evaluateLevel(evaluator);
}
List<Member> result = new ArrayList<Member>();
assert list.getArity() == 1;
for (Member member : list.slice(0)) {
result.add(member);
if (level != null && member.getLevel() != level) {
if (level.getDimension() != member.getDimension()) {
throw newEvalException(DrilldownLevelTopBottomFunDef.this, "Level '" + level.getUniqueName() + "' not compatible with member '" + member.getUniqueName() + "'");
}
continue;
}
List<Member> children = schemaReader.getMemberChildren(member);
final int savepoint = evaluator.savepoint();
List<Member> sortedChildren;
try {
evaluator.setNonEmpty(false);
sortedChildren = Sorter.sortMembers(evaluator, children, children, orderCalc, top, true);
} finally {
evaluator.restore(savepoint);
}
int x = Math.min(n, sortedChildren.size());
for (int i = 0; i < x; i++) {
result.add(sortedChildren.get(i));
}
}
return new UnaryTupleList(result);
}
public boolean dependsOn(Hierarchy hierarchy) {
return anyDependsButFirst(getCalcs(), hierarchy);
}
};
}
Aggregations