Search in sources :

Example 26 with InterpreterResult

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

the class PythonInterpreterPandasSqlTest method errorMessageIfDependenciesNotInstalled.

@Test
public void errorMessageIfDependenciesNotInstalled() {
    InterpreterResult ret;
    ret = sql.interpret("SELECT * from something", context);
    assertNotNull(ret);
    assertEquals(ret.message().get(0).getData(), InterpreterResult.Code.ERROR, ret.code());
    assertTrue(ret.message().get(0).getData().contains("no such table: something"));
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Test(org.junit.Test)

Example 27 with InterpreterResult

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

the class PythonInterpreterPandasSqlTest method sqlOverTestDataPrintsTable.

@Test
public void sqlOverTestDataPrintsTable() throws IOException {
    InterpreterResult ret;
    // given
    //String expectedTable = "name\tage\n\nmoon\t33\n\npark\t34";
    ret = python.interpret("import pandas as pd", context);
    ret = python.interpret("import numpy as np", context);
    // DataFrame df2 \w test data
    ret = python.interpret("df2 = pd.DataFrame({ 'age'  : np.array([33, 51, 51, 34]), " + "'name' : pd.Categorical(['moon','jobs','gates','park'])})", context);
    assertEquals(ret.message().toString(), InterpreterResult.Code.SUCCESS, ret.code());
    //when
    ret = sql.interpret("select name, age from df2 where age < 40", context);
    //then
    assertEquals(new String(out.getOutputAt(0).toByteArray()), InterpreterResult.Code.SUCCESS, ret.code());
    assertEquals(new String(out.getOutputAt(0).toByteArray()), Type.TABLE, out.getOutputAt(0).getType());
    assertTrue(new String(out.getOutputAt(0).toByteArray()).indexOf("moon\t33") > 0);
    assertTrue(new String(out.getOutputAt(0).toByteArray()).indexOf("park\t34") > 0);
    assertEquals(InterpreterResult.Code.SUCCESS, sql.interpret("select case when name==\"aa\" then name else name end from df2", context).code());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Test(org.junit.Test)

Example 28 with InterpreterResult

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

the class PythonInterpreterPandasSqlTest method setUp.

@Before
public void setUp() throws Exception {
    Properties p = new Properties();
    p.setProperty("zeppelin.python", "python");
    p.setProperty("zeppelin.python.maxResult", "100");
    intpGroup = new InterpreterGroup();
    python = new PythonInterpreter(p);
    python.setInterpreterGroup(intpGroup);
    python.open();
    sql = new PythonInterpreterPandasSql(p);
    sql.setInterpreterGroup(intpGroup);
    intpGroup.put("note", Arrays.asList(python, sql));
    out = new InterpreterOutput(this);
    context = new InterpreterContext("note", "id", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("id"), new LinkedList<InterpreterContextRunner>(), out);
    // to make sure python is running.
    InterpreterResult ret = python.interpret("\n", context);
    assertEquals(ret.message().toString(), InterpreterResult.Code.SUCCESS, ret.code());
    sql.open();
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) HashMap(java.util.HashMap) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Properties(java.util.Properties) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) LinkedList(java.util.LinkedList) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) InterpreterOutput(org.apache.zeppelin.interpreter.InterpreterOutput) GUI(org.apache.zeppelin.display.GUI) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Before(org.junit.Before)

Example 29 with InterpreterResult

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

the class PythonInterpreterTest method testInterpret.

@Test
public void testInterpret() throws InterruptedException, IOException {
    InterpreterResult result = pythonInterpreter.interpret("print (\"hi\")", context);
    assertEquals(InterpreterResult.Code.SUCCESS, result.code());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Test(org.junit.Test)

Example 30 with InterpreterResult

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

the class PythonInterpreterTest method testInterpretInvalidSyntax.

@Test
public void testInterpretInvalidSyntax() throws IOException {
    InterpreterResult result = pythonInterpreter.interpret("for x in range(0,3):  print (\"hi\")\n", context);
    assertEquals(InterpreterResult.Code.SUCCESS, result.code());
    assertTrue(new String(out.getOutputAt(0).toByteArray()).contains("hi\nhi\nhi"));
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Test(org.junit.Test)

Aggregations

InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)159 Test (org.junit.Test)68 Properties (java.util.Properties)17 File (java.io.File)10 IOException (java.io.IOException)9 AlluxioURI (alluxio.AlluxioURI)8 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)7 Theory (org.junit.experimental.theories.Theory)7 FileWriter (java.io.FileWriter)6 PrintStream (java.io.PrintStream)5 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)5 Code (org.apache.zeppelin.interpreter.InterpreterResult.Code)5 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)5 ActionResponse (org.apache.zeppelin.elasticsearch.action.ActionResponse)4 FileInStream (alluxio.client.file.FileInStream)3 JsonObject (com.google.gson.JsonObject)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 SQLException (java.sql.SQLException)3 HashMap (java.util.HashMap)3