Search in sources :

Example 36 with Member

use of mondrian.olap.Member in project mondrian by pentaho.

the class RolapAxisTest method toString.

protected String toString(List<Member> position) {
    StringBuffer buf = new StringBuffer(100);
    buf.append('{');
    boolean firstTimeInner = true;
    for (Member m : position) {
        if (!firstTimeInner) {
            buf.append(',');
        }
        buf.append(m);
        firstTimeInner = false;
    }
    buf.append('}');
    return buf.toString();
}
Also used : TestMember(mondrian.olap.fun.TestMember) Member(mondrian.olap.Member)

Example 37 with Member

use of mondrian.olap.Member in project mondrian by pentaho.

the class ExistingFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final IterCalc setArg = compiler.compileIter(call.getArg(0));
    final Type myType = call.getArg(0).getType();
    return new AbstractListCalc(call, new Calc[] { setArg }) {

        public boolean dependsOn(Hierarchy hierarchy) {
            return myType.usesHierarchy(hierarchy, false);
        }

        public TupleList evaluateList(Evaluator evaluator) {
            TupleIterable setTuples = setArg.evaluateIterable(evaluator);
            TupleList result = TupleCollections.createList(setTuples.getArity());
            List<Member> contextMembers = Arrays.asList(evaluator.getMembers());
            List<Hierarchy> argDims = null;
            List<Hierarchy> contextDims = getHierarchies(contextMembers);
            for (List<Member> tuple : setTuples) {
                if (argDims == null) {
                    argDims = getHierarchies(tuple);
                }
                if (existsInTuple(tuple, contextMembers, argDims, contextDims, evaluator)) {
                    result.add(tuple);
                }
            }
            return result;
        }
    };
}
Also used : TupleList(mondrian.calc.TupleList) Hierarchy(mondrian.olap.Hierarchy) Type(mondrian.olap.type.Type) TupleIterable(mondrian.calc.TupleIterable) IterCalc(mondrian.calc.IterCalc) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) Evaluator(mondrian.olap.Evaluator) Member(mondrian.olap.Member)

Example 38 with Member

use of mondrian.olap.Member 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 39 with Member

use of mondrian.olap.Member in project mondrian by pentaho.

the class BatchTestCase method getMeasure.

protected RolapStar.Measure getMeasure(String cube, String measureName) {
    final Connection connection = getFoodMartConnection();
    final boolean fail = true;
    Cube salesCube = connection.getSchema().lookupCube(cube, fail);
    Member measure = salesCube.getSchemaReader(null).getMemberByUniqueName(Util.parseIdentifier(measureName), fail);
    return RolapStar.getStarMeasure(measure);
}
Also used : Cube(mondrian.olap.Cube) Connection(mondrian.olap.Connection) Member(mondrian.olap.Member)

Example 40 with Member

use of mondrian.olap.Member in project pentaho-kettle by pentaho.

the class MondrianHelper method outputFlattenedRecurse.

private static void outputFlattenedRecurse(Result result, List<List<Object>> rows, List<Object> rowValues, int[] coords, int axisOrdinal) {
    final Axis[] axes = result.getAxes();
    if (axisOrdinal == axes.length) {
        final Cell cell = result.getCell(coords);
        // Output the raw (unformatted) value of the cell.
        // NOTE: We could output other properties of the cell here, such as its
        // formatted value, too.
        rowValues.add(cell.getValue());
        // Add a copy of the completed row to the list of rows.
        rows.add(new ArrayList<>(rowValues));
    } else {
        final Axis axis = axes[axisOrdinal];
        int k = -1;
        int saveLength = rowValues.size();
        for (Position position : axis.getPositions()) {
            coords[axisOrdinal] = ++k;
            for (Member member : position) {
                rowValues.add(member.getUniqueName());
            }
            outputFlattenedRecurse(result, rows, rowValues, coords, axisOrdinal + 1);
            while (rowValues.size() > saveLength) {
                rowValues.remove(rowValues.size() - 1);
            }
        }
    }
}
Also used : Position(mondrian.olap.Position) Cell(mondrian.olap.Cell) Member(mondrian.olap.Member) Axis(mondrian.olap.Axis)

Aggregations

Member (mondrian.olap.Member)60 ArrayList (java.util.ArrayList)20 TestMember (mondrian.olap.fun.TestMember)20 List (java.util.List)15 LimitedRollupMember (mondrian.rolap.RolapHierarchy.LimitedRollupMember)13 Evaluator (mondrian.olap.Evaluator)11 MultiCardinalityDefaultMember (mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember)11 SetEvaluator (mondrian.olap.Evaluator.SetEvaluator)8 Hierarchy (mondrian.olap.Hierarchy)8 TupleList (mondrian.calc.TupleList)7 Axis (mondrian.olap.Axis)7 Exp (mondrian.olap.Exp)7 Level (mondrian.olap.Level)7 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 HashSet (java.util.HashSet)5 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)5 MemberExpr (mondrian.mdx.MemberExpr)5 LinkedHashSet (java.util.LinkedHashSet)4 ResolvedFunCall (mondrian.mdx.ResolvedFunCall)4