Package org.saiku.query

Examples of org.saiku.query.Query


  @Nullable
  @Deprecated
  public ThinQuery createEmpty(String name, SaikuCube cube) {
    try {
      Cube cub = olapDiscoverService.getNativeCube(cube);
      Query query = new Query(name, cub);
      ThinQuery tq = Thin.convert(query, cube);
      return tq;

    } catch (Exception e) {
      LOG.error("Cannot create new query for cube :" + cube, e);
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())) {
View Full Code Here

  private void calculateTotals(@NotNull ThinQuery tq, @NotNull CellDataSet result, @NotNull CellSet cellSet,
                               ICellSetFormatter formatter)
      throws Exception {
    if (ThinQuery.Type.QUERYMODEL.equals(tq.getType()) && formatter instanceof FlattenedCellSetFormatter) {
      Cube cub = olapDiscoverService.getNativeCube(tq.getCube());
      Query query = Fat.convert(tq, cub);

      QueryDetails details = query.getDetails();
      Measure[] selectedMeasures = new Measure[details.getMeasures().size()];
      for (int i = 0; i < selectedMeasures.length; i++) {
        selectedMeasures[i] = details.getMeasures().get(i);
      }
      result.setSelectedMeasures(selectedMeasures);

      int rowsIndex = 0;
      if (!cellSet.getAxes().get(0).getAxisOrdinal().equals(Axis.ROWS)) {
        rowsIndex = rowsIndex + 1 & 1;
      }
      // TODO - refactor this using axis ordinals etc.
      //@formatter:off
      final AxisInfo[] axisInfos = new AxisInfo[] { new AxisInfo(cellSet.getAxes().get(rowsIndex)),
        new AxisInfo(cellSet.getAxes().get(rowsIndex + 1 & 1)) };
      //@formatter:on
      List<TotalNode>[][] totals = new List[2][];
      TotalsListsBuilder builder = null;
      for (int index = 0; index < 2; index++) {
        final int second = index + 1 & 1;
        TotalAggregator[] aggregators = new TotalAggregator[axisInfos[second].maxDepth + 1];
        for (int i = 1; i < aggregators.length - 1; i++) {
          List<String> aggs = query.getAggregators(axisInfos[second].uniqueLevelNames.get(i - 1));
          String totalFunctionName = aggs != null && aggs.size() > 0 ? aggs.get(0) : null;
          aggregators[i] =
              StringUtils.isNotBlank(totalFunctionName)
              ? TotalAggregator.newInstanceByFunctionName(totalFunctionName)
              : null;
        }
        List<String> aggs = query.getAggregators(axisInfos[second].axis.getAxisOrdinal().name());
        String totalFunctionName = aggs != null && aggs.size() > 0 ? aggs.get(0) : null;
        aggregators[0] =
            StringUtils.isNotBlank(totalFunctionName) ? TotalAggregator.newInstanceByFunctionName(totalFunctionName)
                                                      : null;
        builder = new TotalsListsBuilder(selectedMeasures, aggregators, cellSet, axisInfos[index], axisInfos[second]);
View Full Code Here

    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);
          }
View Full Code Here

  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

      OlapConnection con = olapDiscoverService.getNativeConnection(scube.getConnection());
      IQuery query = qd.unparse(xml, con);

      if (QueryType.QM.equals(query.getType())) {
        OlapQuery qr = (OlapQuery) query;
        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());
      }
View Full Code Here

TOP

Related Classes of org.saiku.query.Query

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.