Search in sources :

Example 6 with UnaryTupleList

use of mondrian.calc.impl.UnaryTupleList in project mondrian by pentaho.

the class CancellationTest method testNonEmptyListCancellation.

public void testNonEmptyListCancellation() throws MondrianException {
    // tests that cancellation/timeout is checked in
    // CrossJoinFunDef.nonEmptyList
    propSaver.set(propSaver.properties.CheckCancelOrTimeoutInterval, 1);
    CrossJoinFunDefTester crossJoinFunDef = new CrossJoinFunDefTester(new CrossJoinTest.NullFunDef());
    Result result = executeQuery("select store.[store name].members on 0 from sales");
    Evaluator eval = ((RolapResult) result).getEvaluator(new int[] { 0 });
    TupleList list = new UnaryTupleList();
    for (Position pos : result.getAxes()[0].getPositions()) {
        list.add(pos);
    }
    Execution exec = spy(new Execution(eval.getQuery().getStatement(), 0));
    eval.getQuery().getStatement().start(exec);
    crossJoinFunDef.nonEmptyList(eval, list, null);
    // checkCancelOrTimeout should be called once
    // for each tuple since phase interval is 1
    verify(exec, times(list.size())).checkCancelOrTimeout();
}
Also used : UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) Execution(mondrian.server.Execution) CrossJoinTest(mondrian.olap.fun.CrossJoinTest)

Example 7 with UnaryTupleList

use of mondrian.calc.impl.UnaryTupleList in project mondrian by pentaho.

the class SqlConstraintUtilsTest method makeAggregateExprMember.

private Member makeAggregateExprMember(Evaluator mockEvaluator, List<Member> endMembers) {
    Member member = Mockito.mock(Member.class);
    Mockito.doReturn(true).when(member).isCalculated();
    Member aggregatedMember0 = Mockito.mock(Member.class);
    Exp aggregateArg0 = new MemberExpr(aggregatedMember0);
    FunDef dummy = Mockito.mock(FunDef.class);
    Mockito.doReturn(Syntax.Function).when(dummy).getSyntax();
    Mockito.doReturn("dummy").when(dummy).getName();
    FunDef funDef = new AggregateFunDef(dummy);
    Exp[] args = new Exp[] { aggregateArg0 };
    Type returnType = new DecimalType(1, 1);
    Exp memberExp = new ResolvedFunCall(funDef, args, returnType);
    Mockito.doReturn(memberExp).when(member).getExpression();
    SetEvaluator setEvaluator = Mockito.mock(SetEvaluator.class);
    Mockito.doReturn(setEvaluator).when(mockEvaluator).getSetEvaluator(aggregateArg0, true);
    Mockito.doReturn(new UnaryTupleList(endMembers)).when(setEvaluator).evaluateTupleIterable();
    Assert.assertEquals(true, member.isCalculated());
    Assert.assertEquals(true, SqlConstraintUtils.isSupportedCalculatedMember(member));
    return member;
}
Also used : SetEvaluator(mondrian.olap.Evaluator.SetEvaluator) FunDef(mondrian.olap.FunDef) ParenthesesFunDef(mondrian.olap.fun.ParenthesesFunDef) AggregateFunDef(mondrian.olap.fun.AggregateFunDef) NullFunDef(mondrian.olap.fun.CrossJoinTest.NullFunDef) NullType(mondrian.olap.type.NullType) DecimalType(mondrian.olap.type.DecimalType) TupleType(mondrian.olap.type.TupleType) Type(mondrian.olap.type.Type) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) MemberExpr(mondrian.mdx.MemberExpr) DecimalType(mondrian.olap.type.DecimalType) AggregateFunDef(mondrian.olap.fun.AggregateFunDef) ResolvedFunCall(mondrian.mdx.ResolvedFunCall) Exp(mondrian.olap.Exp) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember)

Example 8 with UnaryTupleList

use of mondrian.calc.impl.UnaryTupleList in project mondrian by pentaho.

