Search in sources :

Example 1 with CellSetAxis

use of org.olap4j.CellSetAxis in project pentaho-kettle by pentaho.

the class CellSetFormatter method format.

public Matrix format(final CellSet cellSet) {
    // Compute how many rows are required to display the columns axis.
    final CellSetAxis columnsAxis;
    if (cellSet.getAxes().size() > 0) {
        columnsAxis = cellSet.getAxes().get(0);
    } else {
        columnsAxis = null;
    }
    final AxisInfo columnsAxisInfo = computeAxisInfo(columnsAxis);
    // Compute how many columns are required to display the rows axis.
    final CellSetAxis rowsAxis;
    if (cellSet.getAxes().size() > 1) {
        rowsAxis = cellSet.getAxes().get(1);
    } else {
        rowsAxis = null;
    }
    final AxisInfo rowsAxisInfo = computeAxisInfo(rowsAxis);
    if (cellSet.getAxes().size() > 2) {
        final int[] dimensions = new int[cellSet.getAxes().size() - 2];
        for (int i = 2; i < cellSet.getAxes().size(); i++) {
            final CellSetAxis cellSetAxis = cellSet.getAxes().get(i);
            dimensions[i - 2] = cellSetAxis.getPositions().size();
        }
        for (final int[] pageCoords : CoordinateIterator.iterate(dimensions)) {
            matrix = formatPage(cellSet, pageCoords, columnsAxis, columnsAxisInfo, rowsAxis, rowsAxisInfo);
        }
    } else {
        matrix = formatPage(cellSet, new int[] {}, columnsAxis, columnsAxisInfo, rowsAxis, rowsAxisInfo);
    }
    return matrix;
}
Also used : CellSetAxis(org.olap4j.CellSetAxis)

Example 2 with CellSetAxis

use of org.olap4j.CellSetAxis in project teiid by teiid.

the class OlapQueryExecution method execute.

@Override
public void execute() throws TranslatorException {
    try {
        stmt = this.connection.createStatement();
        cellSet = stmt.executeOlapQuery(mdxQuery);
        CellSetAxis rowAxis = this.cellSet.getAxes().get(Axis.ROWS.axisOrdinal());
        rowPositionIterator = rowAxis.iterator();
        columnsAxis = cellSet.getAxes().get(Axis.COLUMNS.axisOrdinal());
        colWidth = rowAxis.getAxisMetaData().getHierarchies().size() + this.columnsAxis.getPositions().size();
    } catch (SQLException e) {
        throw new TranslatorException(e);
    }
}
Also used : CellSetAxis(org.olap4j.CellSetAxis) SQLException(java.sql.SQLException) TranslatorException(org.teiid.translator.TranslatorException)

Example 3 with CellSetAxis

use of org.olap4j.CellSetAxis in project pentaho-kettle by pentaho.

the class CellSetFormatter method cellIter.

/**
 * Returns an iterator over cells in a result.
 */
private static Iterable<Cell> cellIter(final int[] pageCoords, final CellSet cellSet) {
    return new Iterable<Cell>() {

        public Iterator<Cell> iterator() {
            final int[] axisDimensions = new int[cellSet.getAxes().size() - pageCoords.length];
            assert pageCoords.length <= axisDimensions.length;
            for (int i = 0; i < axisDimensions.length; i++) {
                final CellSetAxis axis = cellSet.getAxes().get(i);
                axisDimensions[i] = axis.getPositions().size();
            }
            final CoordinateIterator coordIter = new CoordinateIterator(axisDimensions, true);
            return new Iterator<Cell>() {

                public boolean hasNext() {
                    return coordIter.hasNext();
                }

                public Cell next() {
                    final int[] ints = coordIter.next();
                    final AbstractList<Integer> intList = new AbstractList<Integer>() {

                        @Override
                        public Integer get(final int index) {
                            return index < ints.length ? ints[index] : pageCoords[index - ints.length];
                        }

                        @Override
                        public int size() {
                            return pageCoords.length + ints.length;
                        }
                    };
                    return cellSet.getCell(intList);
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
Also used : AbstractList(java.util.AbstractList) CoordinateIterator(org.olap4j.impl.CoordinateIterator) CellSetAxis(org.olap4j.CellSetAxis) Iterator(java.util.Iterator) CoordinateIterator(org.olap4j.impl.CoordinateIterator) Cell(org.olap4j.Cell)

Aggregations

CellSetAxis (org.olap4j.CellSetAxis)3 SQLException (java.sql.SQLException)1 AbstractList (java.util.AbstractList)1 Iterator (java.util.Iterator)1 Cell (org.olap4j.Cell)1 CoordinateIterator (org.olap4j.impl.CoordinateIterator)1 TranslatorException (org.teiid.translator.TranslatorException)1