1 10 package mondrian.calc.impl; 11 12 import mondrian.olap.*; 13 import mondrian.olap.fun.TupleFunDef; 14 import mondrian.olap.type.TupleType; 15 import mondrian.calc.impl.MemberValueCalc; 16 import mondrian.calc.*; 17 18 33 public class TupleValueCalc extends GenericCalc { 34 private final TupleCalc tupleCalc; 35 private final Member[] savedMembers; 36 37 public TupleValueCalc(Exp exp, TupleCalc tupleCalc) { 38 super(exp); 39 this.tupleCalc = tupleCalc; 40 final TupleType tupleType = (TupleType) this.tupleCalc.getType(); 41 this.savedMembers = new Member[tupleType.elementTypes.length]; 42 } 43 44 public Object evaluate(Evaluator evaluator) { 45 final Member[] members = tupleCalc.evaluateTuple(evaluator); 46 if (members == null) { 47 return null; 48 } 49 for (int i = 0; i < members.length; i++) { 50 savedMembers[i] = evaluator.setContext(members[i]); 51 } 52 final Object o = evaluator.evaluateCurrent(); 53 evaluator.setContext(savedMembers); 54 return o; 55 } 56 57 public Calc[] getCalcs() { 58 return new Calc[] {tupleCalc}; 59 } 60 61 73 public Calc optimize() { 74 if (tupleCalc instanceof TupleFunDef.CalcImpl) { 75 TupleFunDef.CalcImpl calc = (TupleFunDef.CalcImpl) tupleCalc; 76 return new MemberValueCalc( 77 new DummyExp(type), calc.getMemberCalcs()); 78 } 79 return this; 80 } 81 } 82 83 | Popular Tags |