Search in sources :

Example 1 with CrossJoinArg

use of mondrian.rolap.sql.CrossJoinArg in project mondrian by pentaho.

the class MemberExcludeConstraint method addLevelConstraint.

@Override
public void addLevelConstraint(SqlQuery query, RolapCube baseCube, AggStar aggStar, RolapLevel level) {
    if (level.equals(this.level)) {
        SqlConstraintUtils.addMemberConstraint(query, baseCube, aggStar, excludes, true, false, true);
    }
    if (csc != null) {
        for (CrossJoinArg cja : csc.args) {
            if (cja.getLevel().equals(level)) {
                cja.addConstraint(query, baseCube, aggStar);
            }
        }
    }
    if (roles.containsKey(level)) {
        List<RolapMember> members = roles.get(level);
        SqlConstraintUtils.addMemberConstraint(query, baseCube, aggStar, members, true, false, false);
    }
}
Also used : CrossJoinArg(mondrian.rolap.sql.CrossJoinArg)

Example 2 with CrossJoinArg

use of mondrian.rolap.sql.CrossJoinArg in project mondrian by pentaho.

the class SqlTupleReader method chooseAggStar.

/**
 * Obtains the AggStar instance which corresponds to an aggregate table which can be used to support the member
 * constraint.
 *
 * @param constraint The tuple constraint to apply.
 * @param evaluator  the current evaluator to obtain the cube and members to be queried  @return AggStar for aggregate
 *                   table
 * @param baseCube   The base cube from which to choose an aggregation star. Can be null, in which case we use the
 *                   evaluator's cube.
 */
AggStar chooseAggStar(TupleConstraint constraint, Evaluator evaluator, RolapCube baseCube) {
    if (!MondrianProperties.instance().UseAggregates.get()) {
        return null;
    }
    if (evaluator == null || !constraint.supportsAggTables()) {
        return null;
    }
    if (baseCube == null) {
        baseCube = (RolapCube) evaluator.getCube();
    }
    // Current cannot support aggregate tables for virtual cubes
    if (baseCube.isVirtual()) {
        return null;
    }
    RolapStar star = baseCube.getStar();
    final int starColumnCount = star.getColumnCount();
    BitKey measureBitKey = BitKey.Factory.makeBitKey(starColumnCount);
    BitKey levelBitKey = BitKey.Factory.makeBitKey(starColumnCount);
    // Convert global ordinal to cube based ordinal (the 0th dimension
    // is always [Measures]). In the case of filter constraint this will
    // be the measure on which the filter will be done.
    // Since we support aggregated members as arguments, we'll expand
    // this too.
    // Failing to do so could result in chosing the wrong aggstar, as the
    // level would not be passed to the bitkeys
    final Member[] members = SqlConstraintUtils.expandSupportedCalculatedMembers(Arrays.asList(evaluator.getNonAllMembers()), evaluator).getMembersArray();
    // if measure is calculated, we can't continue
    if (!(members[0] instanceof RolapBaseCubeMeasure)) {
        return null;
    }
    RolapBaseCubeMeasure measure = (RolapBaseCubeMeasure) members[0];
    int bitPosition = ((RolapStar.Measure) measure.getStarMeasure()).getBitPosition();
    // set a bit for each level which is constrained in the context
    final CellRequest request = RolapAggregationManager.makeRequest(members);
    if (request == null) {
        // One or more calculated members. Cannot use agg table.
        return null;
    }
    // TODO: RME why is this using the array of constrained columns
    // from the CellRequest rather than just the constrained columns
    // BitKey (method getConstrainedColumnsBitKey)?
    RolapStar.Column[] columns = request.getConstrainedColumns();
    for (RolapStar.Column column1 : columns) {
        levelBitKey.set(column1.getBitPosition());
    }
    // set the masks
    for (TargetBase target : targets) {
        RolapLevel level = target.level;
        if (!level.isAll()) {
            RolapStar.Column column = ((RolapCubeLevel) level).getBaseStarKeyColumn(baseCube);
            if (column != null) {
                levelBitKey.set(column.getBitPosition());
            }
        }
    }
    // Set the bits for limited rollup members
    RolapUtil.constraintBitkeyForLimitedMembers(evaluator, evaluator.getMembers(), baseCube, levelBitKey);
    measureBitKey.set(bitPosition);
    if (constraint instanceof RolapNativeCrossJoin.NonEmptyCrossJoinConstraint) {
        // Cannot evaluate NonEmptyCrossJoinConstraint using an agg
        // table if one of its args is a DescendantsConstraint.
        RolapNativeCrossJoin.NonEmptyCrossJoinConstraint necj = (RolapNativeCrossJoin.NonEmptyCrossJoinConstraint) constraint;
        for (CrossJoinArg arg : necj.args) {
            if (arg instanceof DescendantsCrossJoinArg || arg instanceof MemberListCrossJoinArg) {
                final RolapLevel level = arg.getLevel();
                if (level != null && !level.isAll()) {
                    RolapStar.Column column = ((RolapCubeLevel) level).getBaseStarKeyColumn(baseCube);
                    if (column == null) {
                        // target group.
                        continue;
                    }
                    levelBitKey.set(column.getBitPosition());
                }
            }
        }
    } else if (constraint instanceof RolapNativeFilter.FilterConstraint) {
        for (Member slicer : ((RolapEvaluator) evaluator).getSlicerMembers()) {
            final Level level = slicer.getLevel();
            if (level != null && !level.isAll()) {
                final RolapStar.Column column = ((RolapCubeLevel) level).getBaseStarKeyColumn(baseCube);
                levelBitKey.set(column.getBitPosition());
            }
        }
    }
    // find the aggstar using the masks
    return AggregationManager.findAgg(star, levelBitKey, measureBitKey, new boolean[] { false });
}
Also used : DescendantsCrossJoinArg(mondrian.rolap.sql.DescendantsCrossJoinArg) MemberListCrossJoinArg(mondrian.rolap.sql.MemberListCrossJoinArg) CrossJoinArg(mondrian.rolap.sql.CrossJoinArg) DescendantsCrossJoinArg(mondrian.rolap.sql.DescendantsCrossJoinArg) TupleConstraint(mondrian.rolap.sql.TupleConstraint) MemberChildrenConstraint(mondrian.rolap.sql.MemberChildrenConstraint) CellRequest(mondrian.rolap.agg.CellRequest) Level(mondrian.olap.Level) MemberListCrossJoinArg(mondrian.rolap.sql.MemberListCrossJoinArg) Member(mondrian.olap.Member)

