Search in sources :

Example 61 with InterpreterResult

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

the class HbaseInterpreterTest method putsTest.

@Test
public void putsTest() {
    InterpreterResult result = hbaseInterpreter.interpret("puts \"Hello World\"", null);
    assertEquals(InterpreterResult.Code.SUCCESS, result.code());
    assertEquals(result.message().get(0).getType(), InterpreterResult.Type.TEXT);
    assertEquals("Hello World\n", result.message().get(0).getData());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Test(org.junit.Test)

Example 62 with InterpreterResult

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

the class IgniteSqlInterpreter method interpret.

@Override
public InterpreterResult interpret(String st, InterpreterContext context) {
    if (connEx != null) {
        return new InterpreterResult(Code.ERROR, connEx.getMessage());
    }
    StringBuilder msg = new StringBuilder("%table ");
    try (Statement stmt = conn.createStatement()) {
        curStmt = stmt;
        try (ResultSet res = stmt.executeQuery(st)) {
            ResultSetMetaData md = res.getMetaData();
            for (int i = 1; i <= md.getColumnCount(); i++) {
                if (i > 1) {
                    msg.append('\t');
                }
                msg.append(md.getColumnName(i));
            }
            msg.append('\n');
            while (res.next()) {
                for (int i = 1; i <= md.getColumnCount(); i++) {
                    msg.append(res.getString(i));
                    if (i != md.getColumnCount()) {
                        msg.append('\t');
                    }
                }
                msg.append('\n');
            }
        }
    } catch (Exception e) {
        logger.error("Exception in IgniteSqlInterpreter while InterpreterResult interpret: ", e);
        return IgniteInterpreterUtils.buildErrorResult(e);
    } finally {
        curStmt = null;
    }
    return new InterpreterResult(Code.SUCCESS, msg.toString());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) SQLException(java.sql.SQLException) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException)

Example 63 with InterpreterResult

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

the class IgniteInterpreterTest method testInterpretInvalidInput.

@Test
public void testInterpretInvalidInput() {
    InterpreterResult result = intp.interpret("invalid input", INTP_CONTEXT);
    assertEquals(InterpreterResult.Code.ERROR, result.code());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Test(org.junit.Test)

Example 64 with InterpreterResult

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

the class IgniteInterpreterTest method testInterpret.

@Test
public void testInterpret() {
    String sizeVal = "size";
    InterpreterResult result = intp.interpret("import org.apache.ignite.IgniteCache\n" + "val " + sizeVal + " = ignite.cluster().nodes().size()", INTP_CONTEXT);
    assertEquals(InterpreterResult.Code.SUCCESS, result.code());
    assertTrue(result.message().get(0).getData().contains(sizeVal + ": Int = " + ignite.cluster().nodes().size()));
    result = intp.interpret("\"123\"\n  .toInt", INTP_CONTEXT);
    assertEquals(InterpreterResult.Code.SUCCESS, result.code());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Test(org.junit.Test)

Example 65 with InterpreterResult

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

the class JDBCInterpreterTest method testIncorrectPrecode.

@Test
public void testIncorrectPrecode() throws SQLException, IOException {
    Properties properties = new Properties();
    properties.setProperty("default.driver", "org.h2.Driver");
    properties.setProperty("default.url", getJdbcConnection());
    properties.setProperty("default.user", "");
    properties.setProperty("default.password", "");
    properties.setProperty(DEFAULT_PRECODE, "incorrect command");
    JDBCInterpreter jdbcInterpreter = new JDBCInterpreter(properties);
    jdbcInterpreter.open();
    String sqlQuery = "select 1";
    InterpreterResult interpreterResult = jdbcInterpreter.interpret(sqlQuery, interpreterContext);
    assertEquals(InterpreterResult.Code.ERROR, interpreterResult.code());
    assertEquals(InterpreterResult.Type.TEXT, interpreterResult.message().get(0).getType());
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Properties(java.util.Properties) 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