예제 #1
0
 public static byte[] exportCsv(
     CellSet cellSet, String delimiter, String enclosing, ICellSetFormatter formatter) {
   CellDataSet table = OlapResultSetUtil.cellSet2Matrix(cellSet, formatter);
   return getCsv(table, delimiter, enclosing);
 }
예제 #2
0
  public CellDataSet execute(String queryName, ICellSetFormatter formatter) {
    String runId = "runId:" + ID_GENERATOR.getAndIncrement();
    try {
      //			System.out.println("Execute: ID " + Thread.currentThread().getId() + " Name: " +
      // Thread.currentThread().getName());
      IQuery query = getIQuery(queryName);
      OlapConnection con =
          olapDiscoverService.getNativeConnection(query.getSaikuCube().getConnectionName());

      Long start = (new Date()).getTime();
      if (query.getScenario() != null) {
        log.info(
            runId
                + "\tQuery: "
                + query.getName()
                + " Setting scenario:"
                + query.getScenario().getId());
        con.setScenario(query.getScenario());
      }

      if (query.getTag() != null) {
        query = applyTag(query, con, query.getTag());
      }

      String mdx = query.getMdx();
      log.info(runId + "\tType:" + query.getType() + ":\n" + mdx);

      CellSet cellSet = query.execute();
      Long exec = (new Date()).getTime();

      if (query.getScenario() != null) {
        log.info("Query (" + queryName + ") removing scenario:" + query.getScenario().getId());
        con.setScenario(null);
      }

      CellDataSet result = OlapResultSetUtil.cellSet2Matrix(cellSet, formatter);
      Long format = (new Date()).getTime();
      log.info(
          runId
              + "\tSize: "
              + result.getWidth()
              + "/"
              + result.getHeight()
              + "\tExecute:\t"
              + (exec - start)
              + "ms\tFormat:\t"
              + (format - exec)
              + "ms\t Total: "
              + (format - start)
              + "ms");
      result.setRuntime(new Double(format - start).intValue());
      getIQuery(queryName).storeCellset(cellSet);
      return result;
    } catch (Exception e) {
      if (log.isInfoEnabled()) {
        String error = ExceptionUtils.getRootCauseMessage(e);
        log.info(runId + "\tException: " + error);
      }
      throw new SaikuServiceException(runId + "\tCan't execute query: " + queryName, e);
    } catch (Error e) {
      if (log.isInfoEnabled()) {
        String error = ExceptionUtils.getRootCauseMessage(e);
        log.info(runId + "\tError: " + error);
      }
      throw new SaikuServiceException(runId + "\tCan't execute query: " + queryName, e);
    }
  }