use of mondrian.olap.fun.sort.SortKeySpec in project mondrian by pentaho.
the class OrderFunDef method buildKeySpecList.
private void buildKeySpecList(List<SortKeySpec> keySpecList, ResolvedFunCall call, ExpCompiler compiler) {
final int argCount = call.getArgs().length;
// args[0] is the input set
int j = 1;
Calc key;
Flag dir;
Exp arg;
while (j < argCount) {
arg = call.getArg(j);
key = compiler.compileScalar(arg, true);
j++;
if ((j >= argCount) || (call.getArg(j).getCategory() != Category.Symbol)) {
dir = Flag.ASC;
} else {
dir = getLiteralArg(call, j, Flag.ASC, Flag.class);
j++;
}
keySpecList.add(new SortKeySpec(key, dir));
}
}
use of mondrian.olap.fun.sort.SortKeySpec in project mondrian by pentaho.
the class OrderFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final IterCalc listCalc = compiler.compileIter(call.getArg(0));
List<SortKeySpec> keySpecList = new ArrayList<>();
buildKeySpecList(keySpecList, call, compiler);
final int keySpecCount = keySpecList.size();
// +1 for the listCalc
Calc[] calcList = new Calc[keySpecCount + 1];
calcList[0] = listCalc;
assert keySpecCount >= 1;
final Calc expCalc = keySpecList.get(0).getKey();
calcList[1] = expCalc;
if (keySpecCount == 1) {
if (expCalc.isWrapperFor(MemberValueCalc.class) || expCalc.isWrapperFor(MemberArrayValueCalc.class)) {
List<MemberCalc> constantList = new ArrayList<>();
List<MemberCalc> variableList = new ArrayList<>();
final MemberCalc[] calcs = (MemberCalc[]) ((AbstractCalc) expCalc).getCalcs();
for (MemberCalc memberCalc : calcs) {
if (memberCalc.isWrapperFor(ConstantCalc.class) && !listCalc.dependsOn(memberCalc.getType().getHierarchy())) {
constantList.add(memberCalc);
} else {
variableList.add(memberCalc);
}
}
if (constantList.isEmpty()) {
// All members are non-constant -- cannot optimize
} else if (variableList.isEmpty()) {
// All members are constant. Optimize by setting entire
// context first.
calcList[1] = new ValueCalc(new DummyExp(expCalc.getType()));
return new ContextCalc(calcs, new CalcImpl(call, calcList, keySpecList));
} else {
// Some members are constant. Evaluate these before
// evaluating the list expression.
calcList[1] = MemberValueCalc.create(new DummyExp(expCalc.getType()), variableList.toArray(new MemberCalc[variableList.size()]), compiler.getEvaluator().mightReturnNullForUnrelatedDimension());
return new ContextCalc(constantList.toArray(new MemberCalc[constantList.size()]), new CalcImpl(call, calcList, keySpecList));
}
}
}
for (int i = 1; i < keySpecCount; i++) {
final Calc expCalcs = keySpecList.get(i).getKey();
calcList[i + 1] = expCalcs;
}
return new CalcImpl(call, calcList, keySpecList);
}
Aggregations