@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;
  }
Exemplo n.º 2
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());
   }
 }