mondrian.olap.Position Java Examples

The following examples show how to use mondrian.olap.Position. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CubeService.java    From youkefu with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param axes
 * @param axis
 * @param pos
 * @param result
 * @param dataList
 * @param rowno
 */
private void getRowData(Axis[] axes, int axis, int[] pos, Result result, List<List<ValueData>> dataList, int rowno , Position position , CubeReportData cubeData , List<ColumnProperties> cols) {
	if (axis < 0) {
		if (dataList.size() <= rowno || dataList.get(rowno) == null) {
			dataList.add(new ArrayList<ValueData>());
		}
		Cell cell = result.getCell(pos) ;
		ValueData valueData  = new ValueData(cell.getValue(), cell.getFormattedValue(), null  , cell.canDrillThrough(), cell.getDrillThroughSQL(true) , position!=null && position.size()>0 ? position.get(position.size()-1).getName():"" , cell.getCachedFormatString() , cols) ;
		int rows = 0 ;
		valueData.setRow(getParentLevel(cubeData.getRow() , rowno, rows)) ;
		dataList.get(rowno).add(valueData);
	} else {
		Axis _axis = axes[axis];
		List<Position> positions = _axis.getPositions();
		for (int i = 0; i < positions.size(); i++) {
			Position posit = positions.get(i) ;
			pos[axis] = i;
			if (axis == 0) {
				int row = axis + 1 < pos.length ? pos[axis + 1] : 0;
				rowno = row;
			}
			getRowData(axes, axis - 1, pos, result, dataList, rowno , posit , cubeData , cols);
		}
	}
}
 
Example #2
Source File: JRMondrianAxis.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
public JRMondrianAxis(Axis axis, Hierarchy[] axisHierarchies, JRMondrianFactory factory)
{
	List<Position> positions = axis.getPositions();
	tuples = new JRMondrianTuple[positions.size()];
	
	int idx = 0;
	for (Iterator<Position> it = positions.iterator(); it.hasNext(); ++idx)
	{
		Position position = it.next();
		tuples[idx] = new JRMondrianTuple(position, factory);
	}
	
	hierarchies = new JRMondrianHierarchy[axisHierarchies.length];
	for (int i = 0; i < axisHierarchies.length; i++)
	{
		hierarchies[i] = new JRMondrianHierarchy(axisHierarchies[i]);
	}
}
 
Example #3
Source File: BandedMDXTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected List<String> computeColumnNames( final Axis[] axes,
                                           final List<Member> columnToMemberMapper ) {
  ArrayList<String> columnNames = new ArrayList<String>();
  for ( final Member member : columnToMemberMapper ) {
    columnNames.add( member.getLevel().getUniqueName() );
  }
  if ( axes.length > 0 ) {
    // now create the column names for the column-axis
    final Axis axis = axes[ 0 ];
    final List<Position> positions = axis.getPositions();
    for ( int i = 0; i < positions.size(); i++ ) {
      final Position position = positions.get( i );
      columnNames.add( ResultSetProcessingLib.computeUniqueColumnName( position ) );
    }
  } else {
    columnNames.add( "Measure" );
  }
  return Collections.unmodifiableList( columnNames );
}
 
Example #4
Source File: BandedMDXTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Member getCandidateMembers( final int columnIndex,
                                    final int[] cellKey ) {

  final int axisIndex = columnToAxisPosition.get( columnIndex );
  final Axis[] axes = resultSet.getAxes();
  final Axis axis = axes[ axisIndex ];

  final List<Position> positionList = axis.getPositions();
  if ( positionList.isEmpty() ) {
    return null;
  }

  final int posIndex = cellKey[ axisIndex ];
  final Position position = positionList.get( posIndex );

  final Member memberByName = findMemberByName( position, columnIndex );
  if ( memberByName != null ) {
    return memberByName;
  }
  return findRootMember( position, columnIndex );
}
 
