Search in sources :

Example 71 with InterpreterResultMessage

use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project zeppelin by apache.

the class FlinkStreamSqlInterpreterTest method testCreateTableWithWaterMark.

@Test
public void testCreateTableWithWaterMark() throws InterpreterException, IOException {
    // create table
    InterpreterContext context = getInterpreterContext();
    InterpreterResult result = sqlInterpreter.interpret("CREATE TABLE sink_kafka (\n" + "    status  STRING,\n" + "    direction STRING,\n" + "    event_ts TIMESTAMP(3),\n" + "    WATERMARK FOR event_ts AS event_ts - INTERVAL '5' SECOND\n" + ") WITH (\n" + "  'connector.type' = 'kafka',       \n" + "  'connector.version' = 'universal',    \n" + "  'connector.topic' = 'generated.events2',\n" + "  'connector.properties.zookeeper.connect' = 'localhost:2181',\n" + "  'connector.properties.bootstrap.servers' = 'localhost:9092',\n" + "  'connector.properties.group.id' = 'testGroup',\n" + "  'format.type'='json',\n" + "  'update-mode' = 'append'\n" + ")\n", context);
    assertEquals(context.out.toString(), InterpreterResult.Code.SUCCESS, result.code());
    List<InterpreterResultMessage> resultMessages = context.out.toInterpreterResultMessage();
    assertEquals(1, resultMessages.size());
    assertEquals(InterpreterResult.Type.TEXT, resultMessages.get(0).getType());
    assertEquals("Table has been created.\n", resultMessages.get(0).getData());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.Test)

Example 72 with InterpreterResultMessage

use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project zeppelin by apache.

the class FlinkStreamSqlInterpreterTest method testUpdateStreamSql.

@Test
public void testUpdateStreamSql() throws IOException, InterpreterException {
    String initStreamScalaScript = getInitStreamScript(100);
    InterpreterResult result = flinkInterpreter.interpret(initStreamScalaScript, getInterpreterContext());
    assertEquals(InterpreterResult.Code.SUCCESS, result.code());
    InterpreterContext context = getInterpreterContext();
    result = sqlInterpreter.interpret("select url, count(1) as pv from " + "log group by url", context);
    assertEquals(InterpreterResult.Code.SUCCESS, result.code());
    List<InterpreterResultMessage> resultMessages = context.out.toInterpreterResultMessage();
    assertEquals(InterpreterResult.Type.TABLE, resultMessages.get(0).getType());
    assertTrue(resultMessages.toString(), resultMessages.get(0).getData().contains("url\tpv\n"));
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.Test)

Example 73 with InterpreterResultMessage

use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project zeppelin by apache.

the class FlinkStreamSqlInterpreterTest method testCancelStreamSql.

@Test
public void testCancelStreamSql() throws IOException, InterpreterException, InterruptedException, TimeoutException {
    String initStreamScalaScript = getInitStreamScript(1000);
    InterpreterResult result = flinkInterpreter.interpret(initStreamScalaScript, getInterpreterContext());
    assertEquals(InterpreterResult.Code.SUCCESS, result.code());
    final Waiter waiter = new Waiter();
    Thread thread = new Thread(() -> {
        try {
            InterpreterContext context = getInterpreterContext();
            InterpreterResult result2 = sqlInterpreter.interpret("select url, count(1) as pv from " + "log group by url", context);
            waiter.assertTrue(context.out.toString().contains("Job was cancelled"));
            waiter.assertEquals(InterpreterResult.Code.ERROR, result2.code());
        } catch (Exception e) {
            e.printStackTrace();
            waiter.fail("Should not fail here");
        }
        waiter.resume();
    });
    thread.start();
    // the streaming job will run for 20 seconds. check init_stream.scala
    // sleep 10 seconds to make sure the job is started but not finished
    Thread.sleep(10 * 1000);
    InterpreterContext context = getInterpreterContext();
    sqlInterpreter.cancel(context);
    waiter.await(10 * 1000);
    // resume job
    sqlInterpreter.interpret("select url, count(1) as pv from " + "log group by url", context);
    assertEquals(InterpreterResult.Code.SUCCESS, result.code());
    List<InterpreterResultMessage> resultMessages = context.out.toInterpreterResultMessage();
    assertEquals(InterpreterResult.Type.TABLE, resultMessages.get(0).getType());
    assertTrue(resultMessages.toString(), resultMessages.get(0).getData().contains("url\tpv\n"));
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Waiter(net.jodah.concurrentunit.Waiter) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) Test(org.junit.Test)

Example 74 with InterpreterResultMessage

use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project zeppelin by apache.

the class IPythonKernelTest method testInterpolate.

@Test
public void testInterpolate() throws InterpreterException, IOException {
    intpGroup.getResourcePool().put("name", "hello");
    InterpreterContext context = getInterpreterContext();
    context.getLocalProperties().put("interpolate", "true");
    String st = "print('{name}')";
    InterpreterResult result = interpreter.interpret(st, context);
    assertEquals(InterpreterResult.Code.SUCCESS, result.code());
    List<InterpreterResultMessage> interpreterResultMessages = context.out.toInterpreterResultMessage();
    assertEquals(1, interpreterResultMessages.size());
    assertEquals("hello\n", interpreterResultMessages.get(0).getData());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.Test)

Example 75 with InterpreterResultMessage

use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project zeppelin by apache.

the class TableDataProxyTest method testProxyTable.

@Test
public void testProxyTable() {
    InterpreterResultMessage msg = new InterpreterResultMessage(InterpreterResult.Type.TABLE, "key\tvalue\nsun\t100\nmoon\t200\n");
    InterpreterResultTableData table = new InterpreterResultTableData(msg);
    pool.put("table", table);
    TableDataProxy proxy = new TableDataProxy(pool.get("table"));
    ColumnDef[] cols = proxy.columns();
    assertEquals(2, cols.length);
    assertEquals("key", cols[0].name());
    assertEquals("value", cols[1].name());
    Iterator<Row> it = proxy.rows();
    Row row = it.next();
    assertEquals(2, row.get().length);
    assertEquals("sun", row.get()[0]);
    assertEquals("100", row.get()[1]);
    row = it.next();
    assertEquals("moon", row.get()[0]);
    assertEquals("200", row.get()[1]);
    assertFalse(it.hasNext());
}
Also used : InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.Test)

Aggregations

InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)80 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)78 Test (org.junit.Test)60 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)55 Properties (java.util.Properties)17 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)15 IOException (java.io.IOException)13 File (java.io.File)8 TimeoutException (java.util.concurrent.TimeoutException)7 Waiter (net.jodah.concurrentunit.Waiter)7 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)6 Test (org.junit.jupiter.api.Test)6 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)3 HashMap (java.util.HashMap)3 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 Map (java.util.Map)2 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)2 CheckBox (org.apache.zeppelin.display.ui.CheckBox)2 Select (org.apache.zeppelin.display.ui.Select)2