Skip to content

Commit

Permalink
MONDRIAN: Reorganize the type hierarchy in MondrianDef so that we can…
Browse files Browse the repository at this point in the history
… exploit commonalities between <Table>, <View>, <InlineTable>. <Join> is now a sub-type of MondrianDef.RelationOrJoin, and MondrianDef.Relation only includes Table, View, InlineTable. Can now include InlineTable in a snowflake dimension.

[git-p4: depot-paths = "//open/mondrian/": change = 10311]
  • Loading branch information
julianhyde committed Dec 17, 2007
1 parent baaaaeb commit bfc58a7
Show file tree
Hide file tree
Showing 16 changed files with 442 additions and 294 deletions.
67 changes: 46 additions & 21 deletions src/main/mondrian/olap/Mondrian.xml
Expand Up @@ -497,12 +497,13 @@ Revision is $Id$
</Doc>
</Attribute>

<Object name="relation" type="Relation">
<Object name="relation" type="RelationOrJoin">
<Doc>
The {@link MondrianDef.Table table},
{@link MondrianDef.Join set of tables}, or
{@link MondrianDef.View SQL statement} which populates this
hierarchy.
{@link MondrianDef.Join set of tables},
{@link MondrianDef.View SQL statement}, or
{@link MondrianDef.InlineTable inline table}
which populates this hierarchy.
</Doc>
</Object>
<Array name="levels" type="Level"><Doc></Doc></Array>
Expand Down Expand Up @@ -985,11 +986,10 @@ Revision is $Id$
<Attribute name="value"/>
</Element>

<Class class="Relation">
<Class class="RelationOrJoin">
<Doc>A table or a join</Doc>
<Code>
public abstract Relation find(String seekAlias);
public abstract String getAlias();
public boolean equals(Object o) {
return this == o;
}
Expand All @@ -999,18 +999,32 @@ Revision is $Id$
</Code>
</Class>

<Class class="Relation" superclass="RelationOrJoin">
<Doc>A table, inline table or view</Doc>
<Code>
public abstract String getAlias();
</Code>
</Class>

<Element type="View" class="Relation">
<Doc>
A collection of SQL statements, one per dialect.
</Doc>
<Attribute name="alias" required="true"/>
<Array name="selects" type="SQL" min="1"/>
<Code>
/**
* Copy constructor.
*/
public View(View view) {
this.alias = view.alias;
this.selects = view.selects.clone();
}
public String toString() {
return selects[0].cdata;
}

public Relation find(String seekAlias) {
public View find(String seekAlias) {
if (seekAlias.equals(alias)) {
return this;
} else {
Expand Down Expand Up @@ -1092,7 +1106,7 @@ Revision is $Id$
</Code>
</Element>

<Element type="Join" class="Relation">
<Element type="Join" class="RelationOrJoin">
<Attribute name="leftAlias">
<Doc>
Defaults to left's alias if left is a table, otherwise
Expand All @@ -1107,12 +1121,18 @@ Revision is $Id$
</Doc>
</Attribute>
<Attribute name="rightKey" required="true"/>
<Object name="left" type="Relation" required="true"/>
<Object name="right" type="Relation" required="true"/>
<Object name="left" type="RelationOrJoin" required="true"/>
<Object name="right" type="RelationOrJoin" required="true"/>
<Code>
/** Convenience constructor. */
public Join(String leftAlias, String leftKey, Relation left,
String rightAlias, String rightKey, Relation right) {
public Join(
String leftAlias,
String leftKey,
RelationOrJoin left,
String rightAlias,
String rightKey,
RelationOrJoin right)
{
this.leftAlias = leftAlias;
this.leftKey = leftKey;
this.left = left;
Expand All @@ -1128,8 +1148,8 @@ Revision is $Id$
if (leftAlias != null) {
return leftAlias;
}
if (left instanceof Table) {
return ((Table) left).getAlias();
if (left instanceof Relation) {
return ((Relation) left).getAlias();
}
throw Util.newInternal(
"alias is required because " + left + " is not a table");
Expand All @@ -1142,8 +1162,8 @@ Revision is $Id$
if (rightAlias != null) {
return rightAlias;
}
if (right instanceof Table) {
return ((Table) right).getAlias();
if (right instanceof Relation) {
return ((Relation) right).getAlias();
}
if (right instanceof Join) {
return ((Join) right).getLeftAlias();
Expand All @@ -1163,9 +1183,6 @@ Revision is $Id$
}
return relation;
}
public String getAlias() {
throw Util.newInternal("join does not have alias");
}
</Code>
</Element>

Expand Down Expand Up @@ -1213,7 +1230,7 @@ Revision is $Id$
name :
schema + "." + name;
}
public Relation find(String seekAlias) {
public Table find(String seekAlias) {
return seekAlias.equals(name) ? this :
(alias != null) && seekAlias.equals(alias) ? this :
null;
Expand Down Expand Up @@ -1257,13 +1274,21 @@ Revision is $Id$
<Object name="columnDefs" type="ColumnDefs" required="true"/>
<Object name="rows" type="Rows" required="true"/>
<Code><![CDATA[
/** Convenience constructor. */
public InlineTable(InlineTable inlineTable) {
this.alias = inlineTable.alias;
this.columnDefs = new ColumnDefs();
this.columnDefs.array = inlineTable.columnDefs.array.clone();
this.rows = new Rows();
this.rows.array = inlineTable.rows.array.clone();
}
public String getAlias() {
return alias;
}
public String toString() {
return "<inline data>";
}
public Relation find(String seekAlias) {
public InlineTable find(String seekAlias) {
return seekAlias.equals(this.alias) ? this : null;
}
public boolean equals(Object o) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/mondrian/rolap/HierarchyUsage.java
Expand Up @@ -254,6 +254,7 @@ public String getUsagePrefix() {
public MondrianDef.Relation getJoinTable() {
return this.joinTable;
}

public MondrianDef.Expression getJoinExp() {
return this.joinExp;
}
Expand Down Expand Up @@ -332,7 +333,8 @@ void init(RolapCube cube,
cube.getUniqueName(),
cubeDim.level);
}
this.joinTable = findJoinTable(hierarchy, joinLevel.getKeyExp().getTableAlias());
this.joinTable =
findJoinTable(hierarchy, joinLevel.getKeyExp().getTableAlias());
this.joinExp = joinLevel.getKeyExp();
} else if (hierarchy.getXmlHierarchy() != null &&
hierarchy.getXmlHierarchy().primaryKey != null) {
Expand Down

0 comments on commit bfc58a7

Please sign in to comment.