[Mondrian] The method MondrianDef.ExpressionView.getTableAlias returns null confuse me.

张建中 zhangjianzhong at revenco.com
Mon Sep 10 04:42:16 EDT 2007

I'm a freshman to Modrian OLAP. 
In my project I defined a "Dimension" 
<Dimension name="Brand">
  <Hierarchy hasAll="true" primaryKey="BRND_CD"
   <Join leftKey="COOPR_CD"  rightKey="COOPR_CD">
    <Table name="TR_BRND" schema="REF" alias="REF_TR_BRND" />
    <Table name="TR_COOPR" schema="REF" alias="REF_TR_COOPR" />
   <Level name="Cooprator" column="COOPR_CD"
    uniqueMembers="true" table="REF_TR_COOPR">
     <SQL dialect="db2">RTRIM(REF_TR_COOPR.COOPR_CD)</SQL>
    <Property name="Cooprator Name"
     column="COOPR_NAM" type="String" />
   <Level name="Brand" column="BRND_CD"
    uniqueMembers="true" table="REF_TR_BRND">
    <Property name="Brand Name" column="BRND_NAM"
it refers two tables so I used a "Join" relation, then 'cause the datas in
the column "COOPR_CD" have spcaces ,so I use a KeyExpression
then my nightmare began , when I query my cube  using MDX : 
select  {[Brand].Members} ON ROWS
from [Communication User Count Daily Analysis];
 Mondrian show me a error tip 
"Mondrian Error:Internal error: bad relation type null" 
I debug the code ,tracing again again. To my surprise, I found that in the
source code ,the logical seems something confusing and I just fall in the
pit... Let me show you.
In class RolapHierarchy , the method addToFrom follows it's statement,then
it use the "expression.getTableAlias()", which always returns a "null" .
which leads the error  "bad relation type null" in the following method
Could you help me make the method MondrianDef.ExpressionView.getTableAlias
available ? 
void addToFrom(SqlQuery query, MondrianDef.Expression expression) {
        if (relation == null) {
            throw Util.newError(
                    "cannot add hierarchy " + getUniqueName() +
                    " to query: it does not have a <Table>, <View> or
        final boolean failIfExists = false;
        MondrianDef.Relation subRelation = relation;
        if (relation instanceof MondrianDef.Join) {
            if (expression != null) {
                // Suppose relation is
                //   (((A join B) join C) join D)
                // and the fact table is
                //   F
                // and our expression uses C. We want to make the expression
                //   F left join ((A join B) join C).
                // Search for the smallest subset of the relation which
                // uses C.
                subRelation = relationSubset(relation,
        query.addFrom(subRelation, null, failIfExists);
public boolean addFrom(final MondrianDef.Relation relation,
                           final String alias,
                           final boolean failIfExists)
        if (relation instanceof MondrianDef.View) {
            final MondrianDef.View view = (MondrianDef.View) relation;
            final String viewAlias = (alias == null)
                    ? view.getAlias()
                    : alias;
            final String sqlString = view.getCodeSet().chooseQuery(dialect);
            return addFromQuery(sqlString, viewAlias, false);
        } else if (relation instanceof MondrianDef.Table) {
            final MondrianDef.Table table = (MondrianDef.Table) relation;
            final String tableAlias = (alias == null)
                    ? table.getAlias()
                    : alias;
            return addFromTable(table.schema, table.name, tableAlias,
                table.getFilter(), failIfExists);
        } else if (relation instanceof MondrianDef.Join) {
            final MondrianDef.Join join = (MondrianDef.Join) relation;
            final String leftAlias = join.getLeftAlias();
            final String rightAlias = join.getRightAlias();
            boolean addLeft = addFrom(join.left, leftAlias, failIfExists);
            boolean addRight = addFrom(join.right, rightAlias,
            boolean added = addLeft || addRight;
            if (added) {
                dialect.quoteIdentifier(leftAlias, join.leftKey, buf);
                buf.append(" = ");
                dialect.quoteIdentifier(rightAlias, join.rightKey, buf);
            return added;
        } else {
            throw Util.newInternal("bad relation type " + relation);




 广州从兴电子开发有限公司 BI研发部

 GuangZhou Sunrise Electronics Development CO.,LTD

 ( 020-8711-6417  13560042989

 * zhangjianzhong at revenco.com

 +广州大道南368号14F , 510300





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.pentaho.org/pipermail/mondrian/attachments/20070910/fb3206a5/attachment.html 

More information about the Mondrian mailing list