Search in sources :

Example 1 with RolapStar

use of mondrian.rolap.RolapStar 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 RolapStar

use of mondrian.rolap.RolapStar 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)

Example 3 with RolapStar

use of mondrian.rolap.RolapStar in project mondrian by pentaho.

the class AggGen method init.

/**
 * The columns are the RolapStar columns taking part in an aggregation
 * request. This is what happens.
 * First, for each column, walk up the column's table until one level below
 * the base fact table. The left join condition contains the base fact table
 * and the foreign key column name. This column should not be lost.
 * Get the base fact table's measure columns.
 * With a list of columns that should not be lost and measure, one can
 * create lost create and insert commands.
 */
private void init() {
    JdbcSchema db = JdbcSchema.makeDB(star.getDataSource());
    try {
        db.load(new Util.PropertyList());
    } catch (SQLException ex) {
        getLogger().error(ex);
        return;
    }
    JdbcSchema.Table factTable = getTable(db, getFactTableName());
    if (factTable == null) {
        getLogger().warn("Init: " + "No fact table with name \"" + getFactTableName() + "\"");
        return;
    }
    try {
        factTable.load();
    } catch (SQLException ex) {
        getLogger().error(ex);
        return;
    }
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Init: " + "RolapStar:" + Util.nl + getFactTable() + Util.nl + "FactTable:" + Util.nl + factTable);
    }
    // do foreign keys
    for (RolapStar.Column column : columns) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Init: " + "Column: " + column);
        }
        RolapStar.Table table = column.getTable();
        if (table.getParentTable() == null) {
            // in the RolapStar is this hiearchy captured - ugg.
            if (!addSpecialCollapsedColumn(db, column)) {
                return;
            }
            MondrianDef.Expression expr = column.getExpression();
            if (expr instanceof MondrianDef.Column) {
                MondrianDef.Column exprColumn = (MondrianDef.Column) expr;
                String name = exprColumn.getColumnName();
                JdbcSchema.Table.Column c = getColumn(factTable, name);
                if (c == null) {
                    getLogger().warn("Init: " + "FactTable:" + getFactTableName() + Util.nl + "No Column with name \"" + name + "\"");
                    return;
                }
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("  Jdbc Column: c=" + c);
                }
                addForeignKeyToNotLostColumnUsages(c);
            }
        } else {
            if (!addCollapsedColumn(db, column)) {
                return;
            }
            while (table.getParentTable().getParentTable() != null) {
                table = table.getParentTable();
            }
            RolapStar.Condition cond = table.getJoinCondition();
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("  RolapStar.Condition: cond=" + cond);
            }
            MondrianDef.Expression left = cond.getLeft();
            if (left instanceof MondrianDef.Column) {
                MondrianDef.Column leftColumn = (MondrianDef.Column) left;
                String name = leftColumn.getColumnName();
                JdbcSchema.Table.Column c = getColumn(factTable, name);
                if (c == null) {
                    getLogger().warn("Init: " + "FactTable:" + getFactTableName() + Util.nl + "No Column with name \"" + name + "\"");
                    return;
                }
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("  Jdbc Column: c=" + c);
                }
                addForeignKeyToNotLostColumnUsages(c);
            }
        }
    }
    // do measures
    for (RolapStar.Column rColumn : getFactTable().getColumns()) {
        String name = getRolapStarColumnName(rColumn);
        if (name == null) {
            getLogger().warn("Init: " + "For fact table \"" + getFactTableName() + "\", could not get column name for RolapStar.Column: " + rColumn);
            return;
        }
        if (!(rColumn instanceof RolapStar.Measure)) {
            // TODO: whats the solution to this?
            // its a funky dimension column in the fact table!!!
            getLogger().warn("not a measure: " + name);
            continue;
        }
        RolapStar.Measure rMeasure = (RolapStar.Measure) rColumn;
        if (!rMeasure.getCubeName().equals(cubeName)) {
            continue;
        }
        final RolapAggregator aggregator = rMeasure.getAggregator();
        JdbcSchema.Table.Column c = getColumn(factTable, name);
        if (c == null) {
            getLogger().warn("For RolapStar: \"" + getFactTable().getAlias() + "\" measure with name, " + name + ", is not a column name. " + "The measure's column name may be an expression" + " and currently AggGen does not handle expressions." + " You will have to add this measure to the" + " aggregate table definition by hand.");
            continue;
        }
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("  Jdbc Column m=" + c);
        }
        JdbcSchema.Table.Column.Usage usage = null;
        if (c.hasUsage(JdbcSchema.UsageType.MEASURE)) {
            for (Iterator<JdbcSchema.Table.Column.Usage> uit = c.getUsages(JdbcSchema.UsageType.MEASURE); uit.hasNext(); ) {
                JdbcSchema.Table.Column.Usage tmpUsage = uit.next();
                if ((tmpUsage.getAggregator() == aggregator) && tmpUsage.getSymbolicName().equals(rColumn.getName())) {
                    usage = tmpUsage;
                    break;
                }
            }
        }
        if (usage == null) {
            usage = c.newUsage(JdbcSchema.UsageType.MEASURE);
            usage.setAggregator(aggregator);
            usage.setSymbolicName(rColumn.getName());
        }
        measures.add(usage);
    }
    // If we got to here, then everything is ok.
    isReady = true;
}
Also used : SQLException(java.sql.SQLException) Util(mondrian.olap.Util) RolapAggregator(mondrian.rolap.RolapAggregator) MondrianDef(mondrian.olap.MondrianDef) RolapStar(mondrian.rolap.RolapStar)