Example #5
Source File: LegacyBandedMDXTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private GenericObjectTable createColumnHeaders() {
  final Axis[] axes = this.resultSet.getAxes();
  if ( axes.length < 1 ) {
    return new GenericObjectTable();
  }
  final Axis axis = axes[ AXIS_COLUMN ];
  final List<Position> positions = axis.getPositions();
  final int colCount = positions.size();
  final GenericObjectTable result = new GenericObjectTable( 20, Math.max( 1, colCount ) );
  for ( int c = 0; c < colCount; c++ ) {
    final Position position = positions.get( c );
    Member member = null;
    final int rowCount = position.size();
    for ( int r = 0; r < rowCount; r++ ) {
      member = position.get( r );
      if ( member != null ) {
        result.setObject( r, c, member.getName() );
      }
    }

    if ( member != null ) {
      result.setObject( rowCount, c, member.getHierarchy().getName() );
    }
  }
  return result;
}
 
Example #6
Source File: LegacyBandedMDXTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @return
 */
private GenericObjectTable createRowHeaders() {
  final Axis[] axes = this.resultSet.getAxes();
  if ( axes.length < 2 ) {
    return new GenericObjectTable();
  }
  final Axis axis = axes[ AXIS_ROW ];
  final List<Position> positions = axis.getPositions();
  final int rowCount = positions.size();
  final GenericObjectTable result = new GenericObjectTable( Math.max( 1, rowCount ), 5 );

  for ( int r = 0; r < rowCount; r++ ) {
    final Position position = positions.get( r );
    Member member = null;
    final int colCount = position.size();
    for ( int c = 0; c < colCount; c++ ) {
      member = position.get( c );
      result.setObject( r, c, member.getName() );
    }
    if ( member != null ) {
      result.setObject( r, colCount, member.getHierarchy().getName() );
    }
  }
  return result;
}
 
Example #7
Source File: DenormalizedMDXTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Member computeMeasureName( final Result resultSet ) {
  final List<Position> positionList = resultSet.getSlicerAxis().getPositions();
  for ( int i = 0; i < positionList.size(); i++ ) {
    final Position position = positionList.get( i );
    for ( int positionIndex = 0; positionIndex < position.size(); positionIndex++ ) {

      Member m = position.get( positionIndex );
      while ( m != null ) {
        if ( m.isMeasure() ) {
          return m;
        }
        m = m.getParentMember();
      }
    }
  }

  return null;
}
 
Example #8
Source File: DenormalizedMDXTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Member getCandidateMembers( final int columnIndex,
                                    final int[] cellKey ) {

  final int axisIndex = columnToAxisPosition.get( columnIndex );
  final Axis[] axes = resultSet.getAxes();
  final Axis axis = axes[ axisIndex ];

  final List<Position> positionList = axis.getPositions();
  if ( positionList.isEmpty() ) {
    return null;
  }

  final int posIndex = cellKey[ axisIndex ];
  final Position position = positionList.get( posIndex );

  final Member memberByName = findMemberByName( position, columnIndex );
  if ( memberByName != null ) {
    return memberByName;
  }
  return findRootMember( position, columnIndex );
}
 
Example #9
Source File: ResultSetProcessingLib.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static int computeMemberCountForAxis( final Axis axis,
                                             final boolean membersOnAxisSorted ) {
  final List<Position> positions = axis.getPositions();
  final MemberAddingStrategy strategy = membersOnAxisSorted ?
    new SortedMemberAddingStrategy( positions ) :
    new ResultSetOrderMemberAddingStrategy();

  for ( int positionsIndex = 0; positionsIndex < positions.size(); positionsIndex++ ) {
    final Position position = positions.get( positionsIndex );
    for ( int positionIndex = 0; positionIndex < position.size(); positionIndex++ ) {
      Member m = position.get( positionIndex );
      computeDeepColumnNames( m, strategy );
    }
  }

  return strategy.values().size();
}
 
Example #10
Source File: JRMondrianTuple.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
public JRMondrianTuple(Position position, JRMondrianFactory factory)
{
	members = new JRMondrianMember[position.size()];
	int idx = 0;
	for (Iterator<Member> it = position.iterator(); it.hasNext(); ++idx)
	{
		Member member = it.next();
		members[idx] = factory.createMember(member);
	}
}
 
