use of mondrian.calc.CalcWriter in project mondrian by pentaho.
the class Util method explain.
/**
* Called during major steps of executing a MDX query to provide insight into Calc calls/times
* and key function calls/times.
*
* @param handler
* @param title
* @param calc
* @param timing
*/
public static void explain(ProfileHandler handler, String title, Calc calc, QueryTiming timing) {
if (handler == null) {
return;
}
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
final CalcWriter calcWriter = new CalcWriter(printWriter, true);
printWriter.println(title);
if (calc != null) {
calc.accept(calcWriter);
}
printWriter.close();
handler.explain(stringWriter.toString(), timing);
}
use of mondrian.calc.CalcWriter in project mondrian by pentaho.
the class TestContext method compileExpression.
/**
* Compiles a scalar expression in the context of the default cube.
*
* @param expression The expression to evaluate
* @param scalar Whether the expression is scalar
* @return String form of the program
*/
public String compileExpression(String expression, final boolean scalar) {
String cubeName = getDefaultCubeName();
if (cubeName.indexOf(' ') >= 0) {
cubeName = Util.quoteMdxIdentifier(cubeName);
}
final String queryString;
if (scalar) {
queryString = "with member [Measures].[Foo] as " + Util.singleQuoteString(expression) + " select {[Measures].[Foo]} on columns from " + cubeName;
} else {
queryString = "SELECT {" + expression + "} ON COLUMNS FROM " + cubeName;
}
Connection connection = getConnection();
Query query = connection.parseQuery(queryString);
final Exp exp;
if (scalar) {
exp = query.getFormulas()[0].getExpression();
} else {
exp = query.getAxes()[0].getSet();
}
final Calc calc = query.compileExpression(exp, scalar, null);
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
final CalcWriter calcWriter = new CalcWriter(pw, false);
calc.accept(calcWriter);
pw.flush();
return sw.toString();
}
Aggregations