@Override
  public InterpreterResult interpret(String st, InterpreterContext context) {
    InterpreterResult result;

    if ("getId".equals(st)) {
      // get unique id of this interpreter instance
      result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "" + this.hashCode());
    } else if (st.startsWith("sleep")) {
      try {
        Thread.sleep(Integer.parseInt(st.split(" ")[1]));
      } catch (InterruptedException e) {
        // nothing to do
      }
      result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "repl2: " + st);
    } else {
      result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "repl2: " + st);
    }

    if (context.getResourcePool() != null) {
      context
          .getResourcePool()
          .put(context.getNoteId(), context.getParagraphId(), "result", result);
    }
    return result;
  }
예제 #2
0
  @Override
  public void run(ApplicationArgument arg, InterpreterContext context)
      throws ApplicationException, IOException {
    // get TableData
    TableData tableData =
        (TableData)
            context.getResourcePool().get(arg.getResource().location(), arg.getResource().name());

    if (tableData == null) {
      context.out.write("No table data found");
      return;
    }

    if (tableData.getColumnDef().length < 2) {
      context.out.write("Minimum 2 columns are required. xaxis, yaxis");
      return;
    }
    // dbar elementId
    String elementId = "dbar" + context.getParagraphId();

    // create element
    context.out.write("<div id=\"" + elementId + "\" style=\"height:400px;\"><svg></svg></div>");

    // include library
    context.out.write("<script>\n");

    // write data
    int numRows = tableData.length();
    String jsonData = "[ { key: \"data\", values: [";
    for (int i = 0; i < numRows; i++) {
      try {
        jsonData +=
            "{ label:\"" + tableData.getData(i, 0) + "\", value:" + tableData.getData(i, 1) + "}";
        if (i != numRows) {
          jsonData += ",";
        }
      } catch (Exception e) {
        continue;
      }
    }
    jsonData += "]}]";

    context.out.write("nv.addGraph(function() {\n");
    context.out.write("var elementId = \"" + elementId + "\";");
    context.out.write("var data = " + jsonData + ";");
    context.out.writeResource("dbar/draw.js");
    context.out.write("});\n");

    context.out.write("</script>");
  }
예제 #3
0
 @Test
 public void testCreateDataFrame() {
   if (getSparkVersionNumber() >= 13) {
     repl.interpret("case class Person(name:String, age:Int)\n", context);
     repl.interpret(
         "val people = sc.parallelize(Seq(Person(\"moon\", 33), Person(\"jobs\", 51), Person(\"gates\", 51), Person(\"park\", 34)))\n",
         context);
     repl.interpret("people.toDF.count", context);
     assertEquals(
         new Long(4),
         context
             .getResourcePool()
             .get(
                 context.getNoteId(),
                 context.getParagraphId(),
                 WellKnownResourceName.ZeppelinReplResult.toString())
             .get());
   }
 }
 @Override
 public void cancel(InterpreterContext context) {
   livyHelper.cancelHTTP(context.getParagraphId());
 }