Presenting data from the Mondrian OLAP + Olap4j engine

I am planning a little application using the Mondrian OLAP engine with Olap4j, and should present / display data to the user. I understand all the supporting materials, but I'm not sure how I can display the data at the presentation level.

For example, olap4j has a formatter that beautifully outputs SELECT to the console.

How is the data that I get from olap4j displayed as a layer? I just went through the olap4j API, and it seems that nothing happens to get the result in a form that can be processed and displayed in some way. Is this process part of the Pentaho solution? So otherwise it is really not easy to present data only with the Mondrian OLAP and olap4j models?

EDIT: I'm used to traditionally getting some data from a database in DTO and displaying it as a layer. But how do I create a DTO for such a complex set of results?

+4
source share
1 answer

You can create your own view layer, it's a little complicated.

OlapStatement .executeOlapQuery () returns a CellSet , you have to work with that. Also read the specifications , this is a good source of information.

Here is an example that creates a List<List<MyCell>> (not the best view, but easy to forget how it works). This creates a table similar to http://www.olap4j.org/api/index.html?org/olap4j/Position.html (without the "Sex" 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; } 

Create the MyCell class using these constructors:

 public class MyCell { ... public MyCell(){...} public MyCell(Member m){...} public MyCell(Cell c){...} } 

Remember to display the filters, use Cellset.getFilterAxis () for this.

You can also check the Rectangular formatter at SourceForge, but it's a little longer.

+5
source

Source: https://habr.com/ru/post/1338359/


All Articles