Example 3 with CrossJoinArg

use of mondrian.rolap.sql.CrossJoinArg in project mondrian by pentaho.

the class RolapNativeSet method overrideContext.

/**
 * Overrides current members in position by default members in hierarchies which are involved in this
 * filter/topcount.
 * Stores the RolapStoredMeasure into the context because that is needed to generate a cell request to constraint
 * the
 * sql.
 *
 * <p>The current context may contain a calculated measure, this measure
 * was translated into an sql condition (filter/topcount). The measure is not used to constrain the result but
 * only to
 * access the star.
 *
 * @param evaluator     Evaluation context to modify
 * @param cargs         Cross join arguments
 * @param storedMeasure Stored measure
 * @see RolapAggregationManager#makeRequest(RolapEvaluator)
 */
protected void overrideContext(RolapEvaluator evaluator, CrossJoinArg[] cargs, RolapStoredMeasure storedMeasure) {
    SchemaReader schemaReader = evaluator.getSchemaReader();
    for (CrossJoinArg carg : cargs) {
        RolapLevel level = carg.getLevel();
        if (level != null) {
            RolapHierarchy hierarchy = level.getHierarchy();
            final Member contextMember;
            if (hierarchy.hasAll() || schemaReader.getRole().getAccess(hierarchy) == Access.ALL) {
                // The hierarchy may have access restrictions.
                // If it does, calling .substitute() will retrieve an
                // appropriate LimitedRollupMember.
                contextMember = schemaReader.substitute(hierarchy.getAllMember());
            } else {
                // If there is no All member on a role restricted hierarchy,
                // use a restricted member based on the set of accessible
                // root members.
                contextMember = new RestrictedMemberReader.MultiCardinalityDefaultMember(hierarchy.getMemberReader().getRootMembers().get(0));
            }
            evaluator.setContext(contextMember);
        }
    }
    if (storedMeasure != null) {
        evaluator.setContext(storedMeasure);
    }
}
Also used : SchemaReader(mondrian.olap.SchemaReader) DelegatingSchemaReader(mondrian.olap.DelegatingSchemaReader) MemberListCrossJoinArg(mondrian.rolap.sql.MemberListCrossJoinArg) CrossJoinArg(mondrian.rolap.sql.CrossJoinArg) Member(mondrian.olap.Member)

Aggregations

CrossJoinArg (mondrian.rolap.sql.CrossJoinArg)3 Member (mondrian.olap.Member)2 MemberListCrossJoinArg (mondrian.rolap.sql.MemberListCrossJoinArg)2 DelegatingSchemaReader (mondrian.olap.DelegatingSchemaReader)1 Level (mondrian.olap.Level)1 SchemaReader (mondrian.olap.SchemaReader)1 CellRequest (mondrian.rolap.agg.CellRequest)1 DescendantsCrossJoinArg (mondrian.rolap.sql.DescendantsCrossJoinArg)1 MemberChildrenConstraint (mondrian.rolap.sql.MemberChildrenConstraint)1 TupleConstraint (mondrian.rolap.sql.TupleConstraint)1