# Scio 解釋器
原文鏈接 : [http://zeppelin.apache.org/docs/0.7.2/interpreter/scio.html](http://zeppelin.apache.org/docs/0.7.2/interpreter/scio.html)
譯文鏈接 : [http://www.apache.wiki/pages/viewpage.action?pageId=10030912](http://www.apache.wiki/pages/viewpage.action?pageId=10030912)
貢獻者 : [片刻](/display/~jiangzhonglian) [ApacheCN](/display/~apachecn) [Apache中文網](/display/~apachechina)
## 概述?
Scio是[Google云數據流](https://github.com/GoogleCloudPlatform/DataflowJavaSDK)的Scala DSL?和由[Spark](http://spark.apache.org/)和[Scalding](https://github.com/twitter/scalding)啟發的[Apache Beam](http://beam.incubator.apache.org/)。有關更多信息,請參閱當前的[wiki](https://github.com/spotify/scio/wiki)和[API](http://spotify.github.io/scio/)文檔。
## 配置?
| 名稱 | 默認值 | 描述 |
| --- | --- | --- |
| zeppelin.scio.argz | --runner = InProcessPipelineRunner | Scio解釋者廣泛的論據。文檔:[https://github.com/spotify/scio/wiki#options](https://github.com/spotify/scio/wiki#options) 和 [https://cloud.google.com/dataflow/pipelines/specifying-exec-params](https://cloud.google.com/dataflow/pipelines/specifying-exec-params) |
| zeppelin.scio.maxResult | 1000 | 要顯示的最大SC選擇結果數 |
## 啟用Scio解釋器
在筆記本中,要啟用**Scio**解釋器,請單擊**Gear**圖標并選擇**beam**(**beam.scio**)。
## 使用Scio解釋器
在段落中,用于`%beam.scio`選擇**Scio**解釋器。您可以使用與香草Scala REPL和[Scio REPL](https://github.com/spotify/scio/wiki/Scio-REPL)相同的方式。狀態(如變量,導入,執行等)在所有_Scio_段落之間共享。有一個特殊的變量**argz**,它包含來自Scio解釋器設置的參數。最簡單的方法是通過標準創建Scio上下文`ContextAndArgs`。
```
%beam.scio
val (sc, args) = ContextAndArgs(argz)?
```
`sc`以常規管道/ REPL的方式使用上下文。
示例:
```
%beam.scio
val (sc, args) = ContextAndArgs(argz)
sc.parallelize(Seq("foo", "foo", "bar")).countByValue.closeAndDisplay()?
```
如果您關閉Scio上下文,請繼續創建一個新的`ContextAndArgs`。請參考[Scio wiki](https://github.com/spotify/scio/wiki)更復雜的例子。您可以關閉Scio上下文與Scio REPL相同,并使用Zeppelin顯示幫助程序同步關閉并顯示結果 - 在下面閱讀更多。
### 進展
一次只能運行一個段落。沒有總體進展的概念,因此進度條將顯示`0`。
### SCollection顯示助手
Scio解釋器帶有顯示助手,以方便與Zeppelin筆記本電腦的工作。只需使用`closeAndDisplay()`上`SCollection`,關閉背景和顯示結果。結果數量受限于`zeppelin.scio.maxResult`(默認為1000)。
支持的`SCollection`類型:
* Scio鍵入的BigQuery
* Scala的產品(案例 classes, tuples)
* Google BigQuery的TableRow
* Apache Avro
* 所有Scala的?`AnyVal`
**助手方法**
不同的對象有不同的幫助方法。您可以輕松地顯示結果`SCollection`,`Future[Tap]`和`Tap`。
**`SCollection`?幫手**
`SCollection`?`closeAndDisplay`對于上面列出的類型,具有Zeppelin輔助方法。使用它來同步關閉Scio上下文,一旦可用的拉和顯示結果。
**`Future[Tap]`?幫手**
`Future[Tap]`?`waitAndDisplay`對于上面列出的類型,具有Zeppelin輔助方法。使用它來同步等待結果,一旦可用拉和顯示結果。
**`Tap`?幫手**
`Tap`?`display`對于上面列出的類型,具有Zeppelin輔助方法。使用它來拉和顯示結果。
### 示例
BigQuery示例:
```
%beam.scio
@BigQueryType.fromQuery("""|SELECT departure_airport,count(case when departure_delay>0 then 1 else 0 end) as no_of_delays
|FROM [bigquery-samples:airline_ontime_data.flights]
|group by departure_airport
|order by 2 desc
|limit 10""".stripMargin) class Flights
val (sc, args) = ContextAndArgs(argz)
sc.bigQuerySelect(Flights.query).closeAndDisplay(Flights.schema)?
```
BigQuery typed 示例:
```
%beam.scio
@BigQueryType.fromQuery("""|SELECT departure_airport,count(case when departure_delay>0 then 1 else 0 end) as no_of_delays
|FROM [bigquery-samples:airline_ontime_data.flights]
|group by departure_airport
|order by 2 desc
|limit 10""".stripMargin) class Flights
val (sc, args) = ContextAndArgs(argz)
sc.typedBigQuery[Flights]().flatMap(_.no_of_delays).mean.closeAndDisplay()?
```
Avro示例:
```
%beam.scio
import com.spotify.data.ExampleAvro
val (sc, args) = ContextAndArgs(argz)
sc.avroFile[ExampleAvro]("gs://<bucket>/tmp/my.avro").take(10).closeAndDisplay()?
```
具有視圖模式的Avro示例:
```
%beam.scio
import com.spotify.data.ExampleAvro
import org.apache.avro.Schema
val (sc, args) = ContextAndArgs(argz)
val view = Schema.parse("""{"type":"record","name":"ExampleAvro","namespace":"com.spotify.data","fields":[{"name":"track","type":"string"}, {"name":"artist", "type":"string"}]}""")
sc.avroFile[EndSongCleaned]("gs://<bucket>/tmp/my.avro").take(10).closeAndDisplay(view)?
```
### Google憑據
Scio Interpreter會嘗試從其環境推斷出您的Google Cloud憑據,它將進入帳戶:
* `argz`解釋器設置([doc](https://github.com/spotify/scio/wiki#options))
* 環境變量(`GOOGLE_APPLICATION_CREDENTIALS`)
* gcloud配置
**BigQuery宏憑證**
目前用于宏擴展的BigQuery項目是使用Google Dataflow的[DefaultProjectFactory().create()](https://github.com/GoogleCloudPlatform/DataflowJavaSDK/blob/master/sdk/src/main/java/com/google/cloud/dataflow/sdk/options/GcpOptions.java#L187)?推斷的。
- 快速入門
- 什么是Apache Zeppelin?
- 安裝
- 配置
- 探索Apache Zeppelin UI
- 教程
- 動態表單
- 發表你的段落
- 自定義Zeppelin主頁
- 升級Zeppelin版本
- 從源碼編譯
- 使用Flink和Spark Clusters安裝Zeppelin教程
- 解釋器
- 概述
- 解釋器安裝
- 解釋器依賴管理
- 解釋器的模擬用戶
- 解釋員執行Hook(實驗)
- Alluxio 解釋器
- Beam 解釋器
- BigQuery 解釋器
- Cassandra CQL 解釋器
- Elasticsearch 解釋器
- Flink 解釋器
- Geode/Gemfire OQL 解釋器
- HBase Shell 解釋器
- HDFS文件系統 解釋器
- Hive 解釋器
- Ignite 解釋器
- JDBC通用 解釋器
- Kylin 解釋器
- Lens 解釋器
- Livy 解釋器
- Markdown 解釋器
- Pig 解釋器
- PostgreSQL, HAWQ 解釋器
- Python 2&3解釋器
- R 解釋器
- Scalding 解釋器
- Scio 解釋器
- Shell 解釋器
- Spark 解釋器
- 系統顯示
- 系統基本顯示
- 后端Angular API
- 前端Angular API
- 更多
- 筆記本存儲
- REST API
- 解釋器 API
- 筆記本 API
- 筆記本資源 API
- 配置 API
- 憑據 API
- Helium API
- Security ( 安全 )
- Shiro 授權
- 筆記本 授權
- 數據源 授權
- Helium 授權
- Advanced ( 高級 )
- Zeppelin on Vagrant VM ( Zeppelin 在 Vagrant 虛擬機上 )
- Zeppelin on Spark Cluster Mode( Spark 集群模式下的 Zeppelin )
- Zeppelin on CDH ( Zeppelin 在 CDH 上 )
- Contibute ( 貢獻 )
- Writing a New Interpreter ( 寫一個新的解釋器 )
- Writing a new Visualization (Experimental) ( 編寫新的可視化(實驗) )
- Writing a new Application (Experimental) ( 寫一個新的應用程序( 實驗 ) )
- Contributing to Apache Zeppelin ( Code ) ( 向 Apache Zeppelin 貢獻( 代碼 ) )
- Contributing to Apache Zeppelin ( Website ) ( 向 Apache Zeppelin 貢獻(website) )