1 11 package mondrian.rolap; 12 13 import java.sql.Connection ; 14 import java.sql.SQLException ; 15 import java.util.ArrayList ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 import javax.sql.DataSource ; 20 21 import mondrian.olap.*; 22 import mondrian.rolap.sql.SqlQuery; 23 import mondrian.rolap.sql.TupleConstraint; 24 25 32 public class RolapNativeFilter extends RolapNativeSet { 33 34 public RolapNativeFilter() { 35 super.setEnabled(MondrianProperties.instance().EnableNativeFilter.get()); 36 } 37 38 class FilterConstraint extends SetConstraint { 39 String filterExpr; 40 41 public FilterConstraint(CrossJoinArg[] args, RolapEvaluator evaluator, String filterByExpr) { 42 super(args, evaluator, true); 43 this.filterExpr = filterByExpr; 44 } 45 46 50 protected boolean isJoinRequired() { 51 return true; 52 } 53 54 public void addConstraint( 55 SqlQuery sqlQuery, 56 Map <RolapLevel, RolapStar.Column> levelToColumnMap) { 57 sqlQuery.addHaving(filterExpr); 58 super.addConstraint(sqlQuery, levelToColumnMap); 59 } 60 61 public Object getCacheKey() { 62 List <Object > key = new ArrayList <Object >(); 63 key.add(super.getCacheKey()); 64 key.add(filterExpr); 65 return key; 66 } 67 } 68 69 protected boolean isStrict() { 70 return true; 71 } 72 73 NativeEvaluator createEvaluator(RolapEvaluator evaluator, FunDef fun, Exp[] args) { 74 if (!isEnabled()) { 75 return null; 76 } 77 if (!FilterConstraint.isValidContext(evaluator)) { 78 return null; 79 } 80 String funName = fun.getName(); 82 if (!"Filter".equalsIgnoreCase(funName)) { 83 return null; 84 } 85 86 if (args.length != 2) { 87 return null; 88 } 89 90 CrossJoinArg[] cargs = checkCrossJoinArg(args[0]); 92 if (cargs == null) { 93 return null; 94 } 95 if (isPreferInterpreter(cargs)) { 96 return null; 97 } 98 99 SchemaReader schemaReader = evaluator.getSchemaReader(); 101 DataSource ds = schemaReader.getDataSource(); 102 103 SqlQuery sqlQuery = SqlQuery.newQuery(ds, "NativeFilter"); 105 RolapNativeSql sql = new RolapNativeSql(sqlQuery); 106 String filterExpr = sql.generateFilterCondition(args[1]); 107 if (filterExpr == null) { 108 return null; 109 } 110 LOGGER.debug("using native filter"); 111 112 evaluator = overrideContext(evaluator, cargs, sql.getStoredMeasure()); 113 114 TupleConstraint constraint = new FilterConstraint(cargs, evaluator, filterExpr); 115 return new SetEvaluator(cargs, schemaReader, constraint); 116 } 117 118 } 119 120 | Popular Tags |