Emilio Jose Coronado Lopez has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/2550

Change subject: Server side changes to Query-Service API to support logical 
plan, and optimized logical plan parameters
......................................................................

Server side changes to Query-Service API to support logical plan, and
optimized logical plan parameters

The following commits from your working branch will be included:

commit 0078c225ba9f59af3f63731cb957d983c19cc07b
Author: Emilio Coronado <[email protected]>
Date:   Fri Mar 30 12:48:52 2018 +0900

    [ASTERIXDB-2267] AsterixDB Dashboard: Query Plan Viewer Support

    - user model changes: no
    - storage format changes: no
    - interface changes: no

    Details:
    - Adding logical plan, and optimized logical plan parameters support to
    query-service REST API

Change-Id: I96b97b5787803d7ec218c88eed9875c8a23a9947
---
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
2 files changed, 43 insertions(+), 12 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/50/2550/1

diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
index ad715a4..e78b220 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
@@ -120,8 +120,11 @@
     private static final int MIN_FRAME_LIMIT_FOR_JOIN = 5;
     // one for query, two for intermediate results, one for final result, and 
one for reading an inverted list
     private static final int MIN_FRAME_LIMIT_FOR_TEXTSEARCH = 5;
-    private static final String LPLAN = "Logical plan";
-    private static final String OPLAN = "Optimized logical plan";
+    private static final String LPLAN = "logicalPlan";
+    private static final String OPLAN = "optimizedLogicalPlan";
+    private static final String REWRITTEN_EXPRESSION_TREE = 
"rewrittenExpressionTree";
+    private static final String EXPRESSION_TREE = "expressionTree";
+    private static final String HYRACKS_JOB = "hyracksJob";
 
     // A white list of supported configurable parameters.
     private static final Set<String> CONFIGURABLE_PARAMETER_NAMES =
@@ -167,22 +170,31 @@
 
     private void printPlanPrefix(SessionOutput output, String planName) {
         if (output.config().is(SessionConfig.FORMAT_HTML)) {
-            output.out().println("<h4>" + planName + ":</h4>");
             if (LPLAN.equalsIgnoreCase(planName)) {
+                output.out().println("<h4>Logical Plan:</h4>");
                 output.out().println("<pre class = query-plan>");
             } else if (OPLAN.equalsIgnoreCase(planName)) {
+                output.out().println("<h4>Optimized Logical Plan:</h4>");
                 output.out().println("<pre class = query-optimized-plan>");
+            } else if (REWRITTEN_EXPRESSION_TREE.equalsIgnoreCase(planName)) {
+                output.out().println("<h4>Rewritten Expression Tree:</h4>");
+            } else if (EXPRESSION_TREE.equalsIgnoreCase(planName)) {
+                output.out().println("<h4>Expression Tree:</h4>");
+            } else if (HYRACKS_JOB.equalsIgnoreCase(planName)) {
+                output.out().println("<h4>Hyracks Job:</h4>");
             } else {
                 output.out().println("<pre>");
             }
         } else {
-            output.out().println("----------" + planName + ":");
+            output.out().print("\"" + planName + "\":");
         }
     }
 
     private void printPlanPostfix(SessionOutput output) {
         if (output.config().is(SessionConfig.FORMAT_HTML)) {
             output.out().println("</pre>");
+        } else {
+            output.out().print(",");
         }
     }
 
@@ -195,7 +207,7 @@
         SessionConfig conf = output.config();
         if (!conf.is(SessionConfig.FORMAT_ONLY_PHYSICAL_OPS) && 
conf.is(SessionConfig.OOB_EXPR_TREE)) {
             output.out().println();
-            printPlanPrefix(output, "Expression tree");
+            printPlanPrefix(output, "expressionTree");
             q.accept(astPrintVisitorFactory.createLangVisitor(output.out()), 
0);
             printPlanPostfix(output);
         }
