コード例 #1
0
  @Override
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    OutputFormat format;
    boolean csv_and_header = false;
    String output = request.getParameter("output-format");
    if (output.equals("ADM")) {
      format = OutputFormat.ADM;
    } else if (output.equals("CSV")) {
      format = OutputFormat.CSV;
    } else if (output.equals("CSV-Header")) {
      format = OutputFormat.CSV;
      csv_and_header = true;
    } else {
      // Default output format
      format = OutputFormat.JSON;
    }

    String query = request.getParameter("query");
    String printExprParam = request.getParameter("print-expr-tree");
    String printRewrittenExprParam = request.getParameter("print-rewritten-expr-tree");
    String printLogicalPlanParam = request.getParameter("print-logical-plan");
    String printOptimizedLogicalPlanParam = request.getParameter("print-optimized-logical-plan");
    String printJob = request.getParameter("print-job");
    String executeQuery = request.getParameter("execute-query");
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    ServletContext context = getServletContext();
    IHyracksClientConnection hcc;
    IHyracksDataset hds;

    try {
      synchronized (context) {
        hcc = (IHyracksClientConnection) context.getAttribute(HYRACKS_CONNECTION_ATTR);

        hds = (IHyracksDataset) context.getAttribute(HYRACKS_DATASET_ATTR);
        if (hds == null) {
          hds = new HyracksDataset(hcc, ResultReader.FRAME_SIZE, ResultReader.NUM_READERS);
          context.setAttribute(HYRACKS_DATASET_ATTR, hds);
        }
      }
      AQLParser parser = new AQLParser(query);
      List<Statement> aqlStatements = parser.parse();
      SessionConfig sessionConfig = new SessionConfig(out, format, true, isSet(executeQuery), true);
      sessionConfig.set(SessionConfig.FORMAT_HTML, true);
      sessionConfig.set(SessionConfig.FORMAT_CSV_HEADER, csv_and_header);
      sessionConfig.setOOBData(
          isSet(printExprParam),
          isSet(printRewrittenExprParam),
          isSet(printLogicalPlanParam),
          isSet(printOptimizedLogicalPlanParam),
          isSet(printJob));
      MetadataManager.INSTANCE.init();
      AqlTranslator aqlTranslator = new AqlTranslator(aqlStatements, sessionConfig);
      double duration = 0;
      long startTime = System.currentTimeMillis();
      aqlTranslator.compileAndExecute(hcc, hds, AqlTranslator.ResultDelivery.SYNC);
      long endTime = System.currentTimeMillis();
      duration = (endTime - startTime) / 1000.00;
      out.println("<PRE>Duration of all jobs: " + duration + " sec</PRE>");
    } catch (ParseException | TokenMgrError | edu.uci.ics.asterix.aqlplus.parser.TokenMgrError pe) {
      GlobalConfig.ASTERIX_LOGGER.log(Level.INFO, pe.toString(), pe);
      ResultUtils.webUIParseExceptionHandler(out, pe, query);
    } catch (Exception e) {
      GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.getMessage(), e);
      ResultUtils.webUIErrorHandler(out, e);
    }
  }