Skip to content

Commit

Permalink
MONDRIAN: Fix dependency-checking for expressions of uncertain dimens…
Browse files Browse the repository at this point in the history
…ionality.

[git-p4: depot-paths = "//open/mondrian/": change = 9512]
  • Loading branch information
julianhyde committed Jun 26, 2007
1 parent 7e2b322 commit 6379ace
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 53 deletions.
12 changes: 11 additions & 1 deletion src/main/mondrian/calc/impl/MemberValueCalc.java
Expand Up @@ -70,7 +70,17 @@ public boolean dependsOn(Dimension dimension) {
return true;
}
for (MemberCalc memberCalc : memberCalcs) {
// If the expression
// If the expression definitely includes the dimension (in this
// case, that means it is a member of that dimension) then we
// do not depend on the dimension. For example, the scalar value of
// [Store].[USA]
// does not depend on [Store].
//
// If the dimensionality of the expression is unknown, then the
// expression MIGHT include the dimension, so to be safe we have to
// say that it depends on the given dimension. For example,
// Dimensions(3).CurrentMember.Parent
// may depend on [Store].
if (memberCalc.getType().usesDimension(dimension, true)) {
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/mondrian/olap/Query.java
Expand Up @@ -462,7 +462,7 @@ public void setResultStyle(ResultStyle resultStyle) {
resultStyle);
}
}

public ResultStyle getResultStyle() {
return resultStyle;
}
Expand Down Expand Up @@ -579,8 +579,7 @@ public Object visit(UnresolvedFunCall call) {
} else {
axisExp = axes[j];
}
if (axisExp.getSet().getType().usesDimension(dimension,
false)) {
if (axisExp.getSet().getType().usesDimension(dimension, true)) {
++useCount;
}
}
Expand Down
16 changes: 0 additions & 16 deletions src/main/mondrian/olap/fun/BuiltinFunTable.java
Expand Up @@ -930,15 +930,10 @@ public List evaluateList(Evaluator evaluator) {
});

define(CrossJoinFunDef.Resolver);

define(NonEmptyCrossJoinFunDef.Resolver);

define(CrossJoinFunDef.StarResolver);

define(DescendantsFunDef.Resolver);

define(DistinctFunDef.instance);

define(DrilldownLevelFunDef.Resolver);

if (false) define(new FunDefBase(
Expand Down Expand Up @@ -1426,17 +1421,6 @@ public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
}
});

// we do not support the <String expression> arguments
if (false) define(new FunDefBase(
"Item",
"<Set>.Item(<String Expression>[, <String Expression>...] | <Index>)",
"Returns a tuple from a set.",
"mx*") {
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
throw new UnsupportedOperationException();
}
});

define(SetItemFunDef.intResolver);
define(SetItemFunDef.stringResolver);
define(TupleItemFunDef.instance);
Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/olap/type/CubeType.java
Expand Up @@ -35,7 +35,7 @@ public Cube getCube() {
return cube;
}

