Search in sources :

Example 1 with CalcWriter

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);
}
Also used : StringWriter(java.io.StringWriter) CalcWriter(mondrian.calc.CalcWriter) PrintWriter(java.io.PrintWriter) QueryPrintWriter(mondrian.mdx.QueryPrintWriter)

Example 2 with CalcWriter

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();
}
Also used : Query(mondrian.olap.Query) StringWriter(java.io.StringWriter) CalcWriter(mondrian.calc.CalcWriter) OlapConnection(org.olap4j.OlapConnection) Connection(mondrian.olap.Connection) Calc(mondrian.calc.Calc) Exp(mondrian.olap.Exp) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 CalcWriter (mondrian.calc.CalcWriter)2 Calc (mondrian.calc.Calc)1 QueryPrintWriter (mondrian.mdx.QueryPrintWriter)1 Connection (mondrian.olap.Connection)1 Exp (mondrian.olap.Exp)1 Query (mondrian.olap.Query)1 OlapConnection (org.olap4j.OlapConnection)1