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