Package org.saiku.olap.query2.util

Examples of org.saiku.olap.query2.util.Fat


  }

  @NotNull
  public CellDataSet getFormattedResult(String query, @NotNull String format) throws Exception {
    QueryContext qc = getContext(query);
    ThinQuery tq = qc.getOlapQuery();
    CellSet cs = qc.getOlapResult();
    String formatterName = StringUtils.isBlank(format) ? "" : format.toLowerCase();
    ICellSetFormatter cf = cff.forName(formatterName);
    CellDataSet result = OlapResultSetUtil.cellSet2Matrix(cs, cf);

    if (ThinQuery.Type.QUERYMODEL.equals(tq.getType()) && cf instanceof FlattenedCellSetFormatter && tq
        .hasAggregators()) {
      calculateTotals(tq, result, cs, cf);
    }
    return result;
  }
View Full Code Here


  @NotNull
  public ThinQuery updateQuery(@NotNull ThinQuery old) throws Exception {
    if (ThinQuery.Type.QUERYMODEL.equals(old.getType())) {
      Cube cub = olapDiscoverService.getNativeCube(old.getCube());
      Query q = Fat.convert(old, cub);
      ThinQuery tqAfter = Thin.convert(q, old.getCube());
      old.setQueryModel(tqAfter.getQueryModel());
      old.setMdx(tqAfter.getMdx());
    }
    if (context.containsKey(old.getName())) {
      QueryContext qc = context.get(old.getName());
      qc.store(ObjectKey.QUERY, old);
    }
View Full Code Here

  }

  byte[] getExport(String queryName, @NotNull String type, ICellSetFormatter formatter) {
    if (StringUtils.isNotBlank(type) && context.containsKey(queryName)) {
      CellSet rs = context.get(queryName).getOlapResult();
      ThinQuery tq = context.get(queryName).getOlapQuery();
      List<ThinHierarchy> filterHierarchies = null;
      if (ThinQuery.Type.QUERYMODEL.equals(tq.getType())) {
        filterHierarchies = tq.getQueryModel().getAxes().get(AxisLocation.FILTER).getHierarchies();
      }
      if (type.toLowerCase().equals("xls")) {
        return ExcelExporter.exportExcel(rs, formatter, filterHierarchies);
      }
      if (type.toLowerCase().equals("csv")) {
View Full Code Here

  public ResultSet drillthrough(String queryName, int maxrows, String returns) {
    OlapStatement stmt = null;
    try {

      ThinQuery query = context.get(queryName).getOlapQuery();
      final OlapConnection con = olapDiscoverService.getNativeConnection(query.getCube().getConnection());
      stmt = con.createStatement();
      String mdx = query.getMdx();
      if (maxrows > 0) {
        mdx = "DRILLTHROUGH MAXROWS " + maxrows + " " + mdx;
      } else {
        mdx = "DRILLTHROUGH " + mdx;
      }
View Full Code Here

  public ResultSet drillthrough(String queryName, @NotNull List<Integer> cellPosition, Integer maxrows,
                                String returns) {
    OlapStatement stmt = null;
    try {
      QueryContext queryContext = context.get(queryName);
      ThinQuery query = queryContext.getOlapQuery();
      CellSet cs = queryContext.getOlapResult();
      SaikuCube cube = query.getCube();
      final OlapConnection con = olapDiscoverService.getNativeConnection(cube.getConnection());
      stmt = con.createStatement();

      SelectNode sn = new DefaultMdxParserImpl().parseSelect(query.getMdx());
      String select = null;
      StringBuilder buf = new StringBuilder();
      if (sn.getWithList() != null && sn.getWithList().size() > 0) {
        buf.append("WITH \n");
        StringWriter sw = new StringWriter();
View Full Code Here

  public byte[] exportDrillthroughCsv(String queryName, int maxrows) {
    OlapStatement stmt = null;
    try {
      QueryContext queryContext = context.get(queryName);
      ThinQuery query = queryContext.getOlapQuery();
      final OlapConnection con = olapDiscoverService.getNativeConnection(query.getCube().getConnection());
      stmt = con.createStatement();
      String mdx = query.getMdx();
      if (maxrows > 0) {
        mdx = "DRILLTHROUGH MAXROWS " + maxrows + " " + mdx;
      } else {
        mdx = "DRILLTHROUGH " + mdx;
      }
View Full Code Here

  public ThinQuery zoomIn(String queryName, @Nullable List<List<Integer>> realPositions) {

    try {
      if (context.containsKey(queryName)) {
        CellSet cs = context.get(queryName).getOlapResult();
        ThinQuery old = context.get(queryName).getOlapQuery();
        Cube cub = olapDiscoverService.getNativeCube(old.getCube());
        Query q = Fat.convert(old, cub);

        if (cs == null) {
          throw new SaikuServiceException("Cannot zoom in if last cellset is null");
        }
        if (realPositions == null || realPositions.size() == 0) {
          throw new SaikuServiceException("Cannot zoom in if zoom in position is empty");
        }

        Map<Hierarchy, Set<Member>> memberSelection = new HashMap<Hierarchy, Set<Member>>();
        for (List<Integer> position : realPositions) {
          for (int k = 0; k < position.size(); k++) {
            Position p = cs.getAxes().get(k).getPositions().get(position.get(k));
            List<Member> members = p.getMembers();
            for (Member m : members) {
              Hierarchy h = m.getHierarchy();
              if (!memberSelection.containsKey(h)) {
                Set<Member> mset = new HashSet<Member>();
                memberSelection.put(h, mset);
              }
              memberSelection.get(h).add(m);
            }
          }
        }


        for (Hierarchy h : memberSelection.keySet()) {
          QueryHierarchy qh = q.getHierarchy(h);
          for (QueryLevel ql : qh.getActiveQueryLevels()) {
            ql.getInclusions().clear();
            ql.getExclusions().clear();
            ql.setMdxSetExpression(null);
          }
          for (Member m : memberSelection.get(h)) {
            qh.includeMember(m);
          }
        }
        ThinQuery tqAfter = Thin.convert(q, old.getCube());
        q = null;
        return tqAfter;
      } else {
        throw new SaikuServiceException("Cannot get query result from context: " + queryName);
      }
View Full Code Here

  @NotNull
  public ThinQuery drillacross(String queryName, @NotNull List<Integer> cellPosition,
                               @Nullable Map<String, List<String>> levels) {
    try {
      ThinQuery old = context.get(queryName).getOlapQuery();
      Cube cub = olapDiscoverService.getNativeCube(old.getCube());
      Query query = Fat.convert(old, cub);
      CellSet cs = context.get(queryName).getOlapResult();


      Set<Level> levelSet = new HashSet<Level>();
      if (cs == null) {
        throw new SaikuServiceException("Cannot drill across. Last CellSet empty");
      }
      for (int i = 0; i < cellPosition.size(); i++) {
        List<Member> members = cs.getAxes().get(i).getPositions().get(cellPosition.get(i)).getMembers();
        for (Member m : members) {
          QueryHierarchy qh = query.getHierarchy(m.getHierarchy());
          if (qh.getHierarchy().getDimension().getName().equals("Measures")) {
            Measure measure = query.getMeasure(m.getName());
            if (!query.getDetails().getMeasures().contains(measure)) {
              query.getDetails().add(measure);
            }

          } else {
            qh.clearSelection();
            qh.clearFilters();
            qh.clearSort();
            query.moveHierarchy(qh, Axis.FILTER);
            qh.includeMember(m);
            levelSet.add(m.getLevel());
          }

        }
      }
      boolean clearedMeasures = false;

      if (levels != null) {
        for (String key : levels.keySet()) {
          String dimensionName = key.split("###")[0];

          if ("Measures".equals(dimensionName)) {
            if (!clearedMeasures) {
              query.getDetails().getMeasures().clear();
              clearedMeasures = true;
            }
            for (String measureName : levels.get(key)) {
              Measure measure = query.getMeasure(measureName);
              if (measure != null) {
                query.getDetails().add(measure);
              } else {
                for (Measure m : cub.getMeasures()) {
                  if (m.getUniqueName().equals(measureName)) {
                    query.getDetails().add(m);
                  }
                }
              }
            }
            continue;
          }
          String hierarchyName = key.split("###")[1];
          Dimension d = cub.getDimensions().get(dimensionName);
          Hierarchy h = d.getHierarchies().get(hierarchyName);
          QueryHierarchy qh = query.getHierarchy(h);
          for (Level l : h.getLevels()) {
            for (String levelU : levels.get(key)) {
              if (l.getUniqueName().equals(levelU) || l.getName().equals(levelU)) {
                qh.includeLevel(l);
              }
            }
          }
          if (qh.getActiveQueryLevels().size() > 0) {
            query.moveHierarchy(qh, Axis.ROWS);
          }
        }
      }
      if (query.getDetails().getMeasures().size() == 0) {
        QueryHierarchy qh = query.getHierarchy("Measures");
        Member defaultMeasure = qh.getHierarchy().getDefaultMember();
        query.getDetails().add(query.getMeasure(defaultMeasure.getName()));
      }
      return Thin.convert(query, old.getCube());
    } catch (Exception e) {
      throw new SaikuServiceException("Error drilling across: " + queryName, e);
    }
  }
View Full Code Here

        Query sQ = QueryConverter.convertQuery(qr.getQuery());
        SaikuCube converted = ObjectUtil.convert(scube.getConnection(), sQ.getCube());
        return Thin.convert(sQ, converted);
      } else {
        SaikuCube converted = ObjectUtil.convert(scube.getConnection(), olapDiscoverService.getNativeCube(scube));
        return new ThinQuery(query.getName(), converted, query.getMdx());
      }
    }
    return null;

  }
View Full Code Here

  }

  @NotNull
  private static ThinDetails convert(@NotNull QueryDetails details) {
    ThinDetails.Location location = ThinDetails.Location.valueOf(details.getLocation().toString());
    AxisLocation axis = AxisLocation.valueOf(details.getAxis().toString());
    List<ThinMeasure> measures = new ArrayList<ThinMeasure>();
    if (details.getMeasures().size() > 0) {
      for (Measure m : details.getMeasures()) {
        ThinMeasure.Type type = Type.EXACT;
        if (m instanceof CalculatedMeasure) {
View Full Code Here

TOP

Related Classes of org.saiku.olap.query2.util.Fat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.