[Mondrian] Reg .MDX Query Result

Julian Hyde julianhyde at speakeasy.net
Fri Sep 28 12:43:53 EDT 2007


You need to work with the mondrian.olap.Result object, not the formatted
output. 
 
To give you an idea how the API works, take a look at the code that produced
your output. It is in ResultBase.java:
 
    public void print(PrintWriter pw) {
        for (int i = -1; i < axes.length; i++) {
            pw.println("Axis #" + (i + 1) + ":");
            printAxis(pw, i < 0 ? slicerAxis : axes[i]);
        }
        // Usually there are 3 axes: {slicer, columns, rows}. Position is a
        // {column, row} pair. We call printRows with axis=2. When it
recurses
        // to axis=-1, it prints.
        int[] pos = new int[axes.length];
        printRows(pw, axes.length - 1, pos);
    }

    private void printRows(PrintWriter pw, int axis, int[] pos) {
        Axis _axis = axis < 0 ? slicerAxis : axes[axis];
        List<Position> positions = _axis.getPositions();
        int i = 0;
        for (Position position: positions) {
            if (axis < 0) {
                if (i > 0) {
                    pw.print(", ");
                }
                printCell(pw, pos);
            } else {
                pos[axis] = i;
                if (axis == 0) {
                    int row = axis + 1 < pos.length ? pos[axis + 1] : 0;
                    pw.print("Row #" + row + ": ");
                }
                printRows(pw, axis - 1, pos);
                if (axis == 0) {
                    pw.println();
                }
            }
            i++;
        }
    }

    private void printAxis(PrintWriter pw, Axis axis) {
        List<Position> positions = axis.getPositions();
        for (Position position: positions) {
            boolean firstTime = true;
            pw.print("{");
            for (Member member: position) {
                if (! firstTime) {
                    pw.print(", ");
                }
                pw.print(member.getUniqueName());
                firstTime = false;
            }
            pw.println("}");
        }
    }

    private void printCell(PrintWriter pw, int[] pos) {
        Cell cell = getCell(pos);
        pw.print(cell.getFormattedValue());
    }

 
Something involving Result.getAxes(), Axis.getPositions(), and
Cell.getValue() should solve your problem. To get Double values, you may
need to cast the result of getValue(), like this: ((Number)
cell.getValue()).doubleValue().
 
Julian
 
 



  _____  

From: mondrian-bounces at pentaho.org [mailto:mondrian-bounces at pentaho.org] On
Behalf Of Smruti Naik
Sent: Thursday, September 27, 2007 11:45 PM
To: mondrian at pentaho.org
Subject: [Mondrian] Reg .MDX Query Result


Hello ,
 
I need to Insert MDX Query Result in Double Type Array List .
 
Suppose My Result is ,
Axis #0:
{}
Axis #1:
{[Measures].[Application Time]}
Axis #2:
{[Time].[2007].[Q3 ].[9].[12]}
{[Time].[2007].[Q3 ].[9].[13]}
{[Time].[2007].[Q3 ].[9].[14]}
{[Time].[2007].[Q3 ].[9].[15]}
{[Time].[2007].[Q3 ].[9].[16]} 
{[Time].[2007].[Q3 ].[9].[17]}
{[Time].[2007].[Q3 ].[9].[18]}
{[Time].[2007].[Q3 ].[9].[19]}
{[Time].[2007].[Q3 ].[9].[20]}
{[Time].[2007].[Q3 ].[9].[21]}
{[Time].[2007].[Q3 ].[9].[22]}
{[Time].[2007].[Q3 ].[9].[23]} 
{[Time].[2007].[Q3 ].[9].[24]}
{[Time].[2007].[Q3 ].[9].[25]}
{[Time].[2007].[Q3 ].[9].[26]}
{[Time].[2007].[Q3 ].[9].[27]}
Row #0: 1,337
Row #1: 936
Row #2: 971
Row #3:
Row #4:
Row #5: 4,272 
Row #6: 1,682
Row #7: 1,189
Row #8: 4,156
Row #9: 4,290
Row #10:
Row #11:
Row #12: 3,651
Row #13: 4,307
Row #14: 4,626
Row #15: 5,864
 
I wan to Insert this Row # to ArrayList . Can anyone please help me ? 
 
Regards,
Smruti

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.pentaho.org/pipermail/mondrian/attachments/20070928/7135033f/attachment.html 


More information about the Mondrian mailing list