Example #11
Source File: ResultSetProcessingLib.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static ArrayList<Member> computeColumnToMemberMapping( final Axis[] axes,
                                                              final int[] axesMembers,
                                                              final int startAxis,
                                                              final boolean membersOnAxisSorted ) {
  final ArrayList<Member> columnToMemberMapper = new ArrayList<Member>();
  for ( int axesIndex = axes.length - 1; axesIndex >= startAxis; axesIndex -= 1 ) {
    final Axis axis = axes[ axesIndex ];
    final List<Position> positions = axis.getPositions();

    final MemberAddingStrategy strategy = membersOnAxisSorted ?
      new SortedMemberAddingStrategy( positions ) :
      new ResultSetOrderMemberAddingStrategy();

    for ( int positionsIndex = 0; positionsIndex < positions.size(); positionsIndex++ ) {
      final Position position = positions.get( positionsIndex );
      for ( int positionIndex = 0; positionIndex < position.size(); positionIndex++ ) {
        Member m = position.get( positionIndex );
        computeDeepColumnNames( m, strategy );
      }
    }

    Collection<Member> columnNamesSet = strategy.values();
    if ( columnNamesSet.size() != axesMembers[ axesIndex ] ) {
      logger.error( "ERROR: Number of names is not equal the pre-counted number." );
    }

    columnToMemberMapper.addAll( columnNamesSet );
  }
  return columnToMemberMapper;
}
 
Example #12
Source File: ResultSetProcessingLib.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Column axis members can be nested (having multiple dimensions or multiple levels of the same dimension) and thus
 * the Member's unique name is not necessarily unique across the whole context (same year mentioned for different
 * product lines, for example). So we need to compute that name recursively.
 *
 * @param position The OLAP position, a list of members uniquely specifying a cell-position.
 * @return the computed name, usually jus a concat of all levels.
 */
public static String computeUniqueColumnName( final Position position ) {
  final StringBuilder positionName = new StringBuilder( 100 );
  for ( int j = 0; j < position.size(); j++ ) {
    if ( j != 0 ) {
      positionName.append( '/' );
    }
    final Member member = position.get( j );
    positionName.append( MondrianUtil.getUniqueMemberName( member ) );
  }
  return positionName.toString();
}
 
Example #13
Source File: SortedMemberAddingStrategy.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public MemberComparator( final List<Position> positions ) {
  LinkedHashSet<Dimension> dimensionInOrder = new LinkedHashSet<Dimension>();
  for ( final Position position : positions ) {
    for ( final Member member : position ) {
      dimensionInOrder.add( member.getDimension() );
    }
  }

  dimensionOrder = new HashMap<Dimension, Integer>();
  for ( final Dimension dimension : dimensionInOrder ) {
    dimensionOrder.put( dimension, dimensionOrder.size() );
  }
}
 
Example #14
Source File: MondrianHelper.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private static void outputFlattenedRecurse( Result result, List<List<Object>> rows, List<Object> rowValues,
  int[] coords, int axisOrdinal ) {
  final Axis[] axes = result.getAxes();
  if ( axisOrdinal == axes.length ) {
    final Cell cell = result.getCell( coords );
    // Output the raw (unformatted) value of the cell.
    // NOTE: We could output other properties of the cell here, such as its
    // formatted value, too.
    rowValues.add( cell.getValue() );

    // Add a copy of the completed row to the list of rows.
    rows.add( new ArrayList<>( rowValues ) );
  } else {
    final Axis axis = axes[axisOrdinal];
    int k = -1;
    int saveLength = rowValues.size();
    for ( Position position : axis.getPositions() ) {
      coords[axisOrdinal] = ++k;
      for ( Member member : position ) {
        rowValues.add( member.getUniqueName() );
      }
      outputFlattenedRecurse( result, rows, rowValues, coords, axisOrdinal + 1 );
      while ( rowValues.size() > saveLength ) {
        rowValues.remove( rowValues.size() - 1 );
      }
    }
  }
}
 
Example #15
Source File: SortedMemberAddingStrategy.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SortedMemberAddingStrategy( final List<Position> positions ) {
  this.set = new TreeSet<Member>( new MemberComparator( positions ) );
}
 
Example #16
Source File: MondrianHelper.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieve the rows from the opened query. Also create a description of the flattened output of the query. This call
 * populated rowMetaInterface and rows The query needs to be opened beforehand.
 *
 * @throws KettleDatabaseException
 *           in case something goes wrong
 *
 *           TODO: this is not quite working for our purposes.
 */
public void createFlattenedOutput() throws KettleDatabaseException {

  final Axis[] axes = result.getAxes();
  rows = new ArrayList<>();
  headings = new ArrayList<>();

  // Compute headings. Each heading is a hierarchy name. If there are say
  // 2 members on the columns, and 3 members on the rows axis, then there
  // will be 5 headings.
  //
  for ( Axis axis : axes ) {
    final List<Position> positions = axis.getPositions();
    if ( positions.isEmpty() ) {
      // Result set is empty. There is no data to print, and we cannot
      // even deduce column headings.
      return;
    }
    for ( Member member : positions.get( 0 ) ) {
      Hierarchy hierarchy = member.getHierarchy();
      headings.add( hierarchy.getUniqueName() );
    }
  }

  int[] coords = new int[axes.length];
  outputFlattenedRecurse( result, rows, new ArrayList<>(), coords, 0 );

  outputRowMeta = new RowMeta();

  // Just scan the first row to see what data types we received...
  //
  for ( int i = 0; i < rows.size() && i < 1; i++ ) {

    List<Object> rowValues = rows.get( i );

    for ( int c = 0; c < rowValues.size(); c++ ) {
      Object valueData = rowValues.get( c );

      int valueType;

      if ( valueData instanceof String ) {
        valueType = ValueMetaInterface.TYPE_STRING;
      } else if ( valueData instanceof Date ) {
        valueType = ValueMetaInterface.TYPE_DATE;
      } else if ( valueData instanceof Boolean ) {
        valueType = ValueMetaInterface.TYPE_BOOLEAN;
      } else if ( valueData instanceof Integer ) {
        valueType = ValueMetaInterface.TYPE_INTEGER;
        valueData = Long.valueOf( ( (Integer) valueData ).longValue() );
      } else if ( valueData instanceof Short ) {
        valueType = ValueMetaInterface.TYPE_INTEGER;
        valueData = Long.valueOf( ( (Short) valueData ).longValue() );
      } else if ( valueData instanceof Byte ) {
        valueType = ValueMetaInterface.TYPE_INTEGER;
        valueData = Long.valueOf( ( (Byte) valueData ).longValue() );
      } else if ( valueData instanceof Long ) {
        valueType = ValueMetaInterface.TYPE_INTEGER;
      } else if ( valueData instanceof Double ) {
        valueType = ValueMetaInterface.TYPE_NUMBER;
      } else if ( valueData instanceof Float ) {
        valueType = ValueMetaInterface.TYPE_NUMBER;
        valueData = Double.valueOf( ( (Float) valueData ).doubleValue() );
      } else if ( valueData instanceof BigDecimal ) {
        valueType = ValueMetaInterface.TYPE_BIGNUMBER;
      } else {
        throw new KettleDatabaseException( BaseMessages.getString( PKG, "MondrianInputErrorUnhandledType", valueData.getClass().toString() ) );
      }

      try {
        ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( headings.get( c ), valueType );
        outputRowMeta.addValueMeta( valueMeta );
        rowValues.set( i, valueData );
      } catch ( Exception e ) {
        throw new KettleDatabaseException( e );
      }
    }
  }

  // Now that we painstakingly found the metadata that comes out of the Mondrian database, cache it please...
  //
  DBCacheEntry cacheEntry = new DBCacheEntry( databaseMeta.getName(), queryString );
  DBCache.getInstance().put( cacheEntry, outputRowMeta );
}