use of org.olap4j.Cell in project pentaho-kettle by pentaho.
the class CellSetFormatter method formatPage.
/**
* Formats a two-dimensional page.
*
* @param cellSet
* Cell set
* @param pw
* Print writer
* @param pageCoords
* Coordinates of page [page, chapter, section, ...]
* @param columnsAxis
* Columns axis
* @param columnsAxisInfo
* Description of columns axis
* @param rowsAxis
* Rows axis
* @param rowsAxisInfo
* Description of rows axis
*/
private Matrix formatPage(final CellSet cellSet, final int[] pageCoords, final CellSetAxis columnsAxis, final AxisInfo columnsAxisInfo, final CellSetAxis rowsAxis, final AxisInfo rowsAxisInfo) {
// Figure out the dimensions of the blank rectangle in the top left
// corner.
final int yOffset = columnsAxisInfo.getWidth();
final int xOffsset = rowsAxisInfo.getWidth();
// Populate a string matrix
final Matrix matrix = new Matrix(xOffsset + (columnsAxis == null ? 1 : columnsAxis.getPositions().size()), yOffset + (rowsAxis == null ? 1 : rowsAxis.getPositions().size()));
// Populate corner
for (int x = 0; x < xOffsset; x++) {
for (int y = 0; y < yOffset; y++) {
final MemberCell memberInfo = new MemberCell(false, x > 0);
matrix.set(x, y, memberInfo);
}
}
// Populate matrix with cells representing axes
// noinspection SuspiciousNameCombination
populateAxis(matrix, columnsAxis, columnsAxisInfo, true, xOffsset);
populateAxis(matrix, rowsAxis, rowsAxisInfo, false, yOffset);
// Populate cell values
for (final Cell cell : cellIter(pageCoords, cellSet)) {
final List<Integer> coordList = cell.getCoordinateList();
int x = xOffsset;
if (coordList.size() > 0) {
x += coordList.get(0);
}
int y = yOffset;
if (coordList.size() > 1) {
y += coordList.get(1);
}
final DataCell cellInfo = new DataCell(true, false);
for (int z = 0; z < matrix.getMatrixHeight(); z++) {
final AbstractBaseCell headerCell = matrix.get(x, z);
if (!(headerCell instanceof MemberCell && ((MemberCell) headerCell).getUniqueName() != null)) {
cellInfo.setParentColMember((MemberCell) matrix.get(x, z - 1));
break;
}
}
for (int z = 0; z < matrix.getMatrixWidth(); z++) {
final AbstractBaseCell headerCell = matrix.get(z, y);
if (!(headerCell instanceof MemberCell && ((MemberCell) headerCell).getUniqueName() != null)) {
cellInfo.setParentRowMember((MemberCell) matrix.get(z - 1, y));
break;
}
}
if (cell.getValue() != null) {
if (cell.getValue() instanceof Number) {
cellInfo.setRawNumber((Number) cell.getValue());
}
}
// First try to get a
String cellValue = cell.getFormattedValue();
if (cellValue == null || cellValue.equals("null")) {
cellValue = "";
}
if (cellValue.length() < 1) {
final Object value = cell.getValue();
if (value == null || value.equals("null")) {
cellValue = "";
} else {
try {
DecimalFormat myFormatter = new DecimalFormat("#,###.###");
String output = myFormatter.format(cell.getValue());
cellValue = output;
} catch (Exception e) {
// TODO: handle exception
}
}
// the raw value
}
cellInfo.setFormattedValue(getValueString(cellValue));
matrix.set(x, y, cellInfo);
}
return matrix;
}
use of org.olap4j.Cell in project mondrian by pentaho.
the class Olap4jTest method testCellProperties.
public void testCellProperties() throws SQLException {
final OlapConnection connection = getTestContext().getOlap4jConnection();
final CellSet cellSet = connection.createStatement().executeOlapQuery("with member [Customers].[USA].[CA WA] as\n" + " Aggregate({[Customers].[USA].[CA], [Customers].[USA].[WA]})\n" + "select [Measures].[Unit Sales] on 0,\n" + " {[Customers].[USA].[CA], [Customers].[USA].[CA WA]} on 1\n" + "from [Sales]\n" + "cell properties ACTION_TYPE, DRILLTHROUGH_COUNT");
final CellSetMetaData metaData = cellSet.getMetaData();
final Property actionTypeProperty = metaData.getCellProperties().get("ACTION_TYPE");
final Property drillthroughCountProperty = metaData.getCellProperties().get("DRILLTHROUGH_COUNT");
// Cell [0, 0] is drillable
final Cell cell0 = cellSet.getCell(0);
final int actionType0 = (Integer) cell0.getPropertyValue(actionTypeProperty);
// MDACTION_TYPE_DRILLTHROUGH
assertEquals(0x100, actionType0);
final int drill0 = (Integer) cell0.getPropertyValue(drillthroughCountProperty);
assertEquals(24442, drill0);
// Cell [0, 1] is not drillable
final Cell cell1 = cellSet.getCell(1);
final int actionType1 = (Integer) cell1.getPropertyValue(actionTypeProperty);
assertEquals(0x0, actionType1);
final int drill1 = (Integer) cell1.getPropertyValue(drillthroughCountProperty);
assertEquals(-1, drill1);
}
use of org.olap4j.Cell in project teiid by teiid.
the class OlapQueryExecution method next.
@Override
public List<?> next() throws TranslatorException {
if (!rowPositionIterator.hasNext()) {
return null;
}
Position rowPosition = rowPositionIterator.next();
Object[] result = new Object[colWidth];
int i = 0;
// add in rows axis
List<Member> members = rowPosition.getMembers();
for (Member member : members) {
String columnName = member.getName();
result[i++] = columnName;
}
// add col axis
for (Position colPos : columnsAxis) {
Cell cell = cellSet.getCell(colPos, rowPosition);
result[i++] = cell.getValue();
}
if (returnsArray) {
ArrayList<Object[]> results = new ArrayList<Object[]>(1);
results.add(result);
return results;
}
return Arrays.asList(result);
}
use of org.olap4j.Cell 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();
}
};
}
};
}
Aggregations