Search in sources :

Example 1 with MemberType

use of mondrian.olap.type.MemberType in project mondrian by pentaho.

the class CrossJoinTest method getResolvedFunCall.

protected ResolvedFunCall getResolvedFunCall() {
    FunDef funDef = new TestFunDef();
    Exp[] args = new Exp[0];
    Type returnType = new SetType(new TupleType(new Type[] { new MemberType(null, null, null, null), new MemberType(null, null, null, null) }));
    return new ResolvedFunCall(funDef, args, returnType);
}
Also used : FunDef(mondrian.olap.FunDef) MemberType(mondrian.olap.type.MemberType) TupleType(mondrian.olap.type.TupleType) Type(mondrian.olap.type.Type) SetType(mondrian.olap.type.SetType) SetType(mondrian.olap.type.SetType) MemberType(mondrian.olap.type.MemberType) TupleType(mondrian.olap.type.TupleType) ResolvedFunCall(mondrian.mdx.ResolvedFunCall) Exp(mondrian.olap.Exp)

Example 2 with MemberType

use of mondrian.olap.type.MemberType in project mondrian by pentaho.

the class FunUtil method makeNullTuple.

public static Member[] makeNullTuple(final TupleType tupleType) {
    final Type[] elementTypes = tupleType.elementTypes;
    Member[] members = new Member[elementTypes.length];
    for (int i = 0; i < elementTypes.length; i++) {
        MemberType type = (MemberType) elementTypes[i];
        members[i] = makeNullMember(type);
    }
    return members;
}
Also used : MemberType(mondrian.olap.type.MemberType) TupleType(mondrian.olap.type.TupleType) ScalarType(mondrian.olap.type.ScalarType) MatchType(mondrian.olap.MatchType) Type(mondrian.olap.type.Type) MemberType(mondrian.olap.type.MemberType) Member(mondrian.olap.Member)

Example 3 with MemberType

use of mondrian.olap.type.MemberType in project mondrian by pentaho.

the class CrossJoinFunDef method getResultType.

public Type getResultType(Validator validator, Exp[] args) {
    // CROSSJOIN(<Set1>,<Set2>) has type [Hie1] x [Hie2].
    List<MemberType> list = new ArrayList<MemberType>();
    for (Exp arg : args) {
        final Type type = arg.getType();
        if (type instanceof SetType) {
            addTypes(type, list);
        } else if (getName().equals("*")) {
            // The "*" form of CrossJoin is lenient: args can be either
            // members/tuples or sets.
            addTypes(type, list);
        } else {
            throw Util.newInternal("arg to crossjoin must be a set");
        }
    }
    final MemberType[] types = list.toArray(new MemberType[list.size()]);
    TupleType.checkHierarchies(types);
    final TupleType tupleType = new TupleType(types);
    return new SetType(tupleType);
}
Also used : MemberType(mondrian.olap.type.MemberType) TupleType(mondrian.olap.type.TupleType) Type(mondrian.olap.type.Type) SetType(mondrian.olap.type.SetType) MemberType(mondrian.olap.type.MemberType) SetType(mondrian.olap.type.SetType) ArrayList(java.util.ArrayList) TupleType(mondrian.olap.type.TupleType) DummyExp(mondrian.calc.DummyExp) Exp(mondrian.olap.Exp)

Example 4 with MemberType

use of mondrian.olap.type.MemberType in project mondrian by pentaho.

the class CrossJoinFunDef method addTypes.

/**
 * Adds a type to a list of types. If type is a {@link TupleType}, does so recursively.
 *
 * @param type
 *          Type to add to list
 * @param list
 *          List of types to add to
 */
private static void addTypes(final Type type, List<MemberType> list) {
    if (type instanceof SetType) {
        SetType setType = (SetType) type;
        addTypes(setType.getElementType(), list);
    } else if (type instanceof TupleType) {
        TupleType tupleType = (TupleType) type;
        for (Type elementType : tupleType.elementTypes) {
            addTypes(elementType, list);
        }
    } else if (type instanceof MemberType) {
        list.add((MemberType) type);
    } else {
        throw Util.newInternal("Unexpected type: " + type);
    }
}
Also used : MemberType(mondrian.olap.type.MemberType) TupleType(mondrian.olap.type.TupleType) Type(mondrian.olap.type.Type) SetType(mondrian.olap.type.SetType) SetType(mondrian.olap.type.SetType) MemberType(mondrian.olap.type.MemberType) TupleType(mondrian.olap.type.TupleType)

Example 5 with MemberType

use of mondrian.olap.type.MemberType 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 : NumericType(mondrian.olap.type.NumericType) SchemaReader(mondrian.olap.SchemaReader) EmptyType(mondrian.olap.type.EmptyType) ArrayList(java.util.ArrayList) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) UnresolvedFunCall(mondrian.mdx.UnresolvedFunCall) HierarchyExpr(mondrian.mdx.HierarchyExpr) Hierarchy(mondrian.olap.Hierarchy) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) IntegerCalc(mondrian.calc.IntegerCalc) SetType(mondrian.olap.type.SetType) TupleType(mondrian.olap.type.TupleType) ArrayList(java.util.ArrayList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) List(java.util.List) Sorter.hierarchizeMemberList(mondrian.olap.fun.sort.Sorter.hierarchizeMemberList) Member(mondrian.olap.Member) Calc(mondrian.calc.Calc) LevelCalc(mondrian.calc.LevelCalc) MemberCalc(mondrian.calc.MemberCalc) IntegerCalc(mondrian.calc.IntegerCalc) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) LevelCalc(mondrian.calc.LevelCalc) Evaluator(mondrian.olap.Evaluator) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) EmptyType(mondrian.olap.type.EmptyType) MemberType(mondrian.olap.type.MemberType) TupleType(mondrian.olap.type.TupleType) NumericType(mondrian.olap.type.NumericType) Type(mondrian.olap.type.Type) SetType(mondrian.olap.type.SetType) MemberType(mondrian.olap.type.MemberType) MemberCalc(mondrian.calc.MemberCalc) ResolvedFunCall(mondrian.mdx.ResolvedFunCall) Level(mondrian.olap.Level) Exp(mondrian.olap.Exp)

Aggregations

MemberType (mondrian.olap.type.MemberType)5 TupleType (mondrian.olap.type.TupleType)5 Type (mondrian.olap.type.Type)5 SetType (mondrian.olap.type.SetType)4 Exp (mondrian.olap.Exp)3 ArrayList (java.util.ArrayList)2 ResolvedFunCall (mondrian.mdx.ResolvedFunCall)2 Member (mondrian.olap.Member)2 List (java.util.List)1 Calc (mondrian.calc.Calc)1 DummyExp (mondrian.calc.DummyExp)1 IntegerCalc (mondrian.calc.IntegerCalc)1 LevelCalc (mondrian.calc.LevelCalc)1 MemberCalc (mondrian.calc.MemberCalc)1 TupleList (mondrian.calc.TupleList)1 AbstractListCalc (mondrian.calc.impl.AbstractListCalc)1 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)1 HierarchyExpr (mondrian.mdx.HierarchyExpr)1 UnresolvedFunCall (mondrian.mdx.UnresolvedFunCall)1 Evaluator (mondrian.olap.Evaluator)1