Search in sources :

Example 1 with RecorderException

use of mondrian.recorder.RecorderException in project mondrian by pentaho.

the class AggTableManager method loadRolapStarAggregates.

/**
 * This method loads and/or reloads the aggregate tables.
 * <p>
 * NOTE: At this point all RolapStars have been made for this
 * schema (except for dynamically added cubes which I am going
 * to ignore for right now). So, All stars have their columns
 * and their BitKeys can be generated.
 *
 * @throws SQLException
 */
private void loadRolapStarAggregates() throws SQLException {
    ListRecorder msgRecorder = new ListRecorder();
    try {
        DefaultRules rules = DefaultRules.getInstance();
        JdbcSchema db = getJdbcSchema();
        // calls to other instances of AggTableManager.finalCleanUp()
        synchronized (db) {
            // fix for MONDRIAN-496
            // flush any existing usages of the jdbc schema, so we
            // don't accidentally use another star's metadata
            db.flushUsages();
            // loads tables, not their columns
            db.load();
            loop: for (RolapStar star : getStars()) {
                // This removes any AggStars from any previous invocation of
                // this method (if any)
                star.prepareToLoadAggregates();
                List<ExplicitRules.Group> aggGroups = getAggGroups(star);
                for (ExplicitRules.Group group : aggGroups) {
                    group.validate(msgRecorder);
                }
                String factTableName = getFactTableName(star);
                JdbcSchema.Table dbFactTable = db.getTable(factTableName);
                if (dbFactTable == null) {
                    msgRecorder.reportWarning("No Table found for fact name=" + factTableName);
                    continue loop;
                }
                // For each column in the dbFactTable, figure out it they
                // are measure or foreign key columns
                bindToStar(dbFactTable, star, msgRecorder);
                String schema = dbFactTable.table.schema;
                for (JdbcSchema.Table dbTable : db.getTables()) {
                    String name = dbTable.getName();
                    // this table name.
                    if (ExplicitRules.excludeTable(name, aggGroups)) {
                        continue;
                    }
                    // First see if there is an ExplicitRules match. If so,
                    // then if all of the columns match up, then make an
                    // AggStar. On the other hand, if there is no
                    // ExplicitRules match, see if there is a Default
                    // match. If so and if all the columns match up, then
                    // also make an AggStar.
                    ExplicitRules.TableDef tableDef = ExplicitRules.getIncludeByTableDef(name, aggGroups);
                    boolean makeAggStar = false;
                    int approxRowCount = Integer.MIN_VALUE;
                    // Is it handled by the ExplicitRules
                    if (tableDef != null) {
                        // load columns
                        dbTable.load();
                        makeAggStar = tableDef.columnsOK(star, dbFactTable, dbTable, msgRecorder);
                        approxRowCount = tableDef.getApproxRowCount();
                    }
                    if (!makeAggStar && MondrianProperties.instance().ReadAggregates.get()) {
                        // Is it handled by the DefaultRules
                        if (rules.matchesTableName(factTableName, name)) {
                            // load columns
                            dbTable.load();
                            makeAggStar = rules.columnsOK(star, dbFactTable, dbTable, msgRecorder);
                        }
                    }
                    if (makeAggStar) {
                        dbTable.setTableUsageType(JdbcSchema.TableUsageType.AGG);
                        dbTable.table = new MondrianDef.Table(schema, name, // null alias
                        null, // don't know about table hints
                        null);
                        AggStar aggStar = AggStar.makeAggStar(star, dbTable, msgRecorder, approxRowCount);
                        if (aggStar.getSize() > 0) {
                            star.addAggStar(aggStar);
                        } else {
                            getLogger().warn(mres.AggTableZeroSize.str(aggStar.getFactTable().getName(), factTableName));
                        }
                    }
                // Note: if the dbTable name matches but the columnsOK
                // does not, then this is an error and the aggregate
                // tables can not be loaded.
                // We do not "reset" the column usages in the dbTable
                // allowing it maybe to match another rule.
                }
            }
        }
    } catch (RecorderException ex) {
        throw new MondrianException(ex);
    } finally {
        msgRecorder.logInfoMessage(getLogger());
        msgRecorder.logWarningMessage(getLogger());
        msgRecorder.logErrorMessage(getLogger());
        if (msgRecorder.hasErrors()) {
            throw mres.AggLoadingExceededErrorCount.ex(msgRecorder.getErrorCount());
        }
    }
}
Also used : RolapStar(mondrian.rolap.RolapStar) RecorderException(mondrian.recorder.RecorderException) ArrayList(java.util.ArrayList) List(java.util.List) MondrianException(mondrian.olap.MondrianException) ListRecorder(mondrian.recorder.ListRecorder)

Example 2 with RecorderException

use of mondrian.recorder.RecorderException in project mondrian by pentaho.

the class AggTableManager method loadRolapStarAggregates.

