Flink SQL Client讀取csv中的數據(轉載+總結)
根據官方文檔[2]
| Flink SQL啓動方式 | 啓動命令 |
| (1)starting an embedded standalone process ? | $FLINK_HOME/bin/sql-client.sh embedded |
| (2)connecting to a remote SQL Client Gateway | 官方暫時不支持 "At the moment only the?embedded?mode is supported" |
默認配置文件是:
$FLINK_HOME/conf/sql-client-defaults.yaml
[3]中提到了所謂的 "environment file"的概念其實就是yaml文件
--------------------------------------------------------------------下面是實驗----------------------------------------------------------------------------------------------------???????------------???????---------
準備工作:
①~/桌面/book-store.csv
②$FLINK_HOME/conf/book-store.yaml
文件每行解釋:
| book-store.yaml的每行 | 解釋 |
| tables.type | 等于source-table,表明這是數據源的配置信息 |
| tables.connector | 描述了詳細的數據源信息,path是book-store.csv文件的完整路徑 |
| tables.format | 描述了文件內容; |
| tables.schema | 描述了數據源表的表結構; |
| type | 為view表示MyBookView是個視圖(參考數據庫的視圖概念); |
啓動命令:
$FLINK_HOME/bin/sql-client.sh embedded -d $FLINK_HOME/conf/book-store.yaml
執行命令:
| 命令 | 功能 |
| SELECT * FROM BookStore; | 查詢全表 |
| SELECT BookCatalog, COUNT(*) AS BookCount FROM BookStore GROUP BY BookCatalog; | 按照BookCatalog分組統計記錄數 |
| select * from MyBookView; | select * from MyBookView |
https://github.com/ververica/flink-sql-gateway
運行結果示范:
----------------------------------------------------------------------------------------------------------------------------------------------------------------
CLI支持三種可視化查詢結果的模式[5],可在命令行中進行設置 ,三種模式的區別和使用參考官網
| 運行模式 | FLINK SQL設置命令 |
| table mode? | SET execution.result-mode=table; |
| changelog mode | SET execution.result-mode=changelog; |
| tableau mode | SET execution.result-mode=tableau; |
上述執行的select查詢結果,會緩存到java heap中。具體示範如下:
----------------------------------------------------------------------------------------------------------------------------------------------------------------
啓動時總是會出現的No session environment specified
咋回事呢?
根據我查詢了資料[4]
To configure the SQL Client for the session mode, you need to create an environment YAML file (sql-env.yaml), and add the following configuration:
configuration:execution.target: yarn-sessionThis overrides the Flink configuration of the execution target to?yarn-session?mode.
?
Reference:
[1]Flink SQL Client初探
[2]SQL Client
[3]https://github.com/ververica/flink-sql-gateway
[4]Configuring SQL Client for session mode
[5]Flink v1.11.1 官網Flink SQL Client 的使用
?
?
?
?
總結
以上是生活随笔為你收集整理的Flink SQL Client讀取csv中的數據(轉載+總結)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Schema initializatio
- 下一篇: linux cmake编译源码,linu