KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > fun > NonEmptyCrossJoinFunDef


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/fun/NonEmptyCrossJoinFunDef.java#12 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2004-2005 SAS Institute, Inc.
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 //
10 // sasebb, 16 December, 2004
11 */

12 package mondrian.olap.fun;
13
14 import java.util.List JavaDoc;
15 import java.util.Collections JavaDoc;
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 /**
25  * Definition of the <code>NonEmptyCrossJoin</code> MDX function.
26  *
27  * @author jhyde
28  * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/NonEmptyCrossJoinFunDef.java#12 $
29  * @since Mar 23, 2006
30  */

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 JavaDoc[]{"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 JavaDoc 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 JavaDoc) nativeEvaluator.execute(ResultStyle.LIST);
55                 }
56
57                 final List JavaDoc list1 = listCalc1.evaluateList(evaluator);
58                 if (list1.isEmpty()) {
59                     return Collections.EMPTY_LIST;
60                 }
61                 final List JavaDoc list2 = listCalc2.evaluateList(evaluator);
62                 // evaluate the arguments in non empty mode
63
evaluator = evaluator.push();
64                 evaluator.setNonEmpty(true);
65                 List JavaDoc result = crossJoin(list1, list2, evaluator, call);
66
67                 // remove any remaining empty crossings from the result
68
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                 // Member calculations generate members, which mask the actual
77
// expression from the inherited context.
78
if (listCalc1.getType().usesDimension(dimension, true)) {
79                     return false;
80                 }
81                 if (listCalc2.getType().usesDimension(dimension, true)) {
82                     return false;
83                 }
84                 // The implicit value expression, executed to figure out
85
// whether a given tuple is empty, depends upon all dimensions.
86
return true;
87             }
88         };
89     }
90
91 }
92
93 // End NonEmptyCrossJoinFunDef.java
94
Popular Tags