public boolean usesDimension(Dimension dimension, boolean maybe) {
public boolean usesDimension(Dimension dimension, boolean definitely) {
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/mondrian/olap/type/DimensionType.java
Expand Up @@ -29,8 +29,8 @@ public class DimensionType implements Type {
/**
* Creates a type representing a dimension.
*
* @param dimension Dimension that values of this type must belong to.
* Null if the dimension is unknown.
* @param dimension Dimension that values of this type must belong to, or
* null if the dimension is unknown
*/
public DimensionType(Dimension dimension) {
this.dimension = dimension;
Expand All @@ -50,9 +50,9 @@ public static DimensionType forType(Type type) {
return new DimensionType(type.getDimension());
}

public boolean usesDimension(Dimension dimension, boolean maybe) {
public boolean usesDimension(Dimension dimension, boolean definitely) {
return this.dimension == dimension ||
(maybe && this.dimension == null);
(definitely && this.dimension == null);
}

public Hierarchy getHierarchy() {
Expand Down
10 changes: 7 additions & 3 deletions src/main/mondrian/olap/type/HierarchyType.java
Expand Up @@ -27,6 +27,11 @@ public class HierarchyType implements Type {

/**
* Creates a type representing a hierarchy.
*
* @param dimension Dimension that values of this type must belong to, or
* null if the dimension is unknown
* @param hierarchy Hierarchy that values of this type must belong to,
* null if the hierarchy is unknown
*/
public HierarchyType(Dimension dimension, Hierarchy hierarchy) {
this.dimension = dimension;
Expand All @@ -39,7 +44,6 @@ public HierarchyType(Dimension dimension, Hierarchy hierarchy) {
}
buf.append(">");
this.digest = buf.toString();

}

public static HierarchyType forHierarchy(Hierarchy hierarchy) {
Expand All @@ -50,9 +54,9 @@ public static HierarchyType forType(Type type) {
return new HierarchyType(type.getDimension(), type.getHierarchy());
}

public boolean usesDimension(Dimension dimension, boolean maybe) {
public boolean usesDimension(Dimension dimension, boolean definitely) {
return this.dimension == dimension ||
(maybe && this.dimension == null);
(!definitely && this.dimension == null);
}

public Dimension getDimension() {
Expand Down
12 changes: 5 additions & 7 deletions src/main/mondrian/olap/type/LevelType.java
Expand Up @@ -30,7 +30,8 @@ public class LevelType implements Type {
/**
* Creates a type representing a level.
*
* @param dimension
* @param dimension Dimension which values of this type must belong to, or
* null if not known
* @param hierarchy Hierarchy which values of this type must belong to, or
* null if not known
* @param level Level which values of this type must belong to, or null if
Expand Down Expand Up @@ -76,12 +77,9 @@ public static LevelType forLevel(Level level) {
level);
}

public boolean usesDimension(Dimension dimension, boolean maybe) {
if (this.dimension == null) {
return maybe;
} else {
return this.dimension == dimension;
}
public boolean usesDimension(Dimension dimension, boolean definitely) {
return this.dimension == dimension ||
(!definitely && this.dimension == null);
}

public Dimension getDimension() {
Expand Down
14 changes: 5 additions & 9 deletions src/main/mondrian/olap/type/MemberType.java
Expand Up @@ -30,8 +30,8 @@ public class MemberType implements Type {
/**
* Creates a type representing a member.
*
* @param dimension
* @param hierarchy Hierarchy the member belongs to, or null if not known.
* @param dimension Dimension the member belongs to, or null if not known
* @param hierarchy Hierarchy the member belongs to, or null if not known
* @param level Level the member belongs to, or null if not known
* @param member The precise member, or null if not known
*/
Expand Down Expand Up @@ -102,13 +102,9 @@ public Member getMember() {
return member;
}

public boolean usesDimension(Dimension dimension, boolean maybe) {
if (this.dimension == null) {
return maybe;
} else {
return this.dimension == dimension ||
(maybe && this.dimension == null);
}
public boolean usesDimension(Dimension dimension, boolean definitely) {
return this.dimension == dimension ||
(!definitely && this.dimension == null);
}

public Type getValueType() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/olap/type/ScalarType.java
Expand Up @@ -25,7 +25,7 @@
* @version $Id$
*/
public class ScalarType implements Type {
public boolean usesDimension(Dimension dimension, boolean maybe) {
public boolean usesDimension(Dimension dimension, boolean definitely) {
return false;
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/mondrian/olap/type/SetType.java
Expand Up @@ -40,16 +40,18 @@ public SetType(Type elementType) {

/**
* Returns the type of the elements of this set.
*
* @return the type of the elements in this set
*/
public Type getElementType() {
return elementType;
}

public boolean usesDimension(Dimension dimension, boolean maybe) {
public boolean usesDimension(Dimension dimension, boolean definitely) {
if (elementType == null) {
return maybe;
return definitely;
}
return elementType.usesDimension(dimension, maybe);
return elementType.usesDimension(dimension, definitely);
}

public Dimension getDimension() {
Expand Down
6 changes: 4 additions & 2 deletions src/main/mondrian/olap/type/TupleType.java
Expand Up @@ -23,15 +23,17 @@ public class TupleType implements Type {

/**
* Creates a type representing a tuple whose fields are the given types.
*
* @param elementTypes Array of types of the members in this tuple
*/
public TupleType(Type[] elementTypes) {
assert elementTypes != null;
this.elementTypes = elementTypes.clone();
}

public boolean usesDimension(Dimension dimension, boolean maybe) {
public boolean usesDimension(Dimension dimension, boolean definitely) {
for (Type elementType : elementTypes) {
if (elementType.usesDimension(dimension, maybe)) {
if (elementType.usesDimension(dimension, definitely)) {
return true;
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/mondrian/olap/type/Type.java
Expand Up @@ -33,18 +33,21 @@ public interface Type {
* dimensions.</li>
* </ul><p/>
*
* The <code>maybe</code> parameter comes into play when the
* The <code>definitely</code> parameter comes into play when the
* dimensional information is incomplete. For example, when applied to
* <code>TupleType(MemberType(null), MemberType([Store]))</code>,
* <code>usesDimension([Gender], false)</code> returns true because it
* is possible that the expression returns a member of the
* <code>[Gender]</code> dimension; but
* <code>usesDimension([Gender], true)</code> returns true because it
* is possible that the expression returns a member of the
* <code>[Gender]</code> dimension.
*
* @param dimension Dimension
* @param maybe If true, returns true only if this type definitely
* @param definitely If true, returns true only if this type definitely
* uses the dimension
*/
boolean usesDimension(Dimension dimension, boolean maybe);
boolean usesDimension(Dimension dimension, boolean definitely);

/**
* Returns the dimension of this type, or null if not known.
Expand Down

0 comments on commit 6379ace

Please sign in to comment.