use of mondrian.mdx.ResolvedFunCall in project mondrian by pentaho.
the class UnionFunDefTest method testMondrian2250.
/**
* Test for MONDRIAN-2250 issue.
* Tests that the result is independent on the hashCode.
* For this purpose MemberForTest with rewritten hashCode is used.
*
* Tuples are gotten from customer attachments.
*/
public void testMondrian2250() {
Member[] dates = new Member[4];
for (int i = 25; i < 29; i++) {
dates[i - 25] = new MemberForTest("[Consumption Date.Calendar].[2014-07-" + i + "]");
}
List<Member> list = Arrays.asList(dates);
UnaryTupleList unaryTupleList = new UnaryTupleList(list);
Member consumptionMethod = new MemberForTest("[Consumption Method].[PVR]");
Member measuresAverageTimeshift = new MemberForTest("[Measures].[Average Timeshift]");
String[] hours = { "00", "14", "15", "16", "23" };
Member[] times = new Member[5];
for (int i = 0; i < hours.length; i++) {
times[i] = new MemberForTest("[Consumption Time.Time].[" + hours[i] + ":00]");
}
int arity = 3;
ArrayTupleList arrayTupleList = new ArrayTupleList(arity);
for (Member time : times) {
List<Member> currentList = new ArrayList(3);
currentList.add(consumptionMethod);
currentList.add(measuresAverageTimeshift);
currentList.add(time);
arrayTupleList.add(currentList);
}
CrossJoinFunDef crossJoinFunDef = new CrossJoinFunDef(new CrossJoinTest.NullFunDef());
Exp[] expMock = new Exp[1];
expMock[0] = mock(Exp.class);
ResolvedFunCall resolvedFunCall = new ResolvedFunCall(mock(FunDef.class), expMock, mock(SetType.class));
Calc[] calcs = new Calc[1];
calcs[0] = Mockito.mock(Calc.class);
CrossJoinFunDef.ImmutableListCalc immutableListCalc = crossJoinFunDef.new ImmutableListCalc(resolvedFunCall, calcs);
TupleList listForUnion1 = immutableListCalc.makeList(unaryTupleList, arrayTupleList);
List<Member> list2 = Arrays.asList(dates);
UnaryTupleList unaryTupleList2 = new UnaryTupleList(list2);
Member measuresTotalViewingTime = new MemberForTest("[Measures].[Total Viewing Time]");
ArrayTupleList arrayTupleList2 = new ArrayTupleList(arity);
for (Member time : times) {
List<Member> currentList = new ArrayList(3);
currentList.add(consumptionMethod);
currentList.add(measuresTotalViewingTime);
currentList.add(time);
arrayTupleList2.add(currentList);
}
TupleList listForUnion2 = immutableListCalc.makeList(unaryTupleList2, arrayTupleList2);
UnionFunDef unionFunDefMock = Mockito.mock(UnionFunDef.class);
doCallRealMethod().when(unionFunDefMock).union(any(TupleList.class), any(TupleList.class), anyBoolean());
TupleList tupleList = unionFunDefMock.union(listForUnion1, listForUnion2, false);
System.out.println(tupleList);
assertEquals(40, tupleList.size());
}
use of mondrian.mdx.ResolvedFunCall in project mondrian by pentaho.
the class CompoundPredicateInfo method makeCalculatedMemberPredicate.
private StarPredicate makeCalculatedMemberPredicate(RolapCubeMember member, RolapCube baseCube, Evaluator evaluator) {
assert member.getExpression() instanceof ResolvedFunCall;
ResolvedFunCall fun = (ResolvedFunCall) member.getExpression();
final Exp exp = fun.getArg(0);
final Type type = exp.getType();
if (type instanceof SetType) {
return makeSetPredicate(exp, evaluator);
} else if (type.getArity() == 1) {
return makeUnaryPredicate(member, baseCube, evaluator);
} else {
throw MondrianResource.instance().UnsupportedCalculatedMember.ex(member.getName(), null);
}
}
use of mondrian.mdx.ResolvedFunCall in project mondrian by pentaho.
the class SqlContextConstraint method findMeasures.
/**
* Extracts the stored measures referenced in an expression
*
* @param exp expression
* @param baseCubes set of base cubes
*/
private static void findMeasures(Exp exp, Set<RolapCube> baseCubes, List<RolapCube> baseCubeList) {
if (exp instanceof MemberExpr) {
MemberExpr memberExpr = (MemberExpr) exp;
Member member = memberExpr.getMember();
if (member instanceof RolapStoredMeasure) {
addMeasure((RolapStoredMeasure) member, baseCubes, baseCubeList);
} else if (member instanceof RolapCalculatedMember) {
findMeasures(member.getExpression(), baseCubes, baseCubeList);
}
} else if (exp instanceof ResolvedFunCall) {
ResolvedFunCall funCall = (ResolvedFunCall) exp;
Exp[] args = funCall.getArgs();
for (Exp arg : args) {
findMeasures(arg, baseCubes, baseCubeList);
}
}
}
use of mondrian.mdx.ResolvedFunCall in project mondrian by pentaho.
the class AbstractCalc method getName.
/**
* Returns the name of this expression type, used when serializing an
* expression to a string.
*
* <p>The default implementation tries to extract a name from a function
* call, if any, then prints the last part of the class name.
*/
protected String getName() {
String name = lastSegment(getClass());
if (isDigits(name) && exp instanceof ResolvedFunCall) {
ResolvedFunCall funCall = (ResolvedFunCall) exp;
name = funCall.getFunDef().getName();
}
return name;
}
Aggregations