Example 4 with RolapStar

use of mondrian.rolap.RolapStar in project mondrian by pentaho.

the class AggTableManager method printResults.

private void printResults() {
    /*
 *   This was too much information at the INFO level, compared to the
 *   rest of Mondrian
 *
 *         if (getLogger().isInfoEnabled()) {
            // print just Star table alias and AggStar table names
            StringBuilder buf = new StringBuilder(1024);
            buf.append(Util.nl);
            for (Iterator it = getStars(); it.hasNext();) {
                RolapStar star = (RolapStar) it.next();
                buf.append(star.getFactTable().getAlias());
                buf.append(Util.nl);
                for (Iterator ait = star.getAggStars(); ait.hasNext();) {
                    AggStar aggStar = (AggStar) ait.next();
                    buf.append("    ");
                    buf.append(aggStar.getFactTable().getName());
                    buf.append(Util.nl);
                }
            }
            getLogger().info(buf.toString());

        } else
*/
    if (getLogger().isDebugEnabled()) {
        // print everything, Star, subTables, AggStar and subTables
        // could be a lot
        StringBuilder buf = new StringBuilder(4096);
        buf.append(Util.nl);
        for (RolapStar star : getStars()) {
            buf.append(star.toString());
            buf.append(Util.nl);
        }
        getLogger().debug(buf.toString());
    }
}
Also used : RolapStar(mondrian.rolap.RolapStar)

Example 5 with RolapStar

use of mondrian.rolap.RolapStar in project mondrian by pentaho.

the class GroupingSetsListTest method getStarMock.

private static RolapStar getStarMock() {
    RolapStar mock = mock(RolapStar.class);
    RolapStar.Table tableMock = mock(RolapStar.Table.class);
    RolapSchema schemaMock = mock(RolapSchema.class);
    ByteString md5 = new ByteString("test schema".getBytes());
    when(mock.getSchema()).thenReturn(schemaMock);
    when(schemaMock.getChecksum()).thenReturn(md5);
    when(mock.getFactTable()).thenReturn(tableMock);
    when(tableMock.getAlias()).thenReturn("Table Mock");
    return mock;
}
Also used : RolapSchema(mondrian.rolap.RolapSchema) RolapStar(mondrian.rolap.RolapStar) ByteString(mondrian.util.ByteString)

Aggregations

RolapStar (mondrian.rolap.RolapStar)5 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 SQLException (java.sql.SQLException)1 MondrianDef (mondrian.olap.MondrianDef)1 Util (mondrian.olap.Util)1 PropertyList (mondrian.olap.Util.PropertyList)1 RolapAggregator (mondrian.rolap.RolapAggregator)1 RolapSchema (mondrian.rolap.RolapSchema)1 ByteString (mondrian.util.ByteString)1