use of mondrian.calc.TupleList 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.calc.TupleList in project mondrian by pentaho.
the class CancellationTest method testMutableCrossJoinCancellation.
public void testMutableCrossJoinCancellation() throws MondrianException {
// tests that cancellation/timeout is checked in
// CrossJoinFunDef.mutableCrossJoin
propSaver.set(propSaver.properties.CheckCancelOrTimeoutInterval, 1);
RolapCube salesCube = (RolapCube) cubeByName(getTestContext().getConnection(), "Sales");
SchemaReader salesCubeSchemaReader = salesCube.getSchemaReader(getTestContext().getConnection().getRole()).withLocus();
TupleList productMembers = productMembersPotScrubbersPotsAndPans(salesCubeSchemaReader);
String selectGenders = "select Gender.members on 0 from sales";
Result genders = executeQuery(selectGenders);
Evaluator gendersEval = ((RolapResult) genders).getEvaluator(new int[] { 0 });
TupleList genderMembers = new UnaryTupleList();
for (Position pos : genders.getAxes()[0].getPositions()) {
genderMembers.add(pos);
}
Execution execution = spy(new Execution(genders.getQuery().getStatement(), 0));
TupleList mutableCrossJoinResult = mutableCrossJoin(productMembers, genderMembers, execution);
gendersEval.getQuery().getStatement().start(execution);
// checkCancelOrTimeout should be called once
// for each tuple from mutableCrossJoin since phase interval is 1
// plus once for each productMembers item
// since it gets through SqlStatement.execute
int expectedCallsQuantity = mutableCrossJoinResult.size() + productMembers.size();
verify(execution, times(expectedCallsQuantity)).checkCancelOrTimeout();
}
use of mondrian.calc.TupleList in project mondrian by pentaho.
the class SqlMemberSource method getMembersInLevel.
public List<RolapMember> getMembersInLevel(RolapLevel level, TupleConstraint constraint) {
if (level.isAll()) {
return Collections.singletonList(hierarchy.getAllMember());
}
Dimension dimension = level.getDimension();
boolean isHighCardinality = dimension.isHighCardinality();
final TupleReader tupleReader = isHighCardinality ? new HighCardSqlTupleReader(constraint) : new SqlTupleReader(constraint);
if (isHighCardinality) {
LOGGER.warn(MondrianResource.instance().HighCardinalityInDimension.str(dimension.getUniqueName()));
}
tupleReader.addLevelMembers(level, this, null);
final TupleList tupleList = tupleReader.readMembers(dataSource, null, null);
assert tupleList.getArity() == 1;
return Util.cast(tupleList.slice(0));
}
use of mondrian.calc.TupleList in project mondrian by pentaho.
the class TupleListTest method testArrayTupleList.
public void testArrayTupleList() {
final Member genderFMember = xxx("[Gender].[F]");
final Member genderMMember = xxx("[Gender].[M]");
// empty list
final TupleList list0 = new ArrayTupleList(2);
assertTrue(list0.isEmpty());
assertEquals(0, list0.size());
assertEquals(list0, TupleCollections.emptyList(2));
TupleList list1 = new ArrayTupleList(2);
assertEquals(list0, list1);
final Member storeUsaMember = xxx("[Store].[USA]");
list1.add(Arrays.asList(storeUsaMember, genderFMember));
assertFalse(list1.isEmpty());
assertEquals(1, list1.size());
assertNotSame(list0, list1);
try {
list1.add(Arrays.asList(storeUsaMember));
fail("expected error");
} catch (IllegalArgumentException e) {
assertEquals("Tuple length does not match arity", e.getMessage());
}
try {
list1.addTuple(new Member[] { storeUsaMember });
fail("expected error");
} catch (IllegalArgumentException e) {
assertEquals("Tuple length does not match arity", e.getMessage());
}
try {
list1.add(Arrays.asList(storeUsaMember, genderFMember, genderFMember));
fail("expected error");
} catch (IllegalArgumentException e) {
assertEquals("Tuple length does not match arity", e.getMessage());
}
try {
list1.addTuple(new Member[] { storeUsaMember, genderFMember, genderFMember });
fail("expected error");
} catch (IllegalArgumentException e) {
assertEquals("Tuple length does not match arity", e.getMessage());
}
TupleList list2 = new ArrayTupleList(2);
list2.addTuple(new Member[] { storeUsaMember, genderFMember });
assertFalse(list2.isEmpty());
assertEquals(1, list2.size());
assertEquals(list1, list2);
list2.clear();
assertEquals(list0, list2);
assertEquals(list2, list0);
assertEquals("[]", list0.toString());
assertEquals("[[[Store].[USA], [Gender].[F]]]", list1.toString());
assertEquals("[]", list2.toString());
// For various lists, sublist returns the whole thing.
for (TupleList list : Arrays.asList(list0, list1, list2)) {
final TupleList sublist = list.subList(0, list.size());
assertNotNull(sublist);
assertNotNull(sublist.toString());
assertEquals(sublist.isEmpty(), list.isEmpty());
assertEquals(list, sublist);
assertNotSame(list, sublist);
}
// Null members OK (at least for TupleList).
list1.addTuple(storeUsaMember, null);
list1.add(Arrays.asList(storeUsaMember, null));
TupleList fm = new ArrayTupleList(2);
fm.addTuple(genderFMember, storeUsaMember);
fm.addTuple(genderMMember, storeUsaMember);
checkProject(fm);
}
Aggregations