/**
 * This method loads and/or reloads the aggregate tables.
 * <p>
 * NOTE: At this point all RolapStars have been made for this
 * schema (except for dynamically added cubes which I am going
 * to ignore for right now). So, All stars have their columns
 * and their BitKeys can be generated.
 *
 * @throws SQLException
 */
private void loadRolapStarAggregates(PropertyList connectInfo) throws SQLException {
    ListRecorder msgRecorder = new ListRecorder();
    try {
        DefaultRules rules = DefaultRules.getInstance();
        JdbcSchema db = getJdbcSchema();
        // calls to other instances of AggTableManager.finalCleanUp()
        synchronized (db) {
            // fix for MONDRIAN-496
            // flush any existing usages of the jdbc schema, so we
            // don't accidentally use another star's metadata
            db.flushUsages();
            // loads tables, not their columns
            db.load(connectInfo);
            loop: for (RolapStar star : getStars()) {
                // This removes any AggStars from any previous invocation of
                // this method (if any)
                star.prepareToLoadAggregates();
                List<ExplicitRules.Group> aggGroups = getAggGroups(star);
                for (ExplicitRules.Group group : aggGroups) {
                    group.validate(msgRecorder);
                }
                String factTableName = getFactTableName(star);
                JdbcSchema.Table dbFactTable = db.getTable(factTableName);
                if (dbFactTable == null) {
                    msgRecorder.reportWarning("No Table found for fact name=" + factTableName);
                    continue loop;
                }
                // For each column in the dbFactTable, figure out it they
                // are measure or foreign key columns
                bindToStar(dbFactTable, star, msgRecorder);
                String schema = dbFactTable.table.schema;
                for (JdbcSchema.Table dbTable : db.getTables()) {
                    String name = dbTable.getName();
                    // this table name.
                    if (ExplicitRules.excludeTable(name, aggGroups)) {
                        continue;
                    }
                    // First see if there is an ExplicitRules match. If so,
                    // then if all of the columns match up, then make an
                    // AggStar. On the other hand, if there is no
                    // ExplicitRules match, see if there is a Default
                    // match. If so and if all the columns match up, then
                    // also make an AggStar.
                    ExplicitRules.TableDef tableDef = ExplicitRules.getIncludeByTableDef(name, aggGroups);
                    boolean makeAggStar = false;
                    int approxRowCount = Integer.MIN_VALUE;
                    // Is it handled by the ExplicitRules
                    if (tableDef != null) {
                        // load columns
                        dbTable.load();
                        makeAggStar = tableDef.columnsOK(star, dbFactTable, dbTable, msgRecorder);
                        approxRowCount = tableDef.getApproxRowCount();
                    }
                    if (!makeAggStar && MondrianProperties.instance().ReadAggregates.get()) {
                        // Is it handled by the DefaultRules
                        if (rules.matchesTableName(factTableName, name)) {
                            // load columns
                            dbTable.load();
                            makeAggStar = rules.columnsOK(star, dbFactTable, dbTable, msgRecorder);
                        }
                    }
                    if (makeAggStar) {
                        dbTable.setTableUsageType(JdbcSchema.TableUsageType.AGG);
                        dbTable.table = new MondrianDef.Table(schema, name, // null alias
                        null, // don't know about table hints
                        null);
                        AggStar aggStar = AggStar.makeAggStar(star, dbTable, msgRecorder, approxRowCount);
                        if (aggStar.getSize() > 0) {
                            star.addAggStar(aggStar);
                        } else {
                            getLogger().warn(mres.AggTableZeroSize.str(aggStar.getFactTable().getName(), factTableName));
                        }
                    }
                // Note: if the dbTable name matches but the columnsOK
                // does not, then this is an error and the aggregate
                // tables can not be loaded.
                // We do not "reset" the column usages in the dbTable
                // allowing it maybe to match another rule.
                }
            }
        }
    } catch (RecorderException ex) {
        throw new MondrianException(ex);
    } finally {
        msgRecorder.logInfoMessage(getLogger());
        msgRecorder.logWarningMessage(getLogger());
        msgRecorder.logErrorMessage(getLogger());
        if (msgRecorder.hasErrors()) {
            throw mres.AggLoadingExceededErrorCount.ex(msgRecorder.getErrorCount());
        }
    }
}
Also used : RolapStar(mondrian.rolap.RolapStar) RecorderException(mondrian.recorder.RecorderException) PropertyList(mondrian.olap.Util.PropertyList) ArrayList(java.util.ArrayList) List(java.util.List) MondrianException(mondrian.olap.MondrianException) ListRecorder(mondrian.recorder.ListRecorder)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 MondrianException (mondrian.olap.MondrianException)2 ListRecorder (mondrian.recorder.ListRecorder)2 RecorderException (mondrian.recorder.RecorderException)2 RolapStar (mondrian.rolap.RolapStar)2 PropertyList (mondrian.olap.Util.PropertyList)1