1 12 package mondrian.olap.fun; 13 14 import java.util.List ; 15 import java.util.Collections ; 16 17 import mondrian.olap.*; 18 import mondrian.calc.ExpCompiler.ResultStyle; 19 import mondrian.calc.*; 20 import mondrian.calc.impl.AbstractListCalc; 21 import mondrian.mdx.ResolvedFunCall; 22 23 24 31 public class NonEmptyCrossJoinFunDef extends CrossJoinFunDef { 32 static final ReflectiveMultiResolver Resolver = new ReflectiveMultiResolver( 33 "NonEmptyCrossJoin", 34 "NonEmptyCrossJoin(<Set1>, <Set2>)", 35 "Returns the cross product of two sets, excluding empty tuples and tuples without associated fact table data.", 36 new String []{"fxxx"}, 37 NonEmptyCrossJoinFunDef.class); 38 39 public NonEmptyCrossJoinFunDef(FunDef dummyFunDef) { 40 super(dummyFunDef); 41 } 42 43 public Calc compileCall(final ResolvedFunCall call, ExpCompiler compiler) { 44 final ListCalc listCalc1 = compiler.compileList(call.getArg(0)); 45 final ListCalc listCalc2 = compiler.compileList(call.getArg(1)); 46 return new AbstractListCalc(call, new Calc[] {listCalc1, listCalc2}) { 47 public List evaluateList(Evaluator evaluator) { 48 SchemaReader schemaReader = evaluator.getSchemaReader(); 49 evaluator.setNonEmpty(true); 50 NativeEvaluator nativeEvaluator = 51 schemaReader.getNativeSetEvaluator( 52 call.getFunDef(), call.getArgs(), evaluator, this); 53 if (nativeEvaluator != null) { 54 return (List ) nativeEvaluator.execute(ResultStyle.LIST); 55 } 56 57 final List list1 = listCalc1.evaluateList(evaluator); 58 if (list1.isEmpty()) { 59 return Collections.EMPTY_LIST; 60 } 61 final List list2 = listCalc2.evaluateList(evaluator); 62 evaluator = evaluator.push(); 64 evaluator.setNonEmpty(true); 65 List result = crossJoin(list1, list2, evaluator, call); 66 67 result = nonEmptyList(evaluator, result, call); 69 return result; 70 } 71 72 public boolean dependsOn(Dimension dimension) { 73 if (super.dependsOn(dimension)) { 74 return true; 75 } 76 if (listCalc1.getType().usesDimension(dimension, true)) { 79 return false; 80 } 81 if (listCalc2.getType().usesDimension(dimension, true)) { 82 return false; 83 } 84 return true; 87 } 88 }; 89 } 90 91 } 92 93 | Popular Tags |