@@ -216,7 +228,7 @@
         if (!conf.is(SessionConfig.FORMAT_ONLY_PHYSICAL_OPS) && 
conf.is(SessionConfig.OOB_REWRITTEN_EXPR_TREE)) {
             output.out().println();
 
-            printPlanPrefix(output, "Rewritten expression tree");
+            printPlanPrefix(output, "rewrittenExpressionTree");
             if (isQuery) {
                 
query.accept(astPrintVisitorFactory.createLangVisitor(output.out()), 0);
             }
@@ -232,8 +244,7 @@
 
         if (!conf.is(SessionConfig.FORMAT_ONLY_PHYSICAL_OPS) && 
conf.is(SessionConfig.OOB_LOGICAL_PLAN)) {
             output.out().println();
-
-            printPlanPrefix(output, "Logical plan");
+            printPlanPrefix(output, "logicalPlan");
             if (isQuery || isLoad) {
                 PlanPrettyPrinter.printPlan(plan, 
getPrettyPrintVisitor(output.config().getLpfmt(), output.out()), 0);
             }
@@ -273,7 +284,7 @@
                     AlgebricksAppendable buffer = new 
AlgebricksAppendable(output.out());
                     PlanPrettyPrinter.printPhysicalOps(plan, buffer, 0);
                 } else {
-                    printPlanPrefix(output, "Optimized logical plan");
+                    printPlanPrefix(output, "optimizedLogicalPlan");
                     if (isQuery || isLoad) {
                         PlanPrettyPrinter.printPlan(plan,
                                 
getPrettyPrintVisitor(output.config().getLpfmt(), output.out()), 0);
@@ -376,7 +387,7 @@
     protected void printJobSpec(Query rwQ, JobSpecification spec, 
SessionConfig conf, SessionOutput output)
             throws AlgebricksException {
         if (conf.is(SessionConfig.OOB_HYRACKS_JOB)) {
-            printPlanPrefix(output, "Hyracks job");
+            printPlanPrefix(output, "hyracksJob");
             if (rwQ != null) {
                 try {
                     final ObjectWriter objectWriter = new 
ObjectMapper().writerWithDefaultPrettyPrinter();
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
index 56359e3..8f1f6e7 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
@@ -54,6 +54,7 @@
 import org.apache.asterix.translator.ResultProperties;
 import org.apache.asterix.translator.SessionConfig;
 import org.apache.asterix.translator.SessionOutput;
+import org.apache.asterix.translator.SessionConfig.PlanFormat;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.api.application.IServiceContext;
 import org.apache.hyracks.api.exceptions.HyracksException;
@@ -141,7 +142,10 @@
         MODE("mode"),
         TIMEOUT("timeout"),
         PLAN_FORMAT("plan-format"),
-        MAX_RESULT_READS("max-result-reads");
+        MAX_RESULT_READS("max-result-reads"),
+        PRINT_LOGICAL_PLAN("print-logical-plan"),
+        PRINT_OPTIMIZED_LOGICAL_PLAN("print-optimized-logical-plan"),
+        PRINT_JOB("print_job");
 
         private final String str;
 
@@ -198,6 +202,9 @@
         String clientContextID;
         String mode;
         String maxResultReads;
+        String printLogicalPlan;
+        String printOptimizedLogicalPlan;
+        String printJob;
 
         @Override
         public String toString() {
@@ -213,6 +220,9 @@
                 on.put("format", format);
                 on.put("timeout", timeout);
                 on.put("maxResultReads", maxResultReads);
+                on.put("printLogicalPlan", printLogicalPlan);
+                on.put("printOptimizedLogicalPlan", printOptimizedLogicalPlan);
+                on.put("printJob", printJob);
                 return om.writer(new 
MinimalPrettyPrinter()).writeValueAsString(on);
             } catch (JsonProcessingException e) { // NOSONAR
                 LOGGER.debug("unexpected exception marshalling {} instance to 
json", getClass(), e);
@@ -308,13 +318,15 @@
 
         SessionConfig.OutputFormat format = getFormat(param.format);
         //TODO:get the parameters from UI.Currently set to clean_json.
-        SessionConfig sessionConfig = new SessionConfig(format);
+        SessionConfig sessionConfig = new SessionConfig(format, 
PlanFormat.JSON);
         sessionConfig.set(SessionConfig.FORMAT_WRAPPER_ARRAY, true);
         sessionConfig.set(SessionConfig.FORMAT_INDENT_JSON, param.pretty);
         sessionConfig.set(SessionConfig.FORMAT_QUOTE_RECORD,
                 format != SessionConfig.OutputFormat.CLEAN_JSON && format != 
SessionConfig.OutputFormat.LOSSLESS_JSON);
         sessionConfig.set(SessionConfig.FORMAT_CSV_HEADER, format == 
SessionConfig.OutputFormat.CSV
                 && "present".equals(getParameterValue(param.format, 
Attribute.HEADER.str())));
+        sessionConfig.setOOBData(false, false, isSet(param.printLogicalPlan), 
isSet(param.printOptimizedLogicalPlan),
+                false);
         return new SessionOutput(sessionConfig, resultWriter, resultPrefix, 
resultPostfix, appendHandle, appendStatus);
     }
 
@@ -391,6 +403,8 @@
                 param.clientContextID = getOptText(jsonRequest, 
Parameter.CLIENT_ID.str());
                 param.timeout = getOptText(jsonRequest, 
Parameter.TIMEOUT.str());
                 param.maxResultReads = getOptText(jsonRequest, 
Parameter.MAX_RESULT_READS.str());
+                param.printLogicalPlan = getOptText(jsonRequest, 
Parameter.PRINT_LOGICAL_PLAN.str());
+                param.printOptimizedLogicalPlan = getOptText(jsonRequest, 
Parameter.PRINT_OPTIMIZED_LOGICAL_PLAN.str());
             } catch (JsonParseException | JsonMappingException e) {
                 // if the JSON parsing fails, the statement is empty and we 
get an empty statement error
                 GlobalConfig.ASTERIX_LOGGER.log(Level.ERROR, e.getMessage(), 
e);
@@ -406,6 +420,8 @@
             param.clientContextID = 
request.getParameter(Parameter.CLIENT_ID.str());
             param.timeout = request.getParameter(Parameter.TIMEOUT.str());
             param.maxResultReads = 
request.getParameter(Parameter.MAX_RESULT_READS.str());
+            param.printLogicalPlan = 
request.getParameter(Parameter.PRINT_LOGICAL_PLAN.str());
+            param.printOptimizedLogicalPlan = 
request.getParameter(Parameter.PRINT_OPTIMIZED_LOGICAL_PLAN.str());
         }
         return param;
     }
@@ -566,4 +582,8 @@
             state.setStatus(ResultStatus.FATAL, 
HttpResponseStatus.INTERNAL_SERVER_ERROR);
         }
     }
+
+    private static boolean isSet(String requestParameter) {
+        return requestParameter != null && "true".equals(requestParameter);
+    }
 }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/2550
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I96b97b5787803d7ec218c88eed9875c8a23a9947
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Emilio Jose Coronado Lopez <[email protected]>

Reply via email to