use of mondrian.olap.type.LevelType in project mondrian by pentaho.
the class AbstractExpCompiler method compileHierarchy.
public HierarchyCalc compileHierarchy(Exp exp) {
final Type type = exp.getType();
if (type instanceof DimensionType) {
// <Dimension> --> unique Hierarchy else error
// Resolve at compile time if constant
final Dimension dimension = type.getDimension();
if (dimension != null) {
final Hierarchy hierarchy = FunUtil.getDimensionDefaultHierarchy(dimension);
if (hierarchy != null) {
return (HierarchyCalc) ConstantCalc.constantHierarchy(hierarchy);
} else {
// cell) but we prefer to give an error at validate time.
throw MondrianResource.instance().CannotImplicitlyConvertDimensionToHierarchy.ex(dimension.getName());
}
}
final DimensionCalc dimensionCalc = compileDimension(exp);
return new DimensionHierarchyCalc(new DummyExp(HierarchyType.forType(type)), dimensionCalc);
}
if (type instanceof MemberType) {
// <Member> --> <Member>.Hierarchy
final MemberCalc memberCalc = compileMember(exp);
return new MemberHierarchyFunDef.CalcImpl(new DummyExp(HierarchyType.forType(type)), memberCalc);
}
if (type instanceof LevelType) {
// <Level> --> <Level>.Hierarchy
final LevelCalc levelCalc = compileLevel(exp);
return new LevelHierarchyFunDef.CalcImpl(new DummyExp(HierarchyType.forType(type)), levelCalc);
}
assert type instanceof HierarchyType;
return (HierarchyCalc) compile(exp);
}
use of mondrian.olap.type.LevelType in project mondrian by pentaho.
the class AncestorFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final MemberCalc memberCalc = compiler.compileMember(call.getArg(0));
final Type type1 = call.getArg(1).getType();
if (type1 instanceof LevelType) {
final LevelCalc levelCalc = compiler.compileLevel(call.getArg(1));
return new AbstractMemberCalc(call, new Calc[] { memberCalc, levelCalc }) {
public Member evaluateMember(Evaluator evaluator) {
Level level = levelCalc.evaluateLevel(evaluator);
Member member = memberCalc.evaluateMember(evaluator);
int distance = member.getLevel().getDepth() - level.getDepth();
return ancestor(evaluator, member, distance, level);
}
};
} else {
final IntegerCalc distanceCalc = compiler.compileInteger(call.getArg(1));
return new AbstractMemberCalc(call, new Calc[] { memberCalc, distanceCalc }) {
public Member evaluateMember(Evaluator evaluator) {
int distance = distanceCalc.evaluateInteger(evaluator);
Member member = memberCalc.evaluateMember(evaluator);
return ancestor(evaluator, member, distance, null);
}
};
}
}
use of mondrian.olap.type.LevelType in project mondrian by pentaho.
the class AncestorsFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final MemberCalc memberCalc = compiler.compileMember(call.getArg(0));
final Type type1 = call.getArg(1).getType();
if (type1 instanceof LevelType) {
final LevelCalc levelCalc = compiler.compileLevel(call.getArg(1));
return new AbstractListCalc(call, new Calc[] { memberCalc, levelCalc }) {
public TupleList evaluateList(Evaluator evaluator) {
Level level = levelCalc.evaluateLevel(evaluator);
Member member = memberCalc.evaluateMember(evaluator);
int distance = member.getDepth() - level.getDepth();
List<Member> ancestors = new ArrayList<Member>();
for (int curDist = 1; curDist <= distance; curDist++) {
ancestors.add(ancestor(evaluator, member, curDist, null));
}
return TupleCollections.asTupleList(ancestors);
}
};
} else {
final IntegerCalc distanceCalc = compiler.compileInteger(call.getArg(1));
return new AbstractListCalc(call, new Calc[] { memberCalc, distanceCalc }) {
public TupleList evaluateList(Evaluator evaluator) {
Member member = memberCalc.evaluateMember(evaluator);
int distance = distanceCalc.evaluateInteger(evaluator);
List<Member> ancestors = new ArrayList<Member>();
for (int curDist = 1; curDist <= distance; curDist++) {
ancestors.add(ancestor(evaluator, member, curDist, null));
}
return TupleCollections.asTupleList(ancestors);
}
};
}
}
Aggregations