Esempio n. 1
0
  private SQLResponse queryWithSqlMassage(SQLRequest sqlRequest) throws Exception {
    SQLResponse fakeResponse = QueryUtil.tableauIntercept(sqlRequest.getSql());
    if (null != fakeResponse) {
      logger.debug("Return fake response, is exception? " + fakeResponse.getIsException());
      return fakeResponse;
    }

    String correctedSql = QueryUtil.massageSql(sqlRequest);
    if (correctedSql.equals(sqlRequest.getSql()) == false)
      logger.debug("The corrected query: " + correctedSql);

    // add extra parameters into olap context, like acceptPartial
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put(
        OLAPContext.PRM_ACCEPT_PARTIAL_RESULT, String.valueOf(sqlRequest.isAcceptPartial()));
    OLAPContext.setParameters(parameters);

    try {
      BackdoorToggles.setToggles(sqlRequest.getBackdoorToggles());

      return execute(correctedSql, sqlRequest);

    } finally {
      BackdoorToggles.cleanToggles();
    }
  }
Esempio n. 2
0
  public void logQuery(final SQLRequest request, final SQLResponse response) {
    final String user = SecurityContextHolder.getContext().getAuthentication().getName();
    final Set<String> realizationNames = new HashSet<String>();
    final Set<Long> cuboidIds = new HashSet<Long>();
    float duration = response.getDuration() / (float) 1000;

    if (!response.isHitCache() && null != OLAPContext.getThreadLocalContexts()) {
      for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) {
        Cuboid cuboid = ctx.storageContext.getCuboid();
        if (cuboid != null) {
          // Some queries do not involve cuboid, e.g. lookup table query
          cuboidIds.add(cuboid.getId());
        }

        if (ctx.realization != null) {
          String realizationName = ctx.realization.getName();
          realizationNames.add(realizationName);
        }
      }
    }

    int resultRowCount = 0;
    if (!response.getIsException() && response.getResults() != null) {
      resultRowCount = response.getResults().size();
    }

    String newLine = System.getProperty("line.separator");
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(newLine);
    stringBuilder
        .append("==========================[QUERY]===============================")
        .append(newLine);
    stringBuilder.append("SQL: ").append(request.getSql()).append(newLine);
    stringBuilder.append("User: "******"Success: ")
        .append((null == response.getExceptionMessage()))
        .append(newLine);
    stringBuilder.append("Duration: ").append(duration).append(newLine);
    stringBuilder.append("Project: ").append(request.getProject()).append(newLine);
    stringBuilder.append("Realization Names: ").append(realizationNames).append(newLine);
    stringBuilder.append("Cuboid Ids: ").append(cuboidIds).append(newLine);
    stringBuilder.append("Total scan count: ").append(response.getTotalScanCount()).append(newLine);
    stringBuilder.append("Result row count: ").append(resultRowCount).append(newLine);
    stringBuilder.append("Accept Partial: ").append(request.isAcceptPartial()).append(newLine);
    stringBuilder.append("Is Partial Result: ").append(response.isPartial()).append(newLine);
    stringBuilder.append("Hit Cache: ").append(response.isHitCache()).append(newLine);
    stringBuilder.append("Message: ").append(response.getExceptionMessage()).append(newLine);
    stringBuilder
        .append("==========================[QUERY]===============================")
        .append(newLine);

    logger.info(stringBuilder.toString());
  }