use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class RemoteInterpreter method open.
@Override
public void open() throws InterpreterException {
synchronized (this) {
if (!isOpened) {
// also see method Interpreter.getInterpreterInTheSameSessionByClassName
for (Interpreter interpreter : getInterpreterGroup().getOrCreateSession(this.getUserName(), sessionId)) {
try {
if (!(interpreter instanceof ConfInterpreter)) {
((RemoteInterpreter) interpreter).internal_create();
}
} catch (IOException e) {
throw new InterpreterException(e);
}
}
interpreterProcess.callRemoteFunction(client -> {
LOGGER.info("Open RemoteInterpreter {}", getClassName());
// Push angular object loaded from JSON file to remote interpreter
synchronized (getInterpreterGroup()) {
if (!getInterpreterGroup().isAngularRegistryPushed()) {
pushAngularObjectRegistryToRemote(client);
getInterpreterGroup().setAngularRegistryPushed(true);
}
}
return null;
});
isOpened = true;
}
}
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class CassandraInterpreterTest method should_describe_materialized_view.
@Test
@Ignore
public // TODO(n.a.) activate test when using Java 8 and C* 3.x
void should_describe_materialized_view() throws Exception {
// Given
Properties properties = new Properties();
properties.setProperty(CASSANDRA_HOSTS, "127.0.0.1");
properties.setProperty(CASSANDRA_PORT, "9042");
Interpreter interpreter = new CassandraInterpreter(properties);
interpreter.open();
final String query = "DESCRIBE MATERIALIZED VIEWS;";
// When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
// Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class CassandraInterpreterTest method should_describe_function.
@Test
@Ignore
public // TODO(n.a.) activate test when using Java 8 and C* 3.x
void should_describe_function() throws Exception {
// Given
Properties properties = new Properties();
properties.setProperty(CASSANDRA_HOSTS, "127.0.0.1");
properties.setProperty(CASSANDRA_PORT, "9042");
Interpreter interpreter = new CassandraInterpreter(properties);
interpreter.open();
String createFunction = "CREATE FUNCTION zeppelin.maxof(val1 int,val2 int) " + "RETURNS NULL ON NULL INPUT " + "RETURNS int " + "LANGUAGE java " + "AS $$" + " return Math.max(val1, val2);\n" + "$$;";
interpreter.interpret(createFunction, intrContext);
String query = "DESCRIBE FUNCTION zeppelin.maxOf;";
// When
final InterpreterResult actual = interpreter.interpret(query, intrContext);
// Then
assertThat(actual.code()).isEqualTo(Code.SUCCESS);
assertThat(actual.message()).isEqualTo("xxxxx");
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class FlinkIntegrationTest method testInterpreterBasics.
private void testInterpreterBasics() throws IOException, InterpreterException {
// test FlinkInterpreter
Interpreter flinkInterpreter = interpreterFactory.getInterpreter("flink", new ExecutionContext("user1", "note1", "flink"));
InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
InterpreterResult interpreterResult = flinkInterpreter.interpret("1+1", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
assertTrue(interpreterResult.message().get(0).getData().contains("2"));
interpreterResult = flinkInterpreter.interpret("val data = benv.fromElements(1, 2, 3)\ndata.collect()", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
assertTrue(interpreterResult.message().get(0).getData().contains("1, 2, 3"));
interpreterResult = flinkInterpreter.interpret("val data = senv.fromElements(1, 2, 3)\ndata.print()", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
// check spark weburl in zeppelin-server side
InterpreterSetting flinkInterpreterSetting = interpreterSettingManager.getByName("flink");
assertEquals(1, flinkInterpreterSetting.getAllInterpreterGroups().size());
assertNotNull(flinkInterpreterSetting.getAllInterpreterGroups().get(0).getWebUrl());
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class JdbcIntegrationTest method testMySql.
@Test
public void testMySql() throws InterpreterException, InterruptedException {
InterpreterSetting interpreterSetting = interpreterSettingManager.getInterpreterSettingByName("jdbc");
interpreterSetting.setProperty("default.driver", "com.mysql.jdbc.Driver");
interpreterSetting.setProperty("default.url", "jdbc:mysql://localhost:3306/");
interpreterSetting.setProperty("default.user", "root");
interpreterSetting.setProperty("default.password", "root");
Dependency dependency = new Dependency("mysql:mysql-connector-java:5.1.46");
interpreterSetting.setDependencies(Arrays.asList(dependency));
interpreterSettingManager.restart(interpreterSetting.getId());
interpreterSetting.waitForReady(60 * 1000);
Interpreter jdbcInterpreter = interpreterFactory.getInterpreter("jdbc", new ExecutionContext("user1", "note1", "test"));
assertNotNull("JdbcInterpreter is null", jdbcInterpreter);
InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").setAuthenticationInfo(AuthenticationInfo.ANONYMOUS).build();
InterpreterResult interpreterResult = jdbcInterpreter.interpret("show databases;", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
context.getLocalProperties().put("saveAs", "table_1");
interpreterResult = jdbcInterpreter.interpret("SELECT 1 as c1, 2 as c2;", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
assertEquals(1, interpreterResult.message().size());
assertEquals(InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType());
assertEquals("c1\tc2\n1\t2\n", interpreterResult.message().get(0).getData());
// read table_1 from python interpreter
InterpreterSetting pythonInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("python");
pythonInterpreterSetting.setProperty("zeppelin.python.gatewayserver_address", "127.0.0.1");
Interpreter pythonInterpreter = interpreterFactory.getInterpreter("python", new ExecutionContext("user1", "note1", "test"));
assertNotNull("PythonInterpreter is null", pythonInterpreter);
context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").setAuthenticationInfo(AuthenticationInfo.ANONYMOUS).build();
interpreterResult = pythonInterpreter.interpret("df=z.getAsDataFrame('table_1')\nz.show(df)", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
assertEquals(1, interpreterResult.message().size());
assertEquals(InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType());
assertEquals("c1\tc2\n1\t2\n", interpreterResult.message().get(0).getData());
}
Aggregations