Skip to content

Commit

Permalink
MONDRIAN: Better type-checking. Add a new method getTypeX(), which re…
Browse files Browse the repository at this point in the history
…turns a more descriptive type, for example 'A set of members of the [Store] hierarchy'. The getType() method has been renamed to getCategory(); getType() still exists, but is deprecated.

Improve the performance of FastBatchingCellReader.recordCellRequest(), by using a more efficient ArrayList.hashCode().

[git-p4: depot-paths = "//open/mondrian/": change = 3342]
  • Loading branch information
julianhyde committed Mar 12, 2005
1 parent 3645aa7 commit 2f105ee
Show file tree
Hide file tree
Showing 61 changed files with 4,107 additions and 3,204 deletions.
15 changes: 11 additions & 4 deletions src/main/mondrian/olap/CubeBase.java
Expand Up @@ -12,6 +12,9 @@

package mondrian.olap;

import mondrian.olap.type.Type;
import mondrian.olap.type.CubeType;

/**
* <code>CubeBase</code> is an abstract implementation of {@link Cube}.
*
Expand Down Expand Up @@ -64,6 +67,10 @@ public String getQualifiedName() {
return Util.getRes().getMdxCubeName(getName());
}

public Dimension getDimension() {
return null;
}

public Hierarchy getHierarchy() {
return null;
}
Expand All @@ -76,12 +83,12 @@ public Cube getCube() {
return this;
}

public int getType() {
public int getCategory() {
return Category.Cube;
}

public boolean usesDimension(Dimension dimension) {
return false;
public Type getTypeX() {
return new CubeType(this);
}

public Dimension[] getDimensions() {
Expand All @@ -98,7 +105,7 @@ public Hierarchy lookupHierarchy(String s, boolean unique) {
Hierarchy[] hierarchies = dimension.getHierarchies();
for (int j = 0; j < hierarchies.length; j++) {
Hierarchy hierarchy = hierarchies[j];
String name = unique
String name = unique
? hierarchy.getUniqueName() : hierarchy.getName();
if (name.equals(s)) {
return hierarchy;
Expand Down
58 changes: 40 additions & 18 deletions src/main/mondrian/olap/DimensionBase.java
Expand Up @@ -12,11 +12,13 @@

package mondrian.olap;

import mondrian.olap.type.Type;

import java.util.List;
import java.util.ArrayList;

/**
* todo:
* Abstract implementation for a {@link Dimension}.
*
* @author jhyde
* @since 6 August, 2001
Expand All @@ -33,40 +35,60 @@ public abstract class DimensionBase
protected Hierarchy[] hierarchies;
protected DimensionType dimensionType;

protected DimensionBase(String name,
String uniqueName,
String description,
int globalOrdinal,
DimensionType dimensionType) {
this.name = name;
protected DimensionBase(
String name,
String uniqueName,
String description,
int globalOrdinal,
DimensionType dimensionType)
{
this.name = name;
this.uniqueName = Util.makeFqName(name);
this.description = null;
this.globalOrdinal = globalOrdinal;
this.dimensionType = dimensionType;
}

// implement Element
public String getUniqueName() {
return uniqueName;
}
public String getName() {
return name;

public String getName() {
return name;
}

public String getDescription() {
return description;
}
public String getDescription() {
return description;

public Hierarchy[] getHierarchies() {
return hierarchies;
}

public Hierarchy getHierarchy() {
return hierarchies[0];
}
public Hierarchy[] getHierarchies() {
return hierarchies;

public Dimension getDimension() {
return this;
}
public int getType() {

public int getCategory() {
return Category.Dimension;
}
public DimensionType getDimensionType() {
return dimensionType;

public Type getTypeX() {
return new mondrian.olap.type.DimensionType(this);
}

public DimensionType getDimensionType() {
return dimensionType;
}

public String getQualifiedName() {
return Util.getRes().getMdxDimensionName(getUniqueName());
}

public boolean isMeasures() {
return getUniqueName().equals(MEASURES_UNIQUE_NAME);
}
Expand All @@ -86,7 +108,7 @@ public OlapElement lookupChild(SchemaReader schemaReader, String s) {
oe = getHierarchy().lookupChild(schemaReader, s);
}

if (getLogger().isDebugEnabled()) {
if (getLogger().isDebugEnabled()) {
StringBuffer buf = new StringBuffer(64);
buf.append("DimensionBase.lookupChild: ");
buf.append("name=");
Expand Down
77 changes: 12 additions & 65 deletions src/main/mondrian/olap/Exp.java
Expand Up @@ -12,6 +12,7 @@

package mondrian.olap;

import mondrian.olap.type.Type;
import java.io.PrintWriter;

/**
Expand All @@ -25,8 +26,18 @@ public interface Exp {
* Returns the {@link Category} of the expression.
* @post Category.instance().isValid(return)
**/
int getCategory();

/**
* @deprecated Use {@link #getCategory()}
**/
int getType();

/**
* Returns the type of this expression. Never null.
*/
Type getTypeX();

boolean isSet();

boolean isMember();
Expand All @@ -35,41 +46,9 @@ public interface Exp {

boolean isEmptySet();

/**
* Returns the dimension of a this expression, or null if no dimension is
* defined. Applicable only to set expressions.
*
* <p>Example 1:
* <blockquote><pre>
* [Sales].children
* </pre></blockquote>
* has dimension <code>[Sales]</code>.</p>
*
* <p>Example 2:
* <blockquote><pre>
* order(except([Promotion Media].[Media Type].members,
* {[Promotion Media].[Media Type].[No Media]}),
* [Measures].[Unit Sales], DESC)
* </pre></blockquote>
* has dimension [Promotion Media].</p>
*
* <p>Example 3:
* <blockquote><pre>
* CrossJoin([Product].[Product Department].members,
* [Gender].members)
* </pre></blockquote>
* has no dimension (well, actually it is [Product] x [Gender], but we
* can't represent that, so we return null);</p>
**/
Dimension getDimension();

Hierarchy getHierarchy();

void unparse(PrintWriter pw);

Exp resolve(Resolver resolver);

boolean usesDimension(Dimension dimension);
Exp resolve(Validator resolver);

/**
* true means that the result of this expression will be different
Expand All @@ -95,38 +74,6 @@ public interface Exp {
Object evaluate(Evaluator evaluator);

Object evaluateScalar(Evaluator evaluator);

/**
* Provides context necessary to resolve identifiers to objects, function
* calls to specific functions.
*
* <p>An expression calls {@link #resolveChild} on each of its children,
* which in turn calls {@link Exp#resolve}.
*/
interface Resolver {

Query getQuery();

Exp resolveChild(Exp exp);

Parameter resolveChild(Parameter parameter);

void resolveChild(MemberProperty memberProperty);

void resolveChild(QueryAxis axis);

void resolveChild(Formula formula);

boolean requiresExpression();

FunTable getFunTable();

/**
* Creates or retrieves the parameter corresponding to a "Parameter" or
* "ParamRef" function call.
*/
Parameter createOrLookupParam(FunCall call);
}
}

// End Exp.java
70 changes: 19 additions & 51 deletions src/main/mondrian/olap/ExpBase.java
Expand Up @@ -11,6 +11,8 @@
*/

package mondrian.olap;
import mondrian.olap.type.Type;

import java.io.PrintWriter;

/**
Expand All @@ -34,52 +36,17 @@ protected ExpBase() {

public abstract Object clone();

/**
* Returns the dimension of a this expression, or null if no dimension is
* defined. Applicable only to set expressions.
*
* <p>Example 1:
* <blockquote><pre>
* [Sales].children
* </pre></blockquote>
* has dimension <code>[Sales]</code>.</p>
*
* <p>Example 2:
* <blockquote><pre>
* order(except([Promotion Media].[Media Type].members,
* {[Promotion Media].[Media Type].[No Media]}),
* [Measures].[Unit Sales], DESC)
* </pre></blockquote>
* has dimension [Promotion Media].</p>
*
* <p>Example 3:
* <blockquote><pre>
* CrossJoin([Product].[Product Department].members,
* [Gender].members)
* </pre></blockquote>
* has no dimension (well, actually it is [Product] x [Gender], but we
* can't represent that, so we return null);</p>
**/
public Dimension getDimension() {
Hierarchy mdxHierarchy = getHierarchy();
return (mdxHierarchy == null) ? null : mdxHierarchy.getDimension();
}

public Hierarchy getHierarchy() {
return null;
}

public final boolean isSet() {
int cat = getType();
int cat = getCategory();
return (cat == Category.Set) || (cat == Category.Tuple);
}

public final boolean isMember() {
return (getType() == Category.Member);
return getCategory() == Category.Member;
}

public final boolean isElement() {
int category = getType();
int category = getCategory();
return isMember() ||
(category == Category.Hierarchy) ||
(category == Category.Level) ||
Expand All @@ -90,7 +57,7 @@ public final boolean isEmptySet()
{
if (this instanceof FunCall) {
FunCall f = (FunCall) this;
return (f.getSyntax() == Syntax.Braces) &&
return (f.getSyntax() == Syntax.Braces) &&
(f.getArgLength() == 0);
} else {
return false;
Expand Down Expand Up @@ -126,15 +93,6 @@ public final Member[] isConstantTuple()
return members;
}

protected static boolean arrayUsesDimension(Exp[] exps, Dimension dim)
{
for (int i = 0; i < exps.length; i++)
if (exps[i].usesDimension(dim)) {
return true;
}
return false;
}

public int addAtPosition(Exp e, int iPosition) {
// Since this method has not been overridden for this type of
// expression, we presume that the expression has a dimensionality of
Expand Down Expand Up @@ -175,17 +133,27 @@ public static void unparseList(PrintWriter pw, Exp[] exps, String start,
public static int[] getTypes(Exp[] exps) {
int[] types = new int[exps.length];
for (int i = 0; i < exps.length; i++) {
types[i] = exps[i].getType();
types[i] = exps[i].getCategory();
}
return types;
}

/**
* A simple and incomplete default implementation for dependsOn().
* A simple and incomplete default implementation for
* {@link Exp#dependsOn(Dimension)}.
* It assumes that a dimension, that is used somewhere in the expression
* makes the whole expression independent of that dimension.
*/
public boolean dependsOn(Dimension dimension) {
return !usesDimension(dimension);
final Type type = getTypeX();
return !type.usesDimension(dimension);
}

/**
* @deprecated Use {@link #getCategory()}
**/
public int getType() {
return getCategory();
}
}

Expand Down

0 comments on commit 2f105ee

Please sign in to comment.