Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MONDRIAN: Implement ValidMeasure function (contributed by Matthew Cam…
…pbell); factor out SetToStr and TupleToStr functions into their own files. [git-p4: depot-paths = "//open/mondrian/": change = 7329]
- Loading branch information
1 parent
6a00fc6
commit 04ec7fb
Showing
6 changed files
with
348 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
// $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. | ||
// Copyright (C) 2006-2006 Julian Hyde | ||
// All Rights Reserved. | ||
// You must accept the terms of that agreement to use this software. | ||
*/ | ||
package mondrian.olap.fun; | ||
|
||
import mondrian.calc.Calc; | ||
import mondrian.calc.ExpCompiler; | ||
import mondrian.calc.ListCalc; | ||
import mondrian.calc.impl.AbstractStringCalc; | ||
import mondrian.mdx.ResolvedFunCall; | ||
import mondrian.olap.Evaluator; | ||
import mondrian.olap.Member; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Definition of the <code>SetToStr</code> MDX function. | ||
* | ||
* @author jhyde | ||
* @version $Id$ | ||
* @since Aug 3, 2006 | ||
*/ | ||
class SetToStrFunDef extends FunDefBase { | ||
public static final FunDefBase instance = new SetToStrFunDef(); | ||
|
||
private SetToStrFunDef() { | ||
super("SetToStr", "SetToStr(<Set>)", "Constructs a string from a set.", "fSx"); | ||
} | ||
|
||
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) { | ||
final ListCalc listCalc = | ||
compiler.compileList(call.getArg(0)); | ||
return new AbstractStringCalc(call, new Calc[] {listCalc}) { | ||
public String evaluateString(Evaluator evaluator) { | ||
final List list = listCalc.evaluateList(evaluator); | ||
return strToSet(list); | ||
} | ||
}; | ||
} | ||
|
||
static String strToSet(List list) { | ||
StringBuffer buf = new StringBuffer(); | ||
buf.append("{"); | ||
for (int i = 0; i < list.size(); i++) { | ||
if (i > 0) { | ||
buf.append(", "); | ||
} | ||
final Object o = list.get(i); | ||
appendMemberOrTuple(buf, o); | ||
} | ||
buf.append("}"); | ||
return buf.toString(); | ||
} | ||
|
||
static void appendMemberOrTuple( | ||
StringBuffer buf, | ||
Object memberOrTuple) { | ||
if (memberOrTuple instanceof Member) { | ||
Member member = (Member) memberOrTuple; | ||
buf.append(member.getUniqueName()); | ||
} else { | ||
Member[] members = (Member[]) memberOrTuple; | ||
appendTuple(buf, members); | ||
} | ||
} | ||
} | ||
|
||
// End SetToStrFunDef.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
// $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. | ||
// Copyright (C) 2006-2006 Julian Hyde | ||
// All Rights Reserved. | ||
// You must accept the terms of that agreement to use this software. | ||
*/ | ||
package mondrian.olap.fun; | ||
|
||
import mondrian.calc.Calc; | ||
import mondrian.calc.ExpCompiler; | ||
import mondrian.calc.MemberCalc; | ||
import mondrian.calc.TupleCalc; | ||
import mondrian.calc.impl.AbstractStringCalc; | ||
import mondrian.mdx.ResolvedFunCall; | ||
import mondrian.olap.type.TypeUtil; | ||
import mondrian.olap.Evaluator; | ||
import mondrian.olap.Member; | ||
|
||
/** | ||
* Definition of the <code>TupleToStr</code> MDX function. | ||
* | ||
* @author jhyde | ||
* @version $Id$ | ||
* @since Aug 3, 2006 | ||
*/ | ||
class TupleToStrFunDef extends FunDefBase { | ||
static final TupleToStrFunDef instance = new TupleToStrFunDef(); | ||
|
||
private TupleToStrFunDef() { | ||
super("TupleToStr", "TupleToStr(<Tuple>)", "Constructs a string from a tuple.", "fSt"); | ||
} | ||
|
||
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) { | ||
if (TypeUtil.couldBeMember(call.getArg(0).getType())) { | ||
final MemberCalc memberCalc = | ||
compiler.compileMember(call.getArg(0)); | ||
return new AbstractStringCalc(call, new Calc[] {memberCalc}) { | ||
public String evaluateString(Evaluator evaluator) { | ||
final Member member = | ||
memberCalc.evaluateMember(evaluator); | ||
if (member.isNull()) { | ||
return ""; | ||
} | ||
StringBuffer buf = new StringBuffer(); | ||
buf.append(member.getUniqueName()); | ||
return buf.toString(); | ||
} | ||
}; | ||
} else { | ||
final TupleCalc tupleCalc = | ||
compiler.compileTuple(call.getArg(0)); | ||
return new AbstractStringCalc(call, new Calc[] {tupleCalc}) { | ||
public String evaluateString(Evaluator evaluator) { | ||
final Member[] members = | ||
tupleCalc.evaluateTuple(evaluator); | ||
if (members == null) { | ||
return ""; | ||
} | ||
StringBuffer buf = new StringBuffer(); | ||
SetToStrFunDef.appendTuple(buf, members); | ||
return buf.toString(); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
} | ||
|
||
// End TupleToStrFunDef.java |
Oops, something went wrong.