mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
### What is this PR for? **New Java interpreter** There are several Java libraries that could be used to leverage the Data Visualization & Collaboration features of Zeppelin hence the need of a Java interpreter to run any java code / library with no further dependencies. Dependencies to any java library can be added by the end users in the Java Zeppelin interpreter Dependencies settings section. ### What type of PR is it? * Feature ### Todos * Any feedback from reviewers ### What is the Jira issue? * [ZEPPELIN-3653] ### How should this be tested? Manually * Start the Zeppelin server * Create a new note with the java interpreter binding * Write some java code as per documentation (docs/interpreter/java.md) Unit tests * Run unit tests (JavaInterpreterTest.java and JavaInterpreterUtilsTest.java) ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? No, the dependency on com.thoughtworks.qdox was already added as part of the Beam Interpreter. * Is there breaking changes for older versions? No. * Does this needs documentation? Yes, it has been added to the PR, see docs/interpreter/java.md. Author: Vincenzo Selvaggio <vselvaggio@hotmail.it> Closes #3092 from selvinsource/java-interpreter and squashes the following commits:c5f96b27d[Vincenzo Selvaggio] Excluding java interpreter from zeppelin-server tests.3f85f1cd3[Vincenzo Selvaggio] Removed redundant java profile as result of rebasing.b68634034[Vincenzo Selvaggio] Updated documentation for Java interpreter to be more explicit on the limitations.ce9401079[Vincenzo Selvaggio] Updated Java Interpreter README and documentation.9e9a859e9[Vincenzo Selvaggio] Stylecheck fixes.706aa0795[Vincenzo Selvaggio] PR reviews changes: -updated interpreter list -direct import of java module and update related README -static logger for Java interpreterd2358f5dc[Vincenzo Selvaggio] Updated documentation for Java interpreter by adding relevant examples.b57f1cfd0[Vincenzo Selvaggio] Added Java Interpreter Utils and tests for them.f542a4f61[Vincenzo Selvaggio] Java Interpreter first version
1.9 KiB
1.9 KiB
| layout | title | description | group |
|---|---|---|---|
| page | Java interpreter in Apache Zeppelin | Run Java code and any distributed java computation library by importing the dependencies in the interpreter configuration. | interpreter |
{% include JB/setup %}
Java interpreter for Apache Zeppelin
How to use
Basically, you can write normal java code. You should write the main method inside a class because the interpreter invoke this main to execute the code. Unlike Zeppelin normal pattern, each paragraph is considered as a separate job, there isn't any relation to any other paragraph. For example, a variable defined in one paragraph cannot be used in another one as each paragraph is a self contained java main class that is executed and the output returned to Zeppelin.
The following is a demonstration of a word count example with data represented as a java Map and displayed leveraging Zeppelin's built in visualization using the utility method JavaInterpreterUtils.displayTableFromSimpleMap.
%java
import java.util.HashMap;
import java.util.Map;
import org.apache.zeppelin.java.JavaInterpreterUtils;
public class HelloWorld {
public static void main(String[] args) {
Map<String, Long> counts = new HashMap<>();
counts.put("hello",4L);
counts.put("world",5L);
System.out.println(JavaInterpreterUtils.displayTableFromSimpleMap("Word","Count", counts));
}
}