Search in sources :

Example 36 with Axis

use of mondrian.olap.Axis in project pentaho-platform by pentaho.

the class MDXMetaData method createColumnNames.

/**
 * Flattens the row headers into column names (where the useful columns have useful names and the unuseful columns
 * have unusful names).
 *
 * @return the row headers in a String array
 */
protected String[] createColumnNames() {
    String[] colNames = null;
    if (nativeResultSet != null) {
        // HACK for BISERVER-2640; need backward compatibility to old format of column
        // names, yet with the old format cross joins will have problems (BISERVER-1266).
        Axis[] axes = nativeResultSet.getAxes();
        // Another IndexOOB Fix
        if ((axes.length <= MDXMetaData.AXIS_ROW) || (axes[MDXMetaData.AXIS_ROW] == null)) {
            // no rows...
            return new String[0];
        }
        List positions = axes[MDXMetaData.AXIS_ROW].getPositions();
        if (useExtendedColumnNames) {
            if ((this.rowHeaders.length > 0) && (positions != null) && (positions.size() > 0)) {
                colNames = new String[this.rowHeaders[0].length];
                // Flatten out the column headers into one column-name
                for (int i = 0; i < colNames.length; ++i) {
                    Member member = (Member) ((List) positions.get(0)).get(i);
                    colNames[i] = "[" + member.getDimension().getName() + "].[" + member.getHierarchy().getName() + "].[" + member.getLevel().getName() + "]";
                }
            } else {
                colNames = new String[0];
            }
        } else {
            if ((positions != null) && (positions.size() > 0)) {
                colNames = new String[getColumnCount()];
                // Flatten out the column headers into one column-name
                for (int i = 0; i < colNames.length; ++i) {
                    if (i < ((List) positions.get(0)).size()) {
                        Member member = (Member) ((List) positions.get(0)).get(i);
                        Hierarchy hierarchy = member.getHierarchy();
                        colNames[i] = hierarchy.getCaption();
                    } else {
                        colNames[i] = ((Member) ((List) positions.get(0)).get(((List) positions.get(0)).size() - 1)).getHierarchy().getName() + "{" + i + // $NON-NLS-1$ //$NON-NLS-2$
                        "}";
                    }
                }
            } else {
                colNames = new String[0];
            }
        }
    }
    return colNames;
}
Also used : Hierarchy(mondrian.olap.Hierarchy) List(java.util.List) Member(mondrian.olap.Member) Axis(mondrian.olap.Axis)

Example 37 with Axis

use of mondrian.olap.Axis in project pentaho-platform by pentaho.

the class MDXMetaDataTest method testMetadataForEmptyPositions.

@Test
public void testMetadataForEmptyPositions() {
    Axis axColumn = mockAxis(ListUtils.EMPTY_LIST);
    Axis axRow = mockAxis(ListUtils.EMPTY_LIST);
    Axis[] axes = new Axis[] { axColumn, axRow };
    Result nativeResultSet = mock(Result.class);
    when(nativeResultSet.getAxes()).thenReturn(axes);
    MDXMetaData metadata = new MDXMetaData(nativeResultSet);
    checkEmptyResult(metadata);
}
Also used : Axis(mondrian.olap.Axis) Result(mondrian.olap.Result) Test(org.junit.Test)

Example 38 with Axis

use of mondrian.olap.Axis in project pentaho-platform by pentaho.

the class MDXMetaDataTest method testGetColumnName.

@Test
@SuppressWarnings("rawtypes")
public void testGetColumnName() {
    List positions = mockPositions(COLUMN_SIZE, ROW_SIZE);
    Axis axColumn = mockAxis(positions);
    Axis axRow = mockAxis(positions);
    Axis[] axes = new Axis[] { axColumn, axRow };
    Result nativeResultSet = mock(Result.class);
    when(nativeResultSet.getAxes()).thenReturn(axes);
    MDXMetaData metadata = new MDXMetaData(nativeResultSet);
    String columnName = metadata.getColumnName(0);
    assertEquals(metadata.getRowHeaderNames()[0], columnName);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Axis(mondrian.olap.Axis) Result(mondrian.olap.Result) Test(org.junit.Test)

Aggregations

Axis (mondrian.olap.Axis)38 Result (mondrian.olap.Result)9 Position (mondrian.olap.Position)8 List (java.util.List)7 Member (mondrian.olap.Member)7 Test (org.junit.Test)7 Cell (mondrian.olap.Cell)6 ArrayList (java.util.ArrayList)5 TupleList (mondrian.calc.TupleList)4 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)4 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 Hierarchy (mondrian.olap.Hierarchy)2 RolapAxis (mondrian.rolap.RolapAxis)2 DBCacheEntry (org.pentaho.di.core.DBCacheEntry)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 RowMeta (org.pentaho.di.core.row.RowMeta)2 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)2 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)2