the class DescendantsFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final Type type0 = call.getArg(0).getType();
    if (type0 instanceof SetType) {
        final SetType setType = (SetType) type0;
        if (setType.getElementType() instanceof TupleType) {
            throw MondrianResource.instance().DescendantsAppliedToSetOfTuples.ex();
        }
        MemberType memberType = (MemberType) setType.getElementType();
        final Hierarchy hierarchy = memberType.getHierarchy();
        if (hierarchy == null) {
            throw MondrianResource.instance().CannotDeduceTypeOfSet.ex();
        }
        // Convert
        // Descendants(<set>, <args>)
        // into
        // Generate(<set>, Descendants(<dimension>.CurrentMember, <args>))
        Exp[] descendantsArgs = call.getArgs().clone();
        descendantsArgs[0] = new UnresolvedFunCall("CurrentMember", Syntax.Property, new Exp[] { new HierarchyExpr(hierarchy) });
        final ResolvedFunCall generateCall = (ResolvedFunCall) compiler.getValidator().validate(new UnresolvedFunCall("Generate", new Exp[] { call.getArg(0), new UnresolvedFunCall("Descendants", descendantsArgs) }), false);
        return generateCall.accept(compiler);
    }
    final MemberCalc memberCalc = compiler.compileMember(call.getArg(0));
    Flag flag = Flag.SELF;
    if (call.getArgCount() == 1) {
        flag = Flag.SELF_BEFORE_AFTER;
    }
    final boolean depthSpecified = call.getArgCount() >= 2 && call.getArg(1).getType() instanceof NumericType;
    final boolean depthEmpty = call.getArgCount() >= 2 && call.getArg(1).getType() instanceof EmptyType;
    if (call.getArgCount() >= 3) {
        flag = FunUtil.getLiteralArg(call, 2, Flag.SELF, Flag.class);
    }
    if (call.getArgCount() >= 2 && depthEmpty) {
        if (flag != Flag.LEAVES) {
            throw Util.newError("depth must be specified unless DESC_FLAG is LEAVES");
        }
    }
    if ((depthSpecified || depthEmpty) && flag.leaves) {
        final IntegerCalc depthCalc = depthSpecified ? compiler.compileInteger(call.getArg(1)) : null;
        return new AbstractListCalc(call, new Calc[] { memberCalc, depthCalc }) {

            public TupleList evaluateList(Evaluator evaluator) {
                final Member member = memberCalc.evaluateMember(evaluator);
                List<Member> result = new ArrayList<Member>();
                int depth = -1;
                if (depthCalc != null) {
                    depth = depthCalc.evaluateInteger(evaluator);
                    if (depth < 0) {
                        // no limit
                        depth = -1;
                    }
                }
                final SchemaReader schemaReader = evaluator.getSchemaReader();
                descendantsLeavesByDepth(member, result, schemaReader, depth);
                hierarchizeMemberList(result, false);
                return new UnaryTupleList(result);
            }
        };
    } else if (depthSpecified) {
        final IntegerCalc depthCalc = compiler.compileInteger(call.getArg(1));
        final Flag flag1 = flag;
        return new AbstractListCalc(call, new Calc[] { memberCalc, depthCalc }) {

            public TupleList evaluateList(Evaluator evaluator) {
                final Member member = memberCalc.evaluateMember(evaluator);
                List<Member> result = new ArrayList<Member>();
                final int depth = depthCalc.evaluateInteger(evaluator);
                final SchemaReader schemaReader = evaluator.getSchemaReader();
                descendantsByDepth(member, result, schemaReader, depth, flag1.before, flag1.self, flag1.after, evaluator);
                hierarchizeMemberList(result, false);
                return new UnaryTupleList(result);
            }
        };
    } else {
        final LevelCalc levelCalc = call.getArgCount() > 1 ? compiler.compileLevel(call.getArg(1)) : null;
        final Flag flag2 = flag;
        return new AbstractListCalc(call, new Calc[] { memberCalc, levelCalc }) {

            public TupleList evaluateList(Evaluator evaluator) {
                final Evaluator context = evaluator.isNonEmpty() ? evaluator : null;
                final Member member = memberCalc.evaluateMember(evaluator);
                List<Member> result = new ArrayList<Member>();
                final SchemaReader schemaReader = evaluator.getSchemaReader();
                final Level level = levelCalc != null ? levelCalc.evaluateLevel(evaluator) : member.getLevel();
                descendantsByLevel(schemaReader, member, level, result, flag2.before, flag2.self, flag2.after, flag2.leaves, context);
                hierarchizeMemberList(result, false);
                return new UnaryTupleList(result);
            }
        };
    }
}
Also used : AbstractListCalc(mondrian.calc.impl.AbstractListCalc) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) UnaryTupleList(mondrian.calc.impl.UnaryTupleList)

