use of org.apache.zeppelin.interpreter.InterpreterResult in project zeppelin by apache.
the class FlinkInterpreterTest method testSimpleStatementWithSystemOutput.
@Test
public void testSimpleStatementWithSystemOutput() {
InterpreterResult result = flink.interpret("val a=1", context);
result = flink.interpret("System.out.print(a)", context);
assertEquals("1", result.message().get(0).getData());
}
use of org.apache.zeppelin.interpreter.InterpreterResult in project zeppelin by apache.
the class FlinkInterpreterTest method testWordCount.
@Test
public void testWordCount() {
flink.interpret("val text = benv.fromElements(\"To be or not to be\")", context);
flink.interpret("val counts = text.flatMap { _.toLowerCase.split(\" \") }.map { (_, 1) }.groupBy(0).sum(1)", context);
InterpreterResult result = flink.interpret("counts.print()", context);
assertEquals(Code.SUCCESS, result.code());
String[] expectedCounts = { "(to,2)", "(be,2)", "(or,1)", "(not,1)" };
Arrays.sort(expectedCounts);
String[] counts = result.message().get(0).getData().split("\n");
Arrays.sort(counts);
assertArrayEquals(expectedCounts, counts);
}
use of org.apache.zeppelin.interpreter.InterpreterResult in project zeppelin by apache.
the class GeodeOqlInterpreter method executeOql.
private InterpreterResult executeOql(String oql) {
try {
if (getExceptionOnConnect() != null) {
return new InterpreterResult(Code.ERROR, getExceptionOnConnect().getMessage());
}
@SuppressWarnings("unchecked") SelectResults<Object> results = (SelectResults<Object>) getQueryService().newQuery(oql).execute();
StringBuilder msg = new StringBuilder(TABLE_MAGIC_TAG);
boolean isTableHeaderSet = false;
Iterator<Object> iterator = results.iterator();
int rowDisplayCount = 0;
while (iterator.hasNext() && (rowDisplayCount < getMaxResult())) {
Object entry = iterator.next();
rowDisplayCount++;
if (entry instanceof Number) {
handleNumberEntry(isTableHeaderSet, entry, msg);
} else if (entry instanceof Struct) {
handleStructEntry(isTableHeaderSet, entry, msg);
} else if (entry instanceof PdxInstance) {
handlePdxInstanceEntry(isTableHeaderSet, entry, msg);
} else {
handleUnsupportedTypeEntry(isTableHeaderSet, entry, msg);
}
isTableHeaderSet = true;
msg.append(NEWLINE);
}
return new InterpreterResult(Code.SUCCESS, msg.toString());
} catch (Exception ex) {
logger.error("Cannot run " + oql, ex);
return new InterpreterResult(Code.ERROR, ex.getMessage());
}
}
use of org.apache.zeppelin.interpreter.InterpreterResult in project zeppelin by apache.
the class GeodeOqlInterpreterTest method testOql.
private void testOql(Iterator<Object> queryResponseIterator, String expectedOutput, int maxResult) throws Exception {
GeodeOqlInterpreter spyGeodeOqlInterpreter = spy(new GeodeOqlInterpreter(new Properties()));
QueryService mockQueryService = mock(QueryService.class, RETURNS_DEEP_STUBS);
when(spyGeodeOqlInterpreter.getQueryService()).thenReturn(mockQueryService);
when(spyGeodeOqlInterpreter.getMaxResult()).thenReturn(maxResult);
@SuppressWarnings("unchecked") SelectResults<Object> mockResults = mock(SelectResults.class);
when(mockQueryService.newQuery(eq(OQL_QUERY)).execute()).thenReturn(mockResults);
when(mockResults.iterator()).thenReturn(queryResponseIterator);
InterpreterResult interpreterResult = spyGeodeOqlInterpreter.interpret(OQL_QUERY, null);
assertEquals(Code.SUCCESS, interpreterResult.code());
assertEquals(expectedOutput, interpreterResult.message().get(0).getData());
}
use of org.apache.zeppelin.interpreter.InterpreterResult in project zeppelin by apache.
the class GeodeOqlInterpreterTest method oqlWithQueryException.
@Test
public void oqlWithQueryException() throws Exception {
GeodeOqlInterpreter spyGeodeOqlInterpreter = spy(new GeodeOqlInterpreter(new Properties()));
when(spyGeodeOqlInterpreter.getExceptionOnConnect()).thenReturn(new RuntimeException("Test Exception On Connect"));
InterpreterResult interpreterResult = spyGeodeOqlInterpreter.interpret(OQL_QUERY, null);
assertEquals(Code.ERROR, interpreterResult.code());
assertEquals("Test Exception On Connect", interpreterResult.message().get(0).getData());
}
Aggregations