Search in sources :

Example 76 with InterpreterResultMessage

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());
}
Also used : InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.Test)

Example 77 with InterpreterResultMessage

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());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.jupiter.api.Test)

Example 78 with InterpreterResultMessage

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());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.jupiter.api.Test)

Example 79 with InterpreterResultMessage

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());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.jupiter.api.Test)

Example 80 with InterpreterResultMessage

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());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.jupiter.api.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