Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
881cb41
Added kotlin interpreter stub
dkaznacheev Jul 4, 2019
61ff6d3
Loading compiler configuration
dkaznacheev Jul 4, 2019
bf6825e
Added kotlin REPL interpreter with IO stubs
dkaznacheev Jul 4, 2019
2cca5c9
Fixed kotlin interpreter, path to java and kotlin runtimes are hardcoded
dkaznacheev Jul 8, 2019
4016576
Turned on Kotlin syntax highlighting
dkaznacheev Jul 8, 2019
422c76d
Added output and cancellation
dkaznacheev Jul 8, 2019
d79df4d
Implemented kotlin repl diagnostic message holder
dkaznacheev Jul 8, 2019
bc018c7
Added tests
dkaznacheev Jul 8, 2019
6add47d
Minor cleanups
dkaznacheev Jul 9, 2019
b29c448
Added bind method to Kotlin interpreter
dkaznacheev Jul 12, 2019
6c01762
Changed KotlinInterpreter to use new scripting API
dkaznacheev Jul 17, 2019
634b757
Added object binding to KotlinInterpreter
dkaznacheev Jul 17, 2019
f135a06
Added Kotlin Spark interpreter stub
dkaznacheev Jul 12, 2019
eed0d94
Fixed maven-enforcer package version error
dkaznacheev Jul 12, 2019
01cd61e
Updated KotlinInterpreter to use new API
dkaznacheev Jul 18, 2019
d196552
Attempt to add spark context to ExecutionContext
dkaznacheev Jul 18, 2019
2eeb2f6
Reordered imports for checkstyle
dkaznacheev Jul 18, 2019
eb00b5c
Passing compiler options to KotlinInterpreter
dkaznacheev Jul 18, 2019
b9a3927
Fixed REPLInterpreter not using builder
dkaznacheev Jul 22, 2019
04e86d1
Added class writing to classoutputdir
dkaznacheev Jul 22, 2019
d89dbe6
Shading jpountz module
dkaznacheev Jul 24, 2019
d478dd1
Switched to local kotlin JARs with bugfixes
dkaznacheev Jul 26, 2019
ea024b5
Added ZeppelinContext to ExecutionContext
dkaznacheev Jul 26, 2019
62d87c1
Fixed show in ZeppelinContext
dkaznacheev Jul 26, 2019
fb5a64b
Fixed interpreter output error
dkaznacheev Jul 29, 2019
b9e9f7e
Refactored Kotlin execution context
dkaznacheev Jul 29, 2019
4aaf0bb
Added kotlin interpreter to SparkZeppelinContext list of interpreters
dkaznacheev Jul 30, 2019
019a7c5
Added ZeppelinContext to default Kotlin Interpreter
dkaznacheev Jul 30, 2019
de1cd14
Refactoring: renamed KotlinContext and children to KotlinReceiver to …
dkaznacheev Jul 30, 2019
060a822
Added max result output limit for Kotlin REPL
dkaznacheev Jul 30, 2019
76eaf17
Fixed max result output limit for Kotlin REPL
dkaznacheev Jul 30, 2019
64f5849
Removed local mvn repo dependencies
dkaznacheev Aug 14, 2019
6d48f6f
Added SQLContext to spark kotlin context
dkaznacheev Aug 14, 2019
e919e92
Fixed zeppelin dynamic forms overriding kotlin string interpolation
dkaznacheev Aug 14, 2019
cbe0ed0
Fixed dataframe show() and showSchema() not working
dkaznacheev Aug 14, 2019
21bb458
Refactored df show fix
dkaznacheev Aug 14, 2019
0b95f1f
Added Apache 2.0 license to project files
dkaznacheev Aug 15, 2019
7b2ed79
Added initial code execution to KotlinRepl
dkaznacheev Aug 15, 2019
7c9ea16
Added z.select binding for Kotlin
dkaznacheev Aug 15, 2019
fc88280
Fixed spark job cancellation for kotlin interpreter
dkaznacheev Aug 15, 2019
54bdbdd
setting spark scheduler pool for Kotlin
dkaznacheev Aug 15, 2019
fec0b9b
Fixing kotlin zeppelin interpreter not working
dkaznacheev Aug 16, 2019
8e7221e
Updated tests for plain Kotlin interpreter
dkaznacheev Aug 16, 2019
0a71d93
Added output test
dkaznacheev Aug 16, 2019
839361f
Resolved dependency issues on test run
dkaznacheev Aug 16, 2019
0b2ab05
Added cancellation and runtime exception tests for Kotlin interpreter
dkaznacheev Aug 16, 2019
6d30cf3
Added tests for Kotlin Spark interpreter
dkaznacheev Aug 16, 2019
040d00e
(not pretty) Fixed not writing in-memory Kotlin classes to repl outpu…
dkaznacheev Aug 19, 2019
e1e05c8
Refactored in-memory class output
dkaznacheev Aug 19, 2019
0cc65bf
Added spark job cancellation test
dkaznacheev Aug 19, 2019
f1c4188
Fixed spark cancel test
dkaznacheev Aug 19, 2019
7cd7d34
Removed z from base kotlin interpreter
dkaznacheev Aug 19, 2019
375e175
Fixed BaseZeppelinContext compile error
dkaznacheev Aug 20, 2019
99f4342
Fixed z.select for Kotlin
dkaznacheev Aug 20, 2019
d30a1e4
Importing java udf libraries on startup
dkaznacheev Aug 21, 2019
54a322f
Retrieving variables from runtime
dkaznacheev Aug 21, 2019
0d5316b
Cleaned up getting variables in runtime
dkaznacheev Aug 22, 2019
87c1e14
Passing variable list to implicit receiver
dkaznacheev Aug 22, 2019
4565a9e
Kotlin implicit receiver refactoring
dkaznacheev Aug 22, 2019
95f6a47
Added method retrieving and optimized variable retrieving
dkaznacheev Aug 23, 2019
64fe5fe
Updated completion
dkaznacheev Aug 23, 2019
0bcdb08
Added Kotlin keywords to completion
dkaznacheev Aug 23, 2019
6f59e4b
Added Kotlin types to completion
dkaznacheev Aug 23, 2019
9f0eb82
Skipping conversion of types with type parameters
dkaznacheev Aug 23, 2019
8d1d09e
Added tests for output classes
dkaznacheev Aug 23, 2019
26997ea
Added and updated Kotlin documentation
dkaznacheev Aug 26, 2019
e80f213
Refactored classpath setting
dkaznacheev Aug 27, 2019
3a89c90
Fixed imports loading
dkaznacheev Aug 27, 2019
d3f705d
InvokeWrapper problem
khud Aug 27, 2019
b3a09e5
Fixed variable updating and invoking wrapper from JvmReplEvaluator
dkaznacheev Aug 27, 2019
a7ee65c
Fixed failing on getting wrapper type
dkaznacheev Aug 27, 2019
85727cd
Syncing with old kotlin-spark-interpreter branch
dkaznacheev Aug 27, 2019
b9584de
Fixed competion on first cell in kotlin
dkaznacheev Aug 27, 2019
9914ed6
Fixed completion order
dkaznacheev Aug 27, 2019
163a11f
Fixed retrieving variables from receivers and their child classes
dkaznacheev Aug 29, 2019
60ed6be
Fixed tests in KotlinSparkInterpreter
dkaznacheev Aug 29, 2019
9a35902
Migrated to kotlin 1.3.50 from maven-central: updated tests
dkaznacheev Aug 29, 2019
0f95b1f
Added default classpath and maxResult to ReplBuilder
dkaznacheev Aug 30, 2019
cf488ca
(WIP) moved KotlinReflectUtil to actual Kotlin types
dkaznacheev Aug 30, 2019
7c48cfa
Moved KotlinReflectUtil to actual Kotlin types, updated tests
dkaznacheev Sep 2, 2019
38bb29f
Added test for class writing in kotlin spark interpreter
dkaznacheev Sep 2, 2019
9979d03
Refactored variables and methods search to separate class
dkaznacheev Sep 2, 2019
ad91bcc
Implemented type shortening
dkaznacheev Sep 2, 2019
251ea5a
Moved type shortening to an interpreter property
dkaznacheev Sep 2, 2019
78426cb
Fixed interpreter settings
dkaznacheev Sep 2, 2019
26fac22
Fixed completion shortening
dkaznacheev Sep 2, 2019
a08aa6b
Moved class output to separate class
dkaznacheev Sep 3, 2019
8d9e935
Refactored REPL evaluation
dkaznacheev Sep 3, 2019
c6c400d
Moved kotlin REPL to separate package
dkaznacheev Sep 3, 2019
1206df3
Refactored REPL creation and properties setting
dkaznacheev Sep 3, 2019
5c170f0
Added comments for Kotlin REPL
dkaznacheev Sep 3, 2019
1269ee6
refactored KotlinRepl constructor
dkaznacheev Sep 3, 2019
79e2036
Fixed type shortening in showFunctions()
dkaznacheev Sep 3, 2019
2b42a6f
Fixed beam module not working
dkaznacheev Sep 3, 2019
3120f1a
Updated Zeppelin documentation
dkaznacheev Sep 3, 2019
cc12fe8
Fixed bug with duplicate functions
dkaznacheev Sep 3, 2019
8fc1be8
Added Kotlin interpreter to Travis testing
dkaznacheev Sep 3, 2019
140265c
Fixing checkstyle violations
dkaznacheev Sep 3, 2019
ecd1f5d
Disabled Spark versions older than 2.4 to avoid build issues
dkaznacheev Sep 5, 2019
b444001
updated LICENSE
dkaznacheev Sep 6, 2019
db495e8
Removed unneccessary scala dependency
dkaznacheev Sep 6, 2019
deb152e
Wrapped output redirection in try/finally
dkaznacheev Sep 6, 2019
065f0e2
Various PR fixes
dkaznacheev Sep 30, 2019
54eebe3
Added README.md for Kotlin interpreter
dkaznacheev Oct 16, 2019
61f666b
Added guide to testing and possible improvements
dkaznacheev Oct 17, 2019
476fa37
Fixed spark version checking
dkaznacheev Oct 17, 2019
2c25a7d
Minor PR fixes
dkaznacheev Nov 8, 2019
171a35b
Minor PR fixes
dkaznacheev Nov 8, 2019
2984577
Error fixes in classpath and type printing
dkaznacheev Nov 8, 2019
6e10ed7
Merge branch 'refs/heads/master' into kotlin-spark-interpreter
ileasile Nov 11, 2019
eacb964
Added a comment about repl history records
dkaznacheev Nov 11, 2019
92f00af
Fix comment
ileasile Nov 12, 2019
7a5252d
Fix comment indentation
ileasile Nov 12, 2019
29a4dba
Merge branch 'refs/heads/master' into kotlin-spark-interpreter
ileasile Nov 13, 2019
c8ebf79
[ZEPPELIN-4323] Merge branch 'refs/heads/master' into kotlin-spark-in…
ileasile Nov 13, 2019
347c9eb
Fix KotlinSpark interpreter test for old versions of spark.
ileasile Nov 13, 2019
4358084
Include kotlin interpreter in zeppelin_server builds
ileasile Nov 14, 2019
c8e68e3
Merge branch 'master' into kotlin-spark-interpreter
ileasile Nov 14, 2019
ad2c1a9
Increased memory limits
ileasile Nov 15, 2019
9d5b6a3
Temporary fix for hadoop_lzo
ileasile Nov 15, 2019
ad0380f
Changed hadoop-lzo repo and added Kotlin test
ileasile Nov 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ matrix:
- sudo: required
jdk: "openjdk8"
dist: xenial
env: BUILD_PLUGINS="true" PYTHON="3" SCALA_VER="2.11" PROFILE="-Pspark-2.4 -Pspark-scala-2.11 -Phadoop2 -Pintegration" SPARKR="true" BUILD_FLAG="install -DskipTests -DskipRat -am" TEST_FLAG="test -DskipRat -am" MODULES="-pl zeppelin-interpreter-integration,jdbc,zeppelin-web,spark/spark-dependencies,markdown" TEST_PROJECTS="-Dtest=ZeppelinSparkClusterTest24,SparkIntegrationTest24,JdbcIntegrationTest,org.apache.zeppelin.spark.* -DfailIfNoTests=false"
env: BUILD_PLUGINS="true" PYTHON="3" SCALA_VER="2.11" PROFILE="-Pspark-2.4 -Pspark-scala-2.11 -Phadoop2 -Pintegration" SPARKR="true" BUILD_FLAG="install -DskipTests -DskipRat -am" TEST_FLAG="test -DskipRat -am" MODULES="-pl zeppelin-interpreter-integration,jdbc,zeppelin-web,spark/spark-dependencies,markdown" TEST_PROJECTS="-Dtest=ZeppelinSparkClusterTest24,SparkIntegrationTest24,JdbcIntegrationTest,org.apache.zeppelin.spark.*,org.apache.zeppelin.kotlin.* -DfailIfNoTests=false"

# ZeppelinSparkClusterTest24, SparkIntegrationTest24, JdbcIntegrationTest, Unit test of Spark 2.4 (Scala-2.12)
- sudo: required
jdk: "openjdk8"
dist: xenial
env: BUILD_PLUGINS="true" PYTHON="3" SCALA_VER="2.12" PROFILE="-Pspark-2.4 -Pspark-scala-2.12 -Phadoop2 -Pintegration" SPARKR="true" BUILD_FLAG="install -DskipTests -DskipRat -am" TEST_FLAG="test -DskipRat -am" MODULES="-pl zeppelin-interpreter-integration,jdbc,zeppelin-web,spark/spark-dependencies,markdown" TEST_PROJECTS="-Dtest=ZeppelinSparkClusterTest24,SparkIntegrationTest24,JdbcIntegrationTest,org.apache.zeppelin.spark.* -DfailIfNoTests=false"
env: BUILD_PLUGINS="true" PYTHON="3" SCALA_VER="2.12" PROFILE="-Pspark-2.4 -Pspark-scala-2.12 -Phadoop2 -Pintegration" SPARKR="true" BUILD_FLAG="install -DskipTests -DskipRat -am" TEST_FLAG="test -DskipRat -am" MODULES="-pl zeppelin-interpreter-integration,jdbc,zeppelin-web,spark/spark-dependencies,markdown" TEST_PROJECTS="-Dtest=ZeppelinSparkClusterTest24,SparkIntegrationTest24,JdbcIntegrationTest,org.apache.zeppelin.spark.*,org.apache.zeppelin.kotlin.* -DfailIfNoTests=false"

# ZeppelinSparkClusterTest23, SparkIntegrationTest23, Unit test of Spark 2.3 (Scala-2.11) and Unit test PythonInterpreter under python2
- sudo: required
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ The text of each license is also included at licenses/LICENSE-[project]-[version
(Apache 2.0) Google Cloud Client Library for Java (https://github.com/GoogleCloudPlatform/google-cloud-java)
(Apache 2.0) concurrentunit (https://github.com/jhalterman/concurrentunit)
(Apache 2.0) Embedded MongoDB (https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo)
(Apache 2.0) Kotlin (https://github.com/JetBrains/kotlin)

========================================================================
BSD 3-Clause licenses
Expand Down
2 changes: 1 addition & 1 deletion bin/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ if [[ -z "${ZEPPELIN_MEM}" ]]; then
fi

if [[ -z "${ZEPPELIN_INTP_MEM}" ]]; then
export ZEPPELIN_INTP_MEM="-Xms1024m -Xmx1024m -XX:MaxPermSize=512m"
export ZEPPELIN_INTP_MEM="-Xms1024m -Xmx2048m -XX:MaxPermSize=512m"
fi

JAVA_OPTS+=" ${ZEPPELIN_JAVA_OPTS} -Dfile.encoding=${ZEPPELIN_ENCODING} ${ZEPPELIN_MEM}"
Expand Down
1 change: 1 addition & 0 deletions conf/interpreter-list
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ hbase org.apache.zeppelin:zeppelin-hbase:0.9.0 Hbase in
ignite org.apache.zeppelin:zeppelin-ignite:0.9.0 Ignite interpreter
java org.apache.zeppelin:zeppelin-java:0.9.0 Java interpreter
jdbc org.apache.zeppelin:zeppelin-jdbc:0.9.0 Jdbc interpreter
kotlin org.apache.zeppelin:zeppelin-kotlin:0.9.0 Kotlin interpreter
kylin org.apache.zeppelin:zeppelin-kylin:0.9.0 Kylin interpreter
lens org.apache.zeppelin:zeppelin-lens:0.9.0 Lens interpreter
livy org.apache.zeppelin:zeppelin-livy:0.9.0 Livy interpreter
Expand Down
1 change: 1 addition & 0 deletions docs/_includes/themes/zeppelin/_navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
<li><a href="{{BASE_PATH}}/interpreter/hive.html">Hive</a></li>
<li><a href="{{BASE_PATH}}/interpreter/ignite.html">Ignite</a></li>
<li><a href="{{BASE_PATH}}/interpreter/java.html">Java</a></li>
<li><a href="{{BASE_PATH}}/interpreter/kotlin.html">Kotlin</a></li>
<li><a href="{{BASE_PATH}}/interpreter/kylin.html">Kylin</a></li>
<li><a href="{{BASE_PATH}}/interpreter/lens.html">Lens</a></li>
<li><a href="{{BASE_PATH}}/interpreter/livy.html">Livy</a></li>
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ limitations under the License.
* [Ignite](./interpreter/ignite.html)
* [JDBC](./interpreter/jdbc.html)
* [Kylin](./interpreter/kylin.html)
* [Kotlin](./interpreter/kotlin.html)
* [Lens](./interpreter/lens.html)
* [Livy](./interpreter/livy.html)
* [Mahout](./interpreter/mahout.html)
Expand Down
79 changes: 79 additions & 0 deletions docs/interpreter/kotlin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
layout: page
title: "Kotlin interpreter in Apache Zeppelin"
description: "Kotlin is a cross-platform, statically typed, general-purpose programming language with type inference."
group: interpreter
---
<!--
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

{% include JB/setup %}

# Kotlin interpreter for Apache Zeppelin

<div id="toc"></div>

## Overview
Kotlin is a cross-platform, statically typed, general-purpose programming language with type inference.
It is designed to interoperate fully with Java, and the JVM version of its standard library depends on the Java Class Library, but type inference allows its syntax to be more concise.

## Configuration
<table class="table-configuration">
<tr>
<th>Name</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>zeppelin.kotlin.maxResult</td>
<td>1000</td>
<td>Max n
<tr>
<td>zeppelin.kotlin.shortenTypes</td>
<td>true</td>
<td>Display shortened types instead of full, e.g. Int vs kotlin.Int</td>
</tr>
</table>

## Example

```kotlin
%kotlin

fun square(n: Int): Int = n * n
```

## Kotlin Context
Kotlin context is accessible via `kc` object bound to the interpreter.
It holds `vars` and `functions` fields that return all user-defined variables and functions present in the interpreter.
You can also print variables or functions by calling `kc.showVars()` or `kc.showFunctions()`.

### Example


```kotlin
fun square(n: Int): Int = n * n

val greeter = { s: String -> println("Hello $s!") }
val l = listOf("Drive", "to", "develop")

kc.showVars()
kc.showFunctions()
```
Output:
```
l: List<String> = [Drive, to, develop]
greeter: (String) -> Unit = (kotlin.String) -> kotlin.Unit
fun square(Int): Int
```
9 changes: 7 additions & 2 deletions docs/interpreter/spark.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ limitations under the License.
## Overview
[Apache Spark](http://spark.apache.org) is a fast and general-purpose cluster computing system.
It provides high-level APIs in Java, Scala, Python and R, and an optimized engine that supports general execution graphs.
Apache Spark is supported in Zeppelin with Spark interpreter group which consists of below five interpreters.
Apache Spark is supported in Zeppelin with Spark interpreter group which consists of below six interpreters.

<table class="table-configuration">
<tr>
Expand All @@ -39,6 +39,11 @@ Apache Spark is supported in Zeppelin with Spark interpreter group which consist
<td>SparkInterpreter</td>
<td>Creates a SparkContext and provides a Scala environment</td>
</tr>
<tr>
<td>%spark.kotlin</td>
<td>KotlinSparkInterpreter</td>
<td>Provides a Kotlin environment</td>
</tr>
<tr>
<td>%spark.pyspark</td>
<td>PySparkInterpreter</td>
Expand Down Expand Up @@ -217,7 +222,7 @@ in interpreter setting page means you can use multiple versions of `spark` & `ha
Starting from 0.9, we totally removed the old spark interpreter implementation, and make the new spark interpreter as the official spark interpreter.

## SparkContext, SQLContext, SparkSession, ZeppelinContext
SparkContext, SQLContext and ZeppelinContext are automatically created and exposed as variable names `sc`, `sqlContext` and `z`, respectively, in Scala, Python and R environments.
SparkContext, SQLContext and ZeppelinContext are automatically created and exposed as variable names `sc`, `sqlContext` and `z`, respectively, in Scala, Kotlin, Python and R environments.
Staring from 0.6.1 SparkSession is available as variable `spark` when you are using Spark 2.x.

> Note that Scala/Python/R environment shares the same SparkContext, SQLContext and ZeppelinContext instance.
Expand Down
5 changes: 5 additions & 0 deletions docs/usage/interpreter/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ You can also find the below community managed interpreter list in `conf/interpre
<td>org.apache.zeppelin:zeppelin-jdbc:0.9.0</td>
<td>Jdbc interpreter</td>
</tr>
<tr>
<td>kotlin</td>
<td>org.apache.zeppelin:zeppelin-kotlin:0.7.0</td>
<td>Kotlin interpreter</td>
</tr>
<tr>
<td>kylin</td>
<td>org.apache.zeppelin:zeppelin-kylin:0.9.0</td>
Expand Down
83 changes: 83 additions & 0 deletions kotlin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Developer guide to Kotlin interpreter

The following module adds Kotlin language support to Apache Zeppelin.
Here is the guide to its implementation and how it can be improved and tested.

## Implementation details
### Kotlin REPL
For interactive Kotlin execution, an instance of `KotlinRepl` is created.
To set REPL properties (such as classpath, generated classes output directory, max result, etc.),
pass `KotlinReplProperties` to its constructor. For example:
```$java
KotlinReplProperties replProperties = new KotlinReplProperties()
.maxResult(1000)
.shortenTypes(true);
KotlinRepl repl = new KotlinRepl(replProperties);
```

### Variable/function binding
You can also bind variables and functions on REPL creation using implicit receiver language feature.
This means that all code run in REPL will be executed in Kotlin's `with` block with the receiver,
making the receiver's fields and methods accessible.

To add your variables/functions, extend `KotlinReceiver` class (in separate file), declare your fields and methods, and pass an instance of it to
`KotlinReplProperties`. Example:
```$java
// In separate file:
class CustomReceiver extends KotlinReceiver {
public int myValue = 1 // will be converted to Kotlin "var myValue: Int"
public final String messageTemplate = "Value = %VALUE%" // "val messageTemplate: String"

public String getMessage() {
return messageTemplate.replace("%VALUE%", String.valueOf(myValue));
}
}

// In intepreter creation:
replProperties.receiver(new CustomReceiver);
KotlinRepl repl = new KotlinRepl(replProperties);
repl.eval("getMessage()"); // will return interpreterResult with "Value = 1" string
```

In `KotlinInterpreter` REPL properties are created on construction, are accessible via `getKotlinReplProperties` method,
and are used in REPL creation on `open()`.

### Generated class files
Each code snippet run in REPL is registered as a separate class and saved in location
specified by `outputDir` REPL property. Anonymous classes and lambdas also get saved there under specific names.

This is needed for Spark to send classes to remote executors, and in Spark Kotlin interpreter this directory is the same
as in `sparkContext` option `spark.repl.class.outputDir`.

### Kotlin Spark Interpreter
Kotlin interpreter in Spark intepreter group takes `SparkSession`, `JavaSparkContext`, `SQLContext`
and `BaseZeppelinContext` from `SparkInterpreter` in the same session and binds them in its scope.

## Testing
Kotlin Interpreter and Spark Kotlin Interpreter come with unit tests.
They can be run with \
`mvn clean test` \
in `$ZEPPELIN_HOME/kotlin` for base Kotlin Interpreter and \
`mvn -Dtest=KotlinSparkInterpreterTest test` \
in `$ZEPPELIN_HOME/spark/interpreter` for Spark Kotlin Interpreter.

To test manually, build Zeppelin with \
`mvn clean package -DskipTests` \
and create a note with `kotlin` interpreter for base or `spark` for Spark.
In Spark interpreter, add `%spark.kotlin` in the start of paragraph to use Kotlin Spark Interpreter.

Example:
```$kotlin
%spark.kotlin
val df = spark.range(10)
df.show()
```
## Possible Improvements
* It would be great to bind `ZeppelinContext` to base Kotlin interpreter, but for now I had trouble instantiating it
inside KotlinInterpreter.
* When Kotlin has its own Spark API, it will be good to move to it. Currently in Java Spark API Kotlin
can not use things like `forEach` because of ambiguity between `Iterable<?>.forEach` and `Map<?, ?>.forEach`
(`foreach` from Spark's API does work, though).
* The scoped mode for Kotlin Spark Interpreter currently has issues with having the same class output directory
for different intepreters, leading to overwriting classes. Adding prefixes to generated classes or putting them
in separate directories leads to `ClassNotFoundException` on Spark executors.
125 changes: 125 additions & 0 deletions kotlin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>zeppelin-interpreter-parent</artifactId>
<groupId>org.apache.zeppelin</groupId>
<version>0.9.0-SNAPSHOT</version>
<relativePath>../zeppelin-interpreter-parent/pom.xml</relativePath>
</parent>

<groupId>org.apache.zeppelin</groupId>
<artifactId>zeppelin-kotlin</artifactId>
<packaging>jar</packaging>
<version>0.9.0-SNAPSHOT</version>
<name>Zeppelin: Kotlin interpreter</name>

<properties>
<interpreter.name>kotlin</interpreter.name>
<kotlin.version>1.3.50</kotlin.version>
</properties>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-scripting-jvm-host-embeddable</artifactId>
<version>${kotlin.version}</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</exclusion>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-common</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-compiler-embeddable</artifactId>
<version>${kotlin.version}</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-scripting-jvm</artifactId>
<version>${kotlin.version}</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-scripting-compiler-embeddable</artifactId>
<version>${kotlin.version}</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading