Package org.saiku.olap.query2

Examples of org.saiku.olap.query2.Parameter


  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

    return ax;
  }

  @NotNull
  private static ThinAxis convertAxis(@NotNull QueryAxis queryAxis, @NotNull ThinQuery tq) {
    AxisLocation loc = getLocation(queryAxis);
    List<String> aggs = queryAxis.getQuery().getAggregators(queryAxis.getLocation().toString());
    ThinAxis ta =
        new ThinAxis(loc, convertHierarchies(queryAxis.getQueryHierarchies(), tq), queryAxis.isNonEmpty(), aggs);
    extendSortableQuerySet(ta, queryAxis);
    return ta;
View Full Code Here

    for (IFilterFunction f : filters) {
      if (f instanceof NameFilter) {
        NameFilter nf = (NameFilter) f;
        List<String> expressions = nf.getFilterExpression();
        expressions.add(0, nf.getHierarchy().getUniqueName());
        ThinFilter tf = new ThinFilter(FilterFlavour.Name, FilterOperator.EQUALS, FilterFunction.Filter, expressions);
        tfs.add(tf);
      }
      if (f instanceof NameLikeFilter) {
        NameLikeFilter nf = (NameLikeFilter) f;
        List<String> expressions = nf.getFilterExpression();
        expressions.add(0, nf.getHierarchy().getUniqueName());
        ThinFilter tf = new ThinFilter(FilterFlavour.NameLike, FilterOperator.LIKE, FilterFunction.Filter, expressions);
        tfs.add(tf);
      }
      if (f instanceof GenericFilter) {
        GenericFilter nf = (GenericFilter) f;
        List<String> expressions = new ArrayList<String>();
        expressions.add(nf.getFilterExpression());
        ThinFilter tf = new ThinFilter(FilterFlavour.Generic, null, FilterFunction.Filter, expressions);
        tfs.add(tf);
      }
      if (f instanceof NFilter) {
        NFilter nf = (NFilter) f;
        List<String> expressions = new ArrayList<String>();
        expressions.add(Integer.toString(nf.getN()));
        if (nf.getFilterExpression() != null) {
          expressions.add(nf.getFilterExpression());
        }
        FilterFunction type = FilterFunction.valueOf(nf.getFunctionType().toString());
        ThinFilter tf = new ThinFilter(FilterFlavour.N, null, type, expressions);
        tfs.add(tf);
      }
    }
    return tfs;
  }
View Full Code Here

        List<String> expressions = new ArrayList<String>();
        expressions.add(Integer.toString(nf.getN()));
        if (nf.getFilterExpression() != null) {
          expressions.add(nf.getFilterExpression());
        }
        FilterFunction type = FilterFunction.valueOf(nf.getFunctionType().toString());
        ThinFilter tf = new ThinFilter(FilterFlavour.N, null, type, expressions);
        tfs.add(tf);
      }
    }
    return tfs;
View Full Code Here

TOP

Related Classes of org.saiku.olap.query2.Parameter

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.