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

Eduardo Andrade eduardofandrade at gmail.com
Mon Sep 10 04:51:31 EDT 2007


Hello,

I also had the same problem. This is related to using a KeyExpression,
ParentExpression, etc. inside a Dimension with a Join.
If you remove the KeyExpression, probably everything's fine. Not sure what's
supposed to happen here, maybe someone from the developing team would know.

Just a thought : If you create a View in your Database that is a inner join
of the two tables involved in the dimension, you'll be able to use it as a
dimension table and eliminate this problem also (this way you may use the
KeyExpression).

Best regards,
Eduardo Andrade


On 9/10/07, 张建中 <zhangjianzhong at revenco.com> wrote:
>
>  I'm a freshman to Modrian OLAP.
> In my project I defined a "Dimension"
>
> <Dimension name="Brand">
>   <Hierarchy hasAll="true" primaryKey="BRND_CD"
> primaryKeyTable="REF_TR_BRND">
>    <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" />
>    </Join>
>    <Level name="Cooprator" column="COOPR_CD"
>     uniqueMembers="true" table="REF_TR_COOPR">
>     <KeyExpression>
>      <SQL dialect="db2">RTRIM(REF_TR_COOPR.COOPR_CD)</SQL>
>     </KeyExpression>
>     <Property name="Cooprator Name"
>      column="COOPR_NAM" type="String" />
>    </Level>
>    <Level name="Brand" column="BRND_CD"
>     uniqueMembers="true" table="REF_TR_BRND">
>     <Property name="Brand Name" column="BRND_NAM"
>      type="String"/>
>    </Level>
>   </Hierarchy>
>  </Dimension>
>
> 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
> addFrom.
>
> Could you help me make the method MondrianDef.ExpressionView.getTableAliasavailable ?
>
> thanks
>
> 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
> <Join>");
>         }
>         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,
> expression.getTableAlias());
>
>             }
>         }
>         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,
> failIfExists);
>
>             boolean added = addLeft || addRight;
>             if (added) {
>                 buf.setLength(0);
>
>                 dialect.quoteIdentifier(leftAlias, join.leftKey, buf);
>                 buf.append(" = ");
>                 dialect.quoteIdentifier(rightAlias, join.rightKey, buf);
>
>                 addWhere(buf.toString());
>             }
>             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*
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Mondrian mailing list
> Mondrian at pentaho.org
> http://lists.pentaho.org/mailman/listinfo/mondrian
>
>


-- 
Eduardo Andrade
eduardofandrade at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.pentaho.org/pipermail/mondrian/attachments/20070910/4048704c/attachment.html 


More information about the Mondrian mailing list