来自Mondrian OLAP引擎+ Olap4j的数据表示
我正在对使用Mondrian OLAP引擎和Olap4j并应向用户显示/显示数据的应用程序进行一些规划.我了解所有后端内容,但不确定如何在视图层中显示数据.
I'm doing a little bit of planning of an application that uses Mondrian OLAP engine with Olap4j and should present/display data to user. I understand all the back-end stuff, but I'm not sure how should I display the data in the view layer.
例如olap4j有一个格式化程序,可以将SELECT很好地打印到控制台中.
For example olap4j has a formatter that prints the SELECT nicely into the console.
我从olap4j获得的数据如何显示在视图层中?我只是通过olap4j API进行操作,似乎没有任何东西可以以某种方式获得可以进一步处理和显示的形式的结果.这个过程是Pentaho解决方案的一部分吗?因此,仅从Mondrian OLAP引擎和olap4j呈现数据真的不容易吗?
How is the data that I get from olap4j displayed in view layer ? I just went through the olap4j API, and there doesn't seem to be anything for getting the result in a form that can be somehow further processed and displayed. Is this process part of the Pentaho solution ? So that otherwise it is really not easy to present data just from Mondrian OLAP engine and olap4j ?
传统上,我习惯于将一些数据从数据库获取到我的DTO中,并将其显示在视图层中.但是,如何为如此复杂的结果集创建DTO?
I'm used to traditionally get some data from a database into my DTO and display it in view layer. But how do I create DTOs for such a complicated result set ?
您可以创建自己的视图图层,这有点棘手.
You can create your own view layer it's just a little bit tricky.
OlapStatement .executeOlapQuery()返回规范,它是很好的信息来源.
OlapStatement.executeOlapQuery() returns a CellSet, you will have to work with that. Also read the specifications, it's a good source of information.
这里是创建List<List<MyCell>>
的示例(不是最好的表示,但是很容易理解它的工作方式).这将创建一个类似于 http://www.olap4j.org/api/index的表. html?org/olap4j/Position.html (没有性别"和产品"标签).
Here is an example, that creates List<List<MyCell>>
(not the best representation but it's easy to undarstand how it works). This creates a table similar to http://www.olap4j.org/api/index.html?org/olap4j/Position.html (without the "Gender" and "Product" labels).
private final static int COLUMNS = 0; //see Cellset javadoc
private final static int ROWS= 1; //see Cellset javadoc
/**
* Outer list: rows, inner list: elements in a row
*/
private List<List<MyCell>> getListFromCellSet(CellSet cellSet) {
List<List<MyCell>> toReturn= new ArrayList<List<MyCell>>();
//Column header
//See http://www.olap4j.org/api/index.html?org/olap4j/Position.html on how Position works, it helps a lot
//Every position will be a column in the header
for (Position pos : cellSet.getAxes().get(COLUMNS).getPositions()) {
for (int i = 0; i < pos.getMembers().size(); i++) {
if (toReturn.size() <= i) {
toReturn.add(i, new ArrayList<MyCell>());
}
Member m = pos.getMembers().get(i);
MyCell myCell = new MyCell(m); //use m.getCaption() for display
toReturn.get(i).add(myCell );
}
}
//Put empty elements to the beginning of the list, so there will be place for the rows header
if (cellSet.getAxes().get(ROWS).getPositions().size() > 0) {
for (int count=0; count < cellSet.getAxes().get(1).getPositions().get(0).getMembers().size(); count++) {
for (int i = 0; i < toReturn.size(); i++) {
toReturn.get(i).add(0, new MyCell());
}
}
}
//Content + row header
for(int i = 0; i < cellSet.getAxes().get(ROWS).getPositionCount(); i++) {
List<MyCell> row = new ArrayList<MyCell>();
//Header
for (org.olap4j.metadata.Member m : cellSet.getAxes().get(ROWS).getPositions().get(i).getMembers()) {
row.add(new MyCell(m));
}
//Content
for (int j = 0; j < cellSet.getAxes().get(COLUMNS).getPositionCount(); j++) {
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(j); //coordinte
list.add(i); //coordinte
row.add(new MyCell(cellSet.getCell(list))); //use cell.getFormattedValue() for display
}
toReturn.add(row);
}
return toReturn;
}
使用以下构造函数创建MyCell类:
Create the MyCell class with these constructors:
public class MyCell {
...
public MyCell(){...}
public MyCell(Member m){...}
public MyCell(Cell c){...}
}
别忘了显示过滤器,为此使用Cellset.getFilterAxis().
Don't forget to display the filters, use Cellset.getFilterAxis() for that.
您还可以检查矩形 SourceForge上的格式化程序,但是要更长一些.
You can also check the Rectangular formatter on SourceForge, but it's a bit longer.