Skip to content

Commit

Permalink
MONDRIAN: Support for JPivot:
Browse files Browse the repository at this point in the history
 * Allow JPivot to set the slicer axis of a query;
 * Rename FunCall to ResolvedFunCall, and add FunCall as common interface for it and UnresolvedFunCall.

[git-p4: depot-paths = "//open/mondrian/": change = 4994]
  • Loading branch information
julianhyde committed Jan 9, 2006
1 parent 5aca340 commit 674aeb1
Show file tree
Hide file tree
Showing 35 changed files with 434 additions and 349 deletions.
5 changes: 3 additions & 2 deletions src/main/mondrian/calc/impl/AbstractCalc.java
Expand Up @@ -13,6 +13,7 @@
import mondrian.olap.type.Type;
import mondrian.calc.Calc;
import mondrian.calc.CalcWriter;
import mondrian.mdx.ResolvedFunCall;

import java.io.PrintWriter;
import java.util.List;
Expand Down Expand Up @@ -75,8 +76,8 @@ public void accept(CalcWriter calcWriter) {
*/
protected String getName() {
String name;
if (exp instanceof FunCall) {
FunCall funCall = (FunCall) exp;
if (exp instanceof ResolvedFunCall) {
ResolvedFunCall funCall = (ResolvedFunCall) exp;
name = funCall.getFunDef().getName();
} else {
name = getClass().getName();
Expand Down
149 changes: 149 additions & 0 deletions src/main/mondrian/mdx/ResolvedFunCall.java
@@ -0,0 +1,149 @@
/*
// $Id$
// 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 1998-2006 Kana Software, Inc. and others.
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/

package mondrian.mdx;
import mondrian.calc.Calc;
import mondrian.calc.ExpCompiler;
import mondrian.olap.type.Type;
import mondrian.olap.*;

import java.io.PrintWriter;

/**
* A <code>ResolvedFunCall</code> is a function applied to a list of operands,
* which has been validated and resolved to a
* {@link FunDef function definition}.
*
* @author jhyde
* @version $Id$
* @since Jan 6, 2006
*/
public class ResolvedFunCall extends ExpBase implements FunCall {

/**
* The arguments to the function call. Note that for methods, 0-th arg is
* 'this'.
*/
private final Exp[] args;

/**
* Return type of this function call.
*/
private final Type returnType;

/**
* Function definition.
*/
private final FunDef funDef;

/**
* Creates a function call.
*
* @param funDef Function definition
* @param args Arguments
* @param returnType Return type
*/
public ResolvedFunCall(FunDef funDef, Exp[] args, Type returnType) {
assert funDef != null;
assert args != null;
assert returnType != null;
this.funDef = funDef;
this.args = args;
this.returnType = returnType;
}

public String toString() {
return toMdx();
}

public Object clone() {
return new ResolvedFunCall(funDef, ExpBase.cloneArray(args), returnType);
}

/**
* Returns the Exp argument at the specified index.
*
* @param index the index of the Exp.
* @return the Exp at the specified index of this array of Exp.
* The first Exp is at index <code>0</code>.
* @see #getArgs()
*/
public Exp getArg(int index) {
return args[index];
}

/**
* Returns the internal array of Exp arguments.
*
* <p>Note: this does NOT do a copy.
*
* @return the array of expressions
*/
public Exp[] getArgs() {
return args;
}

/**
* Returns the number of arguments.
*
* @return number of arguments.
* @see #getArgs()
*/
public final int getArgCount() {
return args.length;
}

public String getFunName() {
return funDef.getName();
}

public Syntax getSyntax() {
return funDef.getSyntax();
}

public Object[] getChildren() {
return args;
}

public void replaceChild(int i, QueryPart with) {
args[i] = (Exp) with;
}

/**
* Returns the definition of the function which is being called.
*
* @return function definition
*/
public FunDef getFunDef() {
return funDef;
}

public final int getCategory() {
return funDef.getReturnCategory();
}

public final Type getType() {
return returnType;
}

public Exp accept(Validator validator) {
return this; // already validated
}

public void unparse(PrintWriter pw) {
funDef.unparse(args, pw);
}

public Calc accept(ExpCompiler compiler) {
return funDef.compileCall(this, compiler);
}
}

// End ResolvedFunCall.java
2 changes: 1 addition & 1 deletion src/main/mondrian/mdx/UnresolvedFunCall.java
Expand Up @@ -25,7 +25,7 @@
* @version $Id$
* @since Sep 28, 2005
*/
public class UnresolvedFunCall extends ExpBase implements Exp {
public class UnresolvedFunCall extends ExpBase implements FunCall {
private final String name;
private final Syntax syntax;
private final Exp[] args;
Expand Down
33 changes: 1 addition & 32 deletions src/main/mondrian/olap/ExpBase.java
Expand Up @@ -13,13 +13,12 @@
package mondrian.olap;
import mondrian.calc.Calc;
import mondrian.calc.ExpCompiler;
import mondrian.mdx.MemberExpr;

import java.io.PrintWriter;

/**
* Skeleton implementation of {@link Exp} interface.
**/
*/
public abstract class ExpBase
extends QueryPart
implements Exp {
Expand All @@ -38,36 +37,6 @@ protected ExpBase() {

public abstract Object clone();

/**
* Returns an array of {@link Member}s if this is a member or a tuple,
* null otherwise.
**/
public final Member[] isConstantTuple()
{
if (this instanceof MemberExpr) {
return new Member[] {((MemberExpr) this).getMember()};
}
if (!(this instanceof FunCall)) {
return null;
}
FunCall f = (FunCall) this;
if (f.getFunDef().getSyntax() != Syntax.Parentheses) {
return null;
}
// Make sure every Exp is a MemberExpr.
final Exp[] args = f.getArgs();
for (int i = 0; i < args.length; i++) {
if (!(args[i] instanceof MemberExpr)) {
return null;
}
}
Member[] members = new Member[args.length];
for (int i = 0; i < members.length; i++) {
members[i] = ((MemberExpr) args[i]).getMember();
}
return members;
}

public static void unparseList(PrintWriter pw, Exp[] exps, String start,
String mid, String end) {
pw.print(start);
Expand Down
132 changes: 30 additions & 102 deletions src/main/mondrian/olap/FunCall.java
Expand Up @@ -3,130 +3,58 @@
// 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 1998-2005 Kana Software, Inc. and others.
// (C) Copyright 1998-2006 Kana Software, Inc. and others.
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
// jhyde, 20 January, 1999
*/

package mondrian.olap;
import mondrian.calc.Calc;
import mondrian.calc.ExpCompiler;
import mondrian.olap.type.Type;

import java.io.PrintWriter;

/**
* A <code>FunCall</code> is a function applied to a list of operands.
**/
public class FunCall extends ExpBase {

/**
* The arguments to the function call. Note that for methods, 0-th arg is
* 'this'.
*/
private final Exp[] args;

* A <code>FunCall</code> is a function applied to a list of operands.<p/>
*
* The parser creates function calls as an
* {@link mondrian.mdx.UnresolvedFunCall unresolved function call}.
* The validator converts it to a
* {@link mondrian.mdx.ResolvedFunCall resolved function call},
* which has a {@link FunDef function definition} and extra type information.
*
* @author jhyde
* @version $Id$
* @since Jan 6, 2006
*/
public interface FunCall extends Exp {
/**
* Return type of this function call.
*/
private final Type returnType;

/**
* Function definition.
* Returns the <code>index</code><sup>th</sup> argument to this function
* call.
*
* @param index
* @return
*/
private final FunDef funDef;
Exp getArg(int index);

/**
* Creates a function call.
* Returns the arguments to this function.
*
* @param funDef Function definition
* @param args Arguments
* @param returnType Return type
* @return array of arguments
*/
public FunCall(FunDef funDef, Exp[] args, Type returnType) {
assert funDef != null;
assert args != null;
assert returnType != null;
this.funDef = funDef;
this.args = args;
this.returnType = returnType;
}

public String toString() {
return toMdx();
}

public Object clone() {
return new FunCall(funDef, ExpBase.cloneArray(args), returnType);
}
Exp[] getArgs();

/**
* Returns the Exp argument at the specified index.
* Returns the number of arguments to this function.
*
* @param index the index of the Exp.
* @return the Exp at the specified index of this array of Exp.
* The first Exp is at index <code>0</code>.
* @see #getArgs()
* @return number of arguments
*/
public Exp getArg(int index) {
return args[index];
}
int getArgCount();

/**
* Returns the internal array of Exp arguments.
*
* <p>Note: this does NOT do a copy.
*
* @return the array of expressions
* Returns the name of the function.
*/
public Exp[] getArgs() {
return args;
}
String getFunName();

/**
* Returns the number of arguments.
*
* @return number of arguments.
* @see #getArgs()
* Returns the syntax of the call.
*/
public final int getArgCount() {
return args.length;
}

public Object[] getChildren() {
return args;
}

public void replaceChild(int i, QueryPart with) {
args[i] = (Exp) with;
}

public FunDef getFunDef() {
return funDef;
}

public final int getCategory() {
return funDef.getReturnCategory();
}

public final Type getType() {
return returnType;
}

public Exp accept(Validator validator) {
return this; // already validated
}

public void unparse(PrintWriter pw) {
funDef.unparse(args, pw);
}

public Calc accept(ExpCompiler compiler) {
return funDef.compileCall(this, compiler);
}

Syntax getSyntax();
}

// End FunCall.java

0 comments on commit 674aeb1

Please sign in to comment.