# Lens 解釋器
原文鏈接 : [http://zeppelin.apache.org/docs/0.7.2/interpreter/lens.html](http://zeppelin.apache.org/docs/0.7.2/interpreter/lens.html)
譯文鏈接 : [http://www.apache.wiki/pages/viewpage.action?pageId=10030852](http://www.apache.wiki/pages/viewpage.action?pageId=10030852)
貢獻者 : [片刻](/display/~jiangzhonglian) [ApacheCN](/display/~apachecn) [Apache中文網](/display/~apachechina)
## 概觀
[Apache Lens](https://lens.apache.org/)提供統一分析界面。Lens旨在通過跨多個分層數據存儲提供單一數據視圖并為分析查詢提供最佳執行環境,從而減少數據分析孤立。它將Hadoop與傳統的數據倉庫無縫集成在一起的工具之一。

## 安裝和運行Lens
為了使用Lens解釋器,您可以通過以下簡單的步驟安裝Apache Lens:
1. 從[ASF](http://www.apache.org/dyn/closer.lua/lens/2.3-beta)下載Lens的最新版本。或者舊版本可以[在檔案館](http://archive.apache.org/dist/lens/)找到。
2. 在運行鏡頭之前,您必須設置HIVE?_HOME和HADOOP_?HOME。如果你想獲得更多的信息,請參考[這里](http://lens.apache.org/lenshome/install-and-run.html#Installation)。鏡頭還提供偽分布模式。[Lens偽分布式設置](http://lens.apache.org/lenshome/pseudo-distributed-setup.html)是通過使用[docker](https://www.docker.com/)處理器完成的。Hive服務器和hadoop守護程序作為鏡頭偽分布式設置中的單獨進程運行。
3. 現在,您可以啟動鏡頭服務器(或停止)。
```
./bin/lens-ctl start (or stop)?
```
## 配置Lens解釋器
在“解釋器”菜單中,您可以編輯Lens解釋器或創建新的Lens解釋器。Zeppelin提供Lens的這些屬性。
| 物業名稱 | 值 | 描述 |
| --- | --- | --- |
| lens.client.dbname | default | 數據庫模式名稱 |
| lens.query.enable.persistent.resultset | false | 是否為查詢啟用持久性結果集。啟用后,服務器將從驅動程序中獲取結果,如果有的話將自定義格式,并存儲在配置的位置。查詢輸出的文件名是queryhandle-id,帶有已配置的擴展名 |
| lens.server.base.url | http://hostname:port/lensapi | Lens服務器的基本URL。你必須編輯你可能使用的“hostname”和“port”(例如: http://0.0.0.0:9999/lensapi) |
| lens.session.cluster.user | default | Hadoop集群用戶名 |
| zeppelin.lens.maxResult | 1000 | 要顯示的最大行數 |
| zeppelin.lens.maxThreads | 10 | 如果并發是真的,那么有多少個線程? |
| zeppelin.lens.run.concurrent | true | 同時執行Lens會話 |
| XXX | YYY | [配置Lens服務器]()中的其他任何內容 |

### 解釋器綁定為Zeppelin筆記本
配置Lens解釋器后,創建自己的筆記本,然后您可以綁定如下圖像的解釋器。

有關更多的解釋器綁定信息,請參閱[此處](http://zeppelin.apache.org/docs/manual/interpreters.html)。
### 如何使用
您可以使用[OLAP Cube?](http://lens.apache.org/user/olap-cube.html)[QL](http://lens.apache.org/user/cli.html)來分析數據,這是一種高級SQL類似語言來查詢和描述以數據立方體組織的數據集。您可能會遇到OLAP立方體像這個[視頻教程](https://cwiki.apache.org/confluence/display/LENS/2015/07/13/20+Minute+video+demo+of+Apache+Lens+through+examples)。您可以在此視頻中看到,它們使用的是鏡頭客戶機外殼(./ bin / lens-cli.sh)。所有這些功能也可以使用鏡頭解釋器在Zeppelin上使用。
* 創建和使用(切換)數據庫。
```
create database newDb
use newDb
```
* 創建存儲。
```
create storage your/path/to/lens/client/examples/resources/db-storage.xml?
```
* 創建尺寸,顯示它們的字段和連接鏈。
```
create dimension your/path/to/lens/client/examples/resources/customer.xml
dimension show fields customer
dimension show joinchains customer?
```
* 創建緩存,顯示它們的字段和連接鏈。
```
create cube your/path/to/lens/client/examples/resources/sales-cube.xml
cube show fields sales
cube show joinchains sales
```
* 創造Dimtables和事實。
```
create dimtable your/path/to/lens/client/examples/resources/customer_table.xml
create fact your/path/to/lens/client/examples/resources/sales-raw-fact.xml
```
* 添加分區到Dimtable和Fact。
```
dimtable add single-partition --dimtable_name customer_table --storage_name local --path your/path/to/lens/client/examples/resources/customer-local-part.xml
fact add partitions --fact_name sales_raw_fact --storage_name local --path your/path/to/lens/client/examples/resources/sales-raw-local-parts.xml
```
* 現在,您可以對多維數據集運行查詢。
```
query execute cube select customer_city_name, product_details.description, product_details.category, product_details.color, store_sales from sales where time_range_in(delivery_time, '2015-04-11-00', '2015-04-13-00')
```

這些只是Lens提前提供的例子。如果您想探索Lens的整個[教程](https://cwiki.apache.org/confluence/display/LENS/2015/07/13/20+Minute+video+demo+of+Apache+Lens+through+examples),請參閱[教程視頻](https://cwiki.apache.org/confluence/display/LENS/2015/07/13/20+Minute+video+demo+of+Apache+Lens+through+examples)。
## Lens UI服務
Lens還提供Web UI服務。一旦服務器啟動,您可以打開http://serverhost:19999/index.html上的服務并瀏覽。您也可以在這里檢查您所制作的結構并使用查詢。

- 快速入門
- 什么是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) )