public byte[] exportDrillthroughCsv(String queryName, int maxrows) { OlapStatement stmt = null; try { final OlapConnection con = olapDiscoverService.getNativeConnection( getQuery(queryName).getCube().getConnectionName()); stmt = con.createStatement(); String mdx = getMDXQuery(queryName); if (maxrows > 0) { mdx = "DRILLTHROUGH MAXROWS " + maxrows + " " + mdx; } else { mdx = "DRILLTHROUGH " + mdx; } ResultSet rs = stmt.executeQuery(mdx); return CsvExporter.exportCsv(rs); } catch (SQLException e) { throw new SaikuServiceException("Error DRILLTHROUGH: " + queryName, e); } finally { try { if (stmt != null) stmt.close(); } catch (Exception e) { } } }
public ResultSet drillthrough(String queryName, int maxrows, String returns) { OlapStatement stmt = null; try { final OlapConnection con = olapDiscoverService.getNativeConnection( getQuery(queryName).getCube().getConnectionName()); stmt = con.createStatement(); String mdx = getMDXQuery(queryName); if (maxrows > 0) { mdx = "DRILLTHROUGH MAXROWS " + maxrows + " " + mdx; } else { mdx = "DRILLTHROUGH " + mdx; } if (StringUtils.isNotBlank(returns)) { mdx += "\r\n RETURN " + returns; } ResultSet rs = stmt.executeQuery(mdx); return rs; } catch (SQLException e) { throw new SaikuServiceException("Error DRILLTHROUGH: " + queryName, e); } finally { try { if (stmt != null) stmt.close(); } catch (Exception e) { } } }
public ResultSet explain(String queryName) { OlapStatement stmt = null; try { final OlapConnection con = olapDiscoverService.getNativeConnection( getQuery(queryName).getCube().getConnectionName()); if (!con.isWrapperFor(RolapConnection.class)) throw new IllegalArgumentException("Cannot only get explain plan for Mondrian connections"); stmt = con.createStatement(); String mdx = getMDXQuery(queryName); mdx = "EXPLAIN PLAN FOR \n" + mdx; ResultSet rs = stmt.executeQuery(mdx); return rs; } catch (Exception e) { throw new SaikuServiceException("Error EXPLAIN: " + queryName, e); } finally { try { if (stmt != null) stmt.close(); } catch (Exception e) { } } }
public ResultSet drillthrough( String queryName, List<Integer> cellPosition, Integer maxrows, String returns) { OlapStatement stmt = null; try { IQuery query = getIQuery(queryName); CellSet cs = query.getCellset(); SaikuCube cube = getQuery(queryName).getCube(); final OlapConnection con = olapDiscoverService.getNativeConnection(cube.getConnectionName()); stmt = con.createStatement(); String select = null; StringBuffer buf = new StringBuffer(); buf.append("SELECT ("); for (int i = 0; i < cellPosition.size(); i++) { List<Member> members = cs.getAxes().get(i).getPositions().get(cellPosition.get(i)).getMembers(); for (int k = 0; k < members.size(); k++) { Member m = members.get(k); if (k > 0 || i > 0) { buf.append(", "); } buf.append(m.getUniqueName()); } } buf.append(") ON COLUMNS \r\n"); buf.append("FROM " + cube.getCubeName() + "\r\n"); SelectNode sn = (new DefaultMdxParserImpl().parseSelect(getMDXQuery(queryName))); final Writer writer = new StringWriter(); sn.getFilterAxis().unparse(new ParseTreeWriter(new PrintWriter(writer))); if (StringUtils.isNotBlank(writer.toString())) { buf.append("WHERE " + writer.toString()); } select = buf.toString(); if (maxrows > 0) { select = "DRILLTHROUGH MAXROWS " + maxrows + " " + select + "\r\n"; } else { select = "DRILLTHROUGH " + select + "\r\n"; } if (StringUtils.isNotBlank(returns)) { select += "\r\n RETURN " + returns; } log.debug("Drill Through for query (" + queryName + ") : \r\n" + select); ResultSet rs = stmt.executeQuery(select); return rs; } catch (Exception e) { throw new SaikuServiceException("Error DRILLTHROUGH: " + queryName, e); } finally { try { if (stmt != null) stmt.close(); } catch (Exception e) { } } }