use of mondrian.calc.impl.ArrayTupleList in project mondrian by pentaho.
the class SqlTupleReader method projectTupleList.
/**
* Projects the attributes using the original ordering in targets, then
* copies to a ArrayTupleList (the .project method returns a basic TupleList
* without support for methods like .remove, which may be needed downstream).
*/
private TupleList projectTupleList(TupleList tupleList) {
tupleList = tupleList.project(getLevelIndices(tupleList, targets));
TupleList arrayTupleList = new ArrayTupleList(tupleList.getArity(), tupleList.size());
arrayTupleList.addAll(tupleList);
return arrayTupleList;
}
use of mondrian.calc.impl.ArrayTupleList in project mondrian by pentaho.
the class AggregationOnDistinctCountMeasuresTest method testTupleOptimizationBug1225.
/**
* This is a test for
* <a href="http://jira.pentaho.com/browse/MONDRIAN-1125">MONDRIAN-1225</a>
*
* <p>The optimization routine for tuple lists was implementing a single
* side of an IF conditional, which resulted in an NPE.
*/
public void testTupleOptimizationBug1225() {
Member caMember = member(Id.Segment.toList("Store", "All Stores", "USA", "CA"), salesCubeSchemaReader);
Member orMember = member(Id.Segment.toList("Store", "All Stores", "USA", "OR"), salesCubeSchemaReader);
Member waMember = member(Id.Segment.toList("Store", "All Stores", "USA", "WA"), salesCubeSchemaReader);
Member femaleMember = member(Id.Segment.toList("Gender", "All Gender", "F"), salesCubeSchemaReader);
Member[] tupleMembersArity1 = new Member[] { caMember, allMember("Gender", salesCube) };
Member[] tupleMembersArity2 = new Member[] { orMember, allMember("Gender", salesCube) };
Member[] tupleMembersArity3 = new Member[] { waMember, femaleMember };
TupleList tl = new ArrayTupleList(2);
tl.add(Arrays.asList(tupleMembersArity1));
tl.add(Arrays.asList(tupleMembersArity2));
tl.add(Arrays.asList(tupleMembersArity3));
TupleList optimized = optimizeChildren(tl);
assertEquals("[[[Store].[USA], [Gender].[All Gender]], [[Store].[USA], [Gender].[F]]]", optimized.toString());
}
use of mondrian.calc.impl.ArrayTupleList in project mondrian by pentaho.
the class ExceptFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
// todo: implement ALL
final ListCalc listCalc0 = compiler.compileList(call.getArg(0));
final ListCalc listCalc1 = compiler.compileList(call.getArg(1));
return new AbstractListCalc(call, new Calc[] { listCalc0, listCalc1 }) {
public TupleList evaluateList(Evaluator evaluator) {
TupleList list0 = listCalc0.evaluateList(evaluator);
if (list0.isEmpty()) {
return list0;
}
TupleList list1 = listCalc1.evaluateList(evaluator);
if (list1.isEmpty()) {
return list0;
}
final Set<List<Member>> set1 = new HashSet<List<Member>>(list1);
final TupleList result = new ArrayTupleList(list0.getArity(), list0.size());
for (List<Member> tuple1 : list0) {
if (!set1.contains(tuple1)) {
result.add(tuple1);
}
}
return result;
}
};
}
use of mondrian.calc.impl.ArrayTupleList 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());
}
Aggregations