use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project zeppelin by apache.
the class InterpreterResultTableDataTest method test.
@Test
public void test() {
InterpreterResultMessage msg = new InterpreterResultMessage(InterpreterResult.Type.TABLE, "key\tvalue\nsun\t100\nmoon\t200\n");
InterpreterResultTableData table = new InterpreterResultTableData(msg);
ColumnDef[] cols = table.columns();
assertEquals(2, cols.length);
assertEquals("key", cols[0].name());
assertEquals("value", cols[1].name());
Iterator<Row> it = table.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());
}
use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project metron by apache.
the class StellarInterpreterTest method testExecuteStellar.
/**
* Ensure that we can run Stellar code in the interpreter.
*/
@Test
public void testExecuteStellar() {
InterpreterResult result = interpreter.interpret("2 + 2", context);
// validate the result
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
// validate the message
InterpreterResultMessage message = result.message().get(0);
assertEquals("4", message.getData());
assertEquals(InterpreterResult.Type.TEXT, message.getType());
}
use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project metron by apache.
the class StellarInterpreterTest method testExecuteBadStellar.
/**
* Ensure that 'bad' Stellar code is handled correctly by the interpreter.
*/
@Test
public void testExecuteBadStellar() {
InterpreterResult result = interpreter.interpret("2 + ", context);
// validate the result
assertEquals(InterpreterResult.Code.ERROR, result.code());
assertEquals(1, result.message().size());
// validate the message
InterpreterResultMessage message = result.message().get(0);
assertTrue(message.getData().length() > 0);
assertEquals(InterpreterResult.Type.TEXT, message.getType());
}
use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project metron by apache.
the class StellarInterpreterTest method testExecuteNoop.
/**
* The interpreter should handle if no value is returned. Some Stellar expressions
* will result in no value.
*/
@Test
public void testExecuteNoop() {
// x is undefined and will have no result
InterpreterResult result = interpreter.interpret("x", context);
// validate the result
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
// validate the message
InterpreterResultMessage message = result.message().get(0);
assertEquals(0, message.getData().length());
assertEquals(InterpreterResult.Type.TEXT, message.getType());
}
use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project metron by apache.
the class StellarInterpreterTest method testExecuteWithStellarMap.
/**
* Ensure that Stellar maps are displayed correctly in Zeppelin.
*/
@Test
public void testExecuteWithStellarMap() {
final String expected = "{foo=2, key=val}";
InterpreterResult result = interpreter.interpret("{ 'foo':2, 'key':'val' }", context);
// validate the result
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
// validate the message
InterpreterResultMessage message = result.message().get(0);
assertEquals(expected, message.getData());
assertEquals(InterpreterResult.Type.TEXT, message.getType());
}
Aggregations