Example 9 with UnaryTupleList

use of mondrian.calc.impl.UnaryTupleList in project mondrian by pentaho.

the class DrilldownLevelFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final ListCalc listCalc = compiler.compileList(call.getArg(0));
    final LevelCalc levelCalc = call.getArgCount() > 1 && call.getArg(1).getType() instanceof mondrian.olap.type.LevelType ? compiler.compileLevel(call.getArg(1)) : null;
    final IntegerCalc indexCalc = call.getArgCount() > 2 ? compiler.compileInteger(call.getArg(2)) : null;
    final int arity = listCalc.getType().getArity();
    if (indexCalc == null) {
        return new AbstractListCalc(call, new Calc[] { listCalc, levelCalc }) {

            public TupleList evaluateList(Evaluator evaluator) {
                TupleList list = listCalc.evaluateList(evaluator);
                if (list.size() == 0) {
                    return list;
                }
                int searchDepth = -1;
                if (levelCalc != null) {
                    Level level = levelCalc.evaluateLevel(evaluator);
                    searchDepth = level.getDepth();
                }
                return new UnaryTupleList(drill(searchDepth, list.slice(0), evaluator));
            }
        };
    } else {
        return new AbstractListCalc(call, new Calc[] { listCalc, indexCalc }) {

            public TupleList evaluateList(Evaluator evaluator) {
                TupleList list = listCalc.evaluateList(evaluator);
                if (list.isEmpty()) {
                    return list;
                }
                final int index = indexCalc.evaluateInteger(evaluator);
                if (index < 0 || index >= arity) {
                    return list;
                }
                TupleList result = TupleCollections.createList(arity);
                final SchemaReader schemaReader = evaluator.getSchemaReader();
                final Member[] tupleClone = new Member[arity];
                for (List<Member> tuple : list) {
                    result.add(tuple);
                    final List<Member> children = schemaReader.getMemberChildren(tuple.get(index));
                    for (Member child : children) {
                        tuple.toArray(tupleClone);
                        tupleClone[index] = child;
                        result.addTuple(tupleClone);
                    }
                }
                return result;
            }
        };
    }
}
Also used : AbstractListCalc(mondrian.calc.impl.AbstractListCalc) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) mondrian.olap(mondrian.olap)

Example 10 with UnaryTupleList

use of mondrian.calc.impl.UnaryTupleList 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)

Aggregations

UnaryTupleList (mondrian.calc.impl.UnaryTupleList)11 TupleList (mondrian.calc.TupleList)6 AbstractListCalc (mondrian.calc.impl.AbstractListCalc)4 ArrayTupleList (mondrian.calc.impl.ArrayTupleList)4 ResolvedFunCall (mondrian.mdx.ResolvedFunCall)2 Exp (mondrian.olap.Exp)2 FunDef (mondrian.olap.FunDef)2 Member (mondrian.olap.Member)2 RolapHierarchy (mondrian.rolap.RolapHierarchy)2 Execution (mondrian.server.Execution)2 ArrayList (java.util.ArrayList)1 Calc (mondrian.calc.Calc)1 ListTupleList (mondrian.calc.impl.ListTupleList)1 MemberExpr (mondrian.mdx.MemberExpr)1 mondrian.olap (mondrian.olap)1 SetEvaluator (mondrian.olap.Evaluator.SetEvaluator)1 AggregateFunDef (mondrian.olap.fun.AggregateFunDef)1 CrossJoinTest (mondrian.olap.fun.CrossJoinTest)1 NullFunDef (mondrian.olap.fun.CrossJoinTest.NullFunDef)1 ParenthesesFunDef (mondrian.olap.fun.ParenthesesFunDef)1