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;
}
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);
}
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);
}
Aggregations