Skip to content

Commit

Permalink
MONDRIAN: Functions describe what reserved-words they need.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 3023]
  • Loading branch information
julianhyde committed Jan 2, 2005
1 parent 50650a6 commit d4106d7
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 97 deletions.
202 changes: 119 additions & 83 deletions src/main/mondrian/olap/fun/BuiltinFunTable.java

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/main/mondrian/olap/fun/DescendantsFunDef.java
Expand Up @@ -165,5 +165,9 @@ protected FunDef createFunDef(Exp[] args, FunDef dummyFunDef) {
return new DescendantsFunDef(dummyFunDef, flagFinal,
depthSpecifiedFinal, depthLimitFinal);
}

public String[] getReservedWords() {
return Flags.instance.getNames();
}
}
}
8 changes: 6 additions & 2 deletions src/main/mondrian/olap/fun/DrilldownMemberFunDef.java
Expand Up @@ -24,7 +24,7 @@
*/
class DrilldownMemberFunDef extends FunDefBase {
private final boolean recursive;
static final String[] reservedNames = new String[] {"RECURSIVE"};
static final String[] reservedWords = new String[] {"RECURSIVE"};

DrilldownMemberFunDef(FunDef funDef, boolean recursive) {
super(funDef);
Expand Down Expand Up @@ -130,10 +130,14 @@ public Resolver() {
}

protected FunDef createFunDef(Exp[] args, FunDef dummyFunDef) {
boolean recursive = getLiteralArg(args, 2, "", reservedNames,
boolean recursive = getLiteralArg(args, 2, "", reservedWords,
dummyFunDef).equals("RECURSIVE");
return new DrilldownMemberFunDef(dummyFunDef, recursive);
}

public String[] getReservedWords() {
return reservedWords;
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/mondrian/olap/fun/FunDefBase.java
Expand Up @@ -21,7 +21,7 @@
* @since 26 February, 2002
* @version $Id$
**/
class FunDefBase extends FunUtil implements FunDef {
public class FunDefBase extends FunUtil implements FunDef {
protected int flags;
private String name;
private String description;
Expand All @@ -39,7 +39,7 @@ class FunDefBase extends FunUtil implements FunDef {
this.returnType = returnType;
this.parameterTypes = parameterTypes;
}
FunDefBase(
protected FunDefBase(
String name, String signature, String description, String flags) {
this(name,
signature,
Expand Down Expand Up @@ -125,11 +125,11 @@ public boolean dependsOn(Exp[] args, Dimension dimension) {
return true;
return false;
}

/**
* computes the dependsOn() for functions like Tupel and Filter.
* The result of these functions depend on <code>dimension</dimension>
* if all of their arguments depend on it.
* if all of their arguments depend on it.
* <p>
* Derived classes may overload dependsOn() and call this method
* instead of the default implementation.
Expand Down
9 changes: 3 additions & 6 deletions src/main/mondrian/olap/fun/FunUtil.java
Expand Up @@ -24,8 +24,9 @@
**/
public class FunUtil extends Util {
static final String nl = System.getProperty("line.separator");
static final String[] emptyStringArray = new String[0];

public static RuntimeException newEvalException(
public static RuntimeException newEvalException(
FunDef funDef, String message) {
return new MondrianEvaluationException(message);
}
Expand Down Expand Up @@ -154,7 +155,7 @@ static BigDecimal getDecimalArg(Evaluator evaluator, Exp[] args, int index) {

private static final Double nullValue = new Double(0);

static Double getDoubleArg(Evaluator evaluator, Exp[] args, int index) {
protected static Double getDoubleArg(Evaluator evaluator, Exp[] args, int index) {
return getDoubleArg(evaluator, args, index, nullValue);
}

Expand Down Expand Up @@ -327,10 +328,6 @@ static void addUnique(List left, List right, Set set) {
}
}

static Boolean toBoolean(boolean b) {
return b ? Boolean.TRUE : Boolean.FALSE;
}

static List addMembers(SchemaReader schemaReader, List members, Hierarchy hierarchy) {
Level[] levels = schemaReader.getHierarchyLevels(hierarchy); // only accessible levels
for (int i = 0; i < levels.length; i++) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/mondrian/olap/fun/MultiResolver.java
Expand Up @@ -28,7 +28,7 @@ abstract class MultiResolver extends FunUtil implements Resolver {
String[] signatures;
Syntax syntax;

MultiResolver(String name, String signature, String description,
MultiResolver(String name, String signature, String description,
String[] signatures) {
this.name = name;
this.description = description;
Expand All @@ -49,6 +49,10 @@ public Syntax getSyntax() {
return syntax;
}

public String[] getReservedWords() {
return emptyStringArray;
}

public FunDef resolve(Exp[] args, int[] conversionCount) {
outer:
for (int j = 0; j < signatures.length; j++) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/mondrian/olap/fun/OrderFunDef.java
Expand Up @@ -48,6 +48,10 @@ public OrderResolver()
new String[]{"fxxvy", "fxxv"});
}

public String[] getReservedWords() {
return OrderFunDef.Flags.instance.getNames();
}

protected FunDef createFunDef(Exp[] args, FunDef dummyFunDef) {
int order = getLiteralArg(args, 2, Flags.ASC, Flags.instance, dummyFunDef);
final boolean desc = Flags.isDescending(order);
Expand Down
39 changes: 38 additions & 1 deletion src/main/mondrian/olap/fun/Resolver.java
Expand Up @@ -16,7 +16,7 @@
import mondrian.olap.Syntax;

/**
* A <code>Resolver</code> converts a function name, invokation type, and set
* A <code>Resolver</code> converts a function name, invocation type, and set
* of arguments into a {@link FunDef}.
*
* @author jhyde
Expand All @@ -25,8 +25,33 @@
**/
interface Resolver
{
/**
* Returns the name of the function or operator.
*/
String getName();

/**
* Returns the syntax with which the function or operator was invoked.
*/
Syntax getSyntax();

/**
* Given a particular set of arguments the function is applied to, returns
* the correct overloaded form of the function.
*
* <p>The method must increment <code>conversionCount</code> argument every
* time it performs an implicit type-conversion. If there are several
* candidate functions with the same signature, the validator will choose
* the one which used the fewest implicit conversions.
*
* @param args Expressions which this function call is applied to.
*
* @param conversionCount This argument must be an <code>int</code> array
* with a single element; in effect, it is an in/out parameter. It
* The method increments the count every time it performs a conversion.
*
* @return
*/
FunDef resolve(Exp[] args, int[] conversionCount);

/**
Expand All @@ -35,6 +60,18 @@ interface Resolver
* allows a set as its <code>k</code>th argument; true otherwise.
*/
boolean requiresExpression(int k);

/**
* Returns an array of symbolic constants which can appear as arguments
* to this function.
*
* <p>For example, the <code>DrilldownMember</code> may take the symbol
* <code>RECURSIVE</code> as an argument. Most functions do not define
* any symbolic constants.
*
* @return An array of the names of the symbolic constants
*/
String[] getReservedWords();
}


Expand Down
6 changes: 6 additions & 0 deletions src/main/mondrian/olap/fun/ResolverBase.java
Expand Up @@ -26,13 +26,15 @@ abstract class ResolverBase extends FunUtil implements Resolver {
final String signature;
final String description;
final Syntax syntax;

ResolverBase(String name, String signature, String description,
Syntax syntax) {
this.name = name;
this.signature = signature;
this.description = description;
this.syntax = syntax;
}

public String getName() {
return name;
}
Expand All @@ -44,6 +46,10 @@ public Syntax getSyntax() {
public boolean requiresExpression(int k) {
return false;
}

public String[] getReservedWords() {
return emptyStringArray;
}
}

// End ResolverBase.java
4 changes: 4 additions & 0 deletions src/main/mondrian/olap/fun/SimpleResolver.java
Expand Up @@ -36,6 +36,10 @@ public Syntax getSyntax() {
return funDef.getSyntax();
}

public String[] getReservedWords() {
return FunUtil.emptyStringArray;
}

public FunDef resolve(Exp[] args, int[] conversionCount) {
int[] parameterTypes = funDef.getParameterTypes();
if (parameterTypes.length != args.length) {
Expand Down

0 comments on commit d4106d7

Please sign in to comment.