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());
}
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"));
}
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"));
}
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());
}
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());
}
Aggregations