> For the complete documentation index, see [llms.txt](https://zjffdu.gitbook.io/flink-on-zeppelin/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zjffdu.gitbook.io/flink-on-zeppelin/languages/scala.md).

# Scala

## Introduction

Scala is the default language of Flink on Zeppelin（`%flink`), and it is also the entry point of Flink interpreter. Underneath Flink Interpreter will create scala shell which would create several variables, including ExecutionEnvironment，StreamExecutionEnvironment and so on. So don't create these Flink environment variables again, otherwise you might hit weird issues. The scala code you write in Zeppelin will be submitted to this scala shell.  Here are the builtin variables created in  flink scala shell.

* `senv` (StreamExecutionEnvironment),
* `benv` (ExecutionEnvironment)
* `stenv` (StreamTableEnvironment for blink planner)
* `btenv` (BatchTableEnvironment for blink planner)
* `stenv_2` (StreamTableEnvironment for flink planner)
* `btenv_2` (BatchTableEnvironment for flink planner)
* `z`  (ZeppelinContext)

## Blink/Flink Planner <a href="#b410" id="b410"></a>

There’re 2 sql planners supported by flink’s table api: `flink` & `blink`.

* If you want to use DataSet api, and convert it to flink table then please use flink planner (`btenv_2` and `stenv_2`).
* In other cases, we would always recommend you to use blink planner (`btenv` and `stenv`). This is also what flink batch/streaming sql interpreter use underneath (`%flink.bsql` & `%flink.ssql`)

Check this [link](https://ci.apache.org/projects/flink/flink-docs-release-1.10/dev/table/common.html#main-differences-between-the-two-planners) for the details about these 2 planners.

## Stream WordCount Example

You can write whatever flink scala code in Zeppelin. e.g. In the following example, we write a classical streaming wordcount job and print the result.

![](https://3876819094-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEawVq7dzi4LX1-ifgT%2F-MG6jXKdqsptukyw5BUF%2F-MG6kFm8TyEY3A-769zG%2Fimage.png?alt=media\&token=dd23b816-4600-4508-bbd0-3843404f325c)

## Other Features

Besides that Zeppelin also enhance the scala shell with several user-friendly features.

### Code Completion

You can type tab to get code completion.

![](https://3876819094-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEawVq7dzi4LX1-ifgT%2F-MF4z0Ms7TKfsPBpwJih%2F-MF4zsvvpNnUwF-Ofroj%2Fimage.png?alt=media\&token=2666c4de-2343-4c6d-9c7c-1e66d102f22b)

### ZeppelinContext

ZeppelinContext (`z`) provides several advanced features for you, e.g. you can use `z.show` to display DataSet, Batch Table, Streaming Table

#### z.show(DataSet)

![](https://3876819094-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEawVq7dzi4LX1-ifgT%2F-MF4z0Ms7TKfsPBpwJih%2F-MF5-02beFI02kx5xx0S%2Fimage.png?alt=media\&token=cc08bab6-4e29-481e-8fdd-00d76b3d7d43)

#### z.show(Batch Table) <a href="#wgxnn" id="wgxnn"></a>

![](https://3876819094-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEawVq7dzi4LX1-ifgT%2F-MF4z0Ms7TKfsPBpwJih%2F-MF5-DUbjAghghkHSI6i%2Fimage.png?alt=media\&token=06ba61cc-d039-4b81-b156-24e67b8bbd7f)

#### z.show(Stream Table) <a href="#repro" id="repro"></a>

![](https://3876819094-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEawVq7dzi4LX1-ifgT%2F-MF4z0Ms7TKfsPBpwJih%2F-MF5-JfF-ZAhygzTg7AN%2Fimage.png?alt=media\&token=b12532ea-2b01-4e83-abb5-5263c2ffe281)

## Video Tutorial

{% embed url="<https://youtu.be/hQcHKNstlKM?list=PL4oy12nnS7FFtg3KV1iS5vDb0pTz12VcX>" %}

## Community

Join Zeppelin community to discuss with others&#x20;

{% embed url="<http://zeppelin.apache.org/community.html>" %}
