Search in sources :

Example 26 with TupleList

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());
}
Also used : ArrayList(java.util.ArrayList) Calc(mondrian.calc.Calc) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) ArrayTupleList(mondrian.calc.impl.ArrayTupleList) FunDef(mondrian.olap.FunDef) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) ArrayTupleList(mondrian.calc.impl.ArrayTupleList) SetType(mondrian.olap.type.SetType) ResolvedFunCall(mondrian.mdx.ResolvedFunCall) Exp(mondrian.olap.Exp) Member(mondrian.olap.Member)

Example 27 with TupleList

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();
}
Also used : UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) Execution(mondrian.server.Execution)

Example 28 with TupleList

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));
}
Also used : TupleList(mondrian.calc.TupleList)

Example 29 with TupleList

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);
}
Also used : TupleList(mondrian.calc.TupleList)

Aggregations

TupleList (mondrian.calc.TupleList)29 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)21 ArrayTupleList (mondrian.calc.impl.ArrayTupleList)12 Axis (mondrian.olap.Axis)4 ArrayList (java.util.ArrayList)3 ListTupleList (mondrian.calc.impl.ListTupleList)3 Member (mondrian.olap.Member)3 Execution (mondrian.server.Execution)3 SQLException (java.sql.SQLException)2 List (java.util.List)2 TupleIterable (mondrian.calc.TupleIterable)2 DelegatingTupleList (mondrian.calc.impl.DelegatingTupleList)2 ResolvedFunCall (mondrian.mdx.ResolvedFunCall)2 Exp (mondrian.olap.Exp)2 TestMember (mondrian.olap.fun.TestMember)2 TupleConstraint (mondrian.rolap.sql.TupleConstraint)2 TraversalList (mondrian.util.TraversalList)2 ResultSet (java.sql.ResultSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1