Skip to content

Commit

Permalink
MONDRIAN: Fix '*' syntax of 'CrossJoin' operator.
Browse files Browse the repository at this point in the history
Various refactorings regarding function resolution.

[git-p4: depot-paths = "//open/mondrian/": change = 689]
  • Loading branch information
julianhyde committed Aug 5, 2003
1 parent e1ae54a commit 75f3c6a
Show file tree
Hide file tree
Showing 37 changed files with 954 additions and 866 deletions.
2 changes: 1 addition & 1 deletion src/main/mondrian/jolap/Converter.java
Expand Up @@ -128,7 +128,7 @@ Exp convert(MondrianDimensionView dimensionView, MondrianDimensionStepManager st
}

Exp convert(MondrianJolapDimension dimension) {
return new FunCall("Members", new Exp[] {dimension.dimension}, FunDef.TypeProperty);
return new FunCall("Members", Syntax.Property, new Exp[] {dimension.dimension});
}

}
Expand Down
18 changes: 9 additions & 9 deletions src/main/mondrian/jolap/MondrianAttributeFilter.java
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// (C) Copyright 2002 Kana Software, Inc. and others.
// (C) Copyright 2002-2003 Kana Software, Inc. and others.
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
Expand Down Expand Up @@ -48,12 +48,12 @@ Exp getCondition() throws OLAPException {
getDimensionStepManager().getDimensionView().getDimension();
return new FunCall(
getFunName(getOp()),
new Exp[] {
getFunSyntacticType(getOp()), new Exp[] {
new FunCall("CurrentMember",
new Exp[] {dimension.dimension},
FunDef.TypeProperty),
getExp(rhs)},
getFunSyntacticType(getOp()));
Syntax.Property, new Exp[] {dimension.dimension}
),
getExp(rhs)}
);
}

private Exp getExp(Object rhs) {
Expand Down Expand Up @@ -83,8 +83,8 @@ private String getFunName(OperatorType op) {
}
}

private int getFunSyntacticType(OperatorType op) {
return FunDef.TypeInfix;
private Syntax getFunSyntacticType(OperatorType op) {
return Syntax.Infix;
}

public OperatorType getOp() throws OLAPException {
Expand Down Expand Up @@ -112,4 +112,4 @@ public Attribute getAttribute() throws OLAPException {
}
}

// End MondrianAttributeFilter.java
// End MondrianAttributeFilter.java
54 changes: 0 additions & 54 deletions src/main/mondrian/olap/ElementCallback.java

This file was deleted.

15 changes: 13 additions & 2 deletions src/main/mondrian/olap/EnumeratedValues.java
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 1998-2003 Kana Software, Inc. and others.
// (C) Copyright 1998-2003 Kana Software, Inc. and others.
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
Expand Down Expand Up @@ -189,6 +189,17 @@ public final boolean isValid(int ordinal)
return true;
}

/**
* Returns the name associated with an ordinal; the return value
* is null if the ordinal is not a member of the enumeration.
*
* @pre isImmutable()
*/
public final Value getValue(int ordinal) {
Util.assertPrecondition(isImmutable());
return ordinalToValueMap[ordinal - min];
}

/**
* Returns the name associated with an ordinal; the return value
* is null if the ordinal is not a member of the enumeration.
Expand Down Expand Up @@ -233,7 +244,7 @@ public final int getOrdinal(String name) {
}

/**
* Returns the ordinal associated with a name.
* Returns the value associated with a name.
*
* @throws Error if the name is not a member of the enumeration
*/
Expand Down
24 changes: 21 additions & 3 deletions src/main/mondrian/olap/Exp.java
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// (C) Copyright 1999-2002 Kana Software, Inc. and others.
// (C) Copyright 1999-2003 Kana Software, Inc. and others.
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
Expand Down Expand Up @@ -57,8 +57,8 @@ public interface Exp {
**/
Dimension getDimension();
Hierarchy getHierarchy();
void unparse(PrintWriter pw, ElementCallback callback);
Exp resolve(Query q);
void unparse(PrintWriter pw);
Exp resolve(Resolver resolver);
boolean usesDimension(Dimension dimension);
/**
* Adds 'exp' as the right child of the CrossJoin whose left child has
Expand All @@ -69,6 +69,24 @@ public interface Exp {
int addAtPosition(Exp e, int iPosition);
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();
}
}

// End Exp.java
85 changes: 10 additions & 75 deletions src/main/mondrian/olap/ExpBase.java
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 1999-2003 Kana Software, Inc. and others.
// (C) Copyright 1999-2003 Kana Software, Inc. and others.
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
Expand Down Expand Up @@ -94,7 +94,7 @@ public final boolean isEmptySet()
{
if (this instanceof FunCall) {
FunCall f = (FunCall) this;
return f.getSyntacticType() == FunDef.TypeBraces &&
return f.getSyntax() == Syntax.Braces &&
f.args.length == 0;
} else {
return false;
Expand Down Expand Up @@ -135,20 +135,19 @@ protected static boolean arrayUsesDimension(Exp[] exps, Dimension dim)
return false;
}

public int addAtPosition(Exp e, int iPosition)
{
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
// 1. We therefore return 1 to indicate that we could not add the
// expression, and that this expression has a dimensionality of 1.
return 1;
}
public Object evaluate(Evaluator evaluator)
{

public Object evaluate(Evaluator evaluator) {
throw new Error("unsupported");
}
public Object evaluateScalar(Evaluator evaluator)
{

public Object evaluateScalar(Evaluator evaluator) {
Object o = evaluate(evaluator);
if (o instanceof Member) {
evaluator.setContext((Member) o);
Expand All @@ -161,78 +160,14 @@ public Object evaluateScalar(Evaluator evaluator)
}
}

public static String getSignature(
String name, int syntacticType, int returnType, int[] argTypes) {
switch (syntacticType) {
case FunDef.TypeInfix:
// e.g. "<Numeric Expression> / <Numeric Expression>"
return getTypeDescription(argTypes[0]) + " " + name + " " +
getTypeDescription(argTypes[1]);
case FunDef.TypePrefix:
// e.g. "- <Numeric Expression>"
return name + " " + getTypeDescription(argTypes[0]);
case FunDef.TypeProperty:
// e.g. "<Set>.Current"
return getTypeDescription(argTypes[0]) + "." + name;
case FunDef.TypeFunction:
case FunDef.TypeInternal:
// e.g. "StripCalculatedMembers(<Set>)"
return (returnType == Category.Unknown ? "" :
getTypeDescription(returnType) + " ") +
name + "(" + getTypeDescriptionCommaList(argTypes, 0) +
")";
case FunDef.TypeMethod:
// e.g. "<Member>.Lead(<Numeric Expression>)"
return (returnType == Category.Unknown ? "" :
getTypeDescription(returnType) + " ") +
getTypeDescription(argTypes[0]) + "." +
name + "(" + getTypeDescriptionCommaList(argTypes, 1) +
")";
case FunDef.TypeBraces:
return "{" + getTypeDescriptionCommaList(argTypes, 0) + "}";
case FunDef.TypeParentheses:
return "(" + getTypeDescriptionCommaList(argTypes, 0) + ")";
case FunDef.TypeCase:
String s = getTypeDescription(argTypes[0]);
if (argTypes[0] == Category.Logical) {
return "CASE WHEN " + s + " THEN <Expression> ... END";
} else {
return "CASE " + s + " WHEN " + s + " THEN <Expression> ... END";
}
default:
throw Util.newInternal("unknown syntactic type " + syntacticType);
}
}

private static String getTypeDescription(int type) {
return "<" + Category.instance.getDescription(type & Category.Mask) + ">";
}

private static String getTypeDescriptionCommaList(int[] types, int start)
{
int initialSize = (types.length - start) * 16;
StringBuffer sb = new StringBuffer(initialSize > 0 ? initialSize : 16);
for (int i = start; i < types.length; i++) {
if (i > start) {
sb.append(", ");
}
sb.append("<")
.append(Category.instance.getDescription(types[i] & Category.Mask))
.append(">");
}
return sb.toString();
}

public static void unparseList(
PrintWriter pw, Exp[] exps, String start, String mid, String end,
ElementCallback callback)
{
public static void unparseList(PrintWriter pw, Exp[] exps, String start,
String mid, String end) {
pw.print(start);
for (int i = 0; i < exps.length; i++) {
if (i > 0) {
pw.print(mid);
}
exps[i].unparse(pw, callback);
exps[i].unparse(pw);
}
pw.print(end);
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/mondrian/olap/Formula.java
Expand Up @@ -70,10 +70,10 @@ static Formula[] cloneArray(Formula[] x)

/**
* Resolves identifiers into objects.
* @param q The query which contains this formula.
* @param resolver The query which contains this formula.
*/
void resolve(Query q) {
exp = (ExpBase) exp.resolve(q);
void resolve(Exp.Resolver resolver) {
exp = (ExpBase) resolver.resolveChild(exp);
String id = Util.quoteMdxIdentifier(names);
if (isMember) {
if (!(!exp.isSet() ||
Expand All @@ -86,7 +86,7 @@ void resolve(Query q) {
}
}
for (int i = 0; i < memberProperties.length; i++) {
memberProperties[i].resolve(q);
resolver.resolveChild(memberProperties[i]);
}
// Get the format expression from the property list, or derive it from
// the formula.
Expand Down Expand Up @@ -148,22 +148,22 @@ public void replaceChild(int ordinal, QueryPart with)
exp = (ExpBase) with;
}

public void unparse(PrintWriter pw, ElementCallback callback)
public void unparse(PrintWriter pw)
{
if (isMember) {
pw.print("member ");
mdxMember.unparse(pw, callback);
mdxMember.unparse(pw);
} else {
pw.print("set ");
pw.print(Util.quoteMdxIdentifier(names));
}
pw.print(" as '");
exp.unparse(pw, callback);
exp.unparse(pw);
pw.print("'");
if (memberProperties != null) {
for (int i = 0; i < memberProperties.length; i++) {
pw.print(", ");
memberProperties[i].unparse(pw, callback);
memberProperties[i].unparse(pw);
}
}
}
Expand Down

0 comments on commit 75f3c6a

Please sign in to comment.