跳到主要內容

[HowTo] 使用 Tableau Prep Builder 單機也能排程自動更新數據

如果已經有Tableau Dada Management Add-on,這篇文章就可以跳過了,因為Data Management Add-on內的Tableau Prep Conductor就是能夠讓 Prep Flow 可以在Tableau Server 排程的運行。

這篇要介紹的是,當沒有Prep Conductor的時候,要如何能自動化的執行Prep的工作流程來更新數據。

接下來進入主題,首先要能夠執行PrepFlow,這台主機上就需要有安裝 Tableau Prep Builder

 步驟1,儲存Work Flow(.tfl)檔案

 步驟2,建立Credentials .json 認證檔案

根據你的Work Flow當中使用到的數據來源(輸入)以及輸出時的位置(可能是發佈到Tableau Server或另外一個資料庫)來建立這個 json檔案

例如,我的數據來源是MSSQL,我的輸出要發佈到Tableau Server;所以我要準備一個 Json包含 SQL & Tableau Server的相關資訊

{
"tableauServerConnections":[
   {
    "serverUrl":"http://192.168.2.43",
    "contentUrl": "labs",
    "port":80,
    "username": "userabc",
    "password": "passw0rd"
   }
],
"databaseConnections":[
   {
    "hostname":"192.168.2.20",
    "username": "someone",
    "password": "Passw0rd"
   }
]
}      

 tableauServerConnections 段落是放Tableau Server的資訊

databaseConnections 段落是放數據來源(MSSQL)的資訊,如果是其他資料庫需要指令Port Number, 須加上"port": "3306",

 步驟3,於命令提示字元下單次執行流程以重新整理流程輸出

Tableau Prep Builder安裝的路徑下,會有一個Scripts (tableau-prep-cli)用來執行此作業

 For Windows

"\[Tableau Prep Builder install location]\Tableau Prep Builder <version>\scripts"\tableau-prep-cli.bat -c "path\to\[your credential file name].json" -t "path\to\[your flow file name].tfl"

 For Mac

/Applications/Tableau\ Prep\ Builder\ [Tableau Prep Builder version].app/Contents/scripts/./tableau-prep-cli -c path/to/[your credential file name].json -t path/to/[your flow file name].tfl

 舉例,我在Windows 底下執行時:

我的work Flow 檔案位置:C:\tmp\order-flow.tfl

我的Credentials .json 位置:C:\tmp\ mssql.json

C:\Users\Andy Lee>"C:\Program Files\Tableau\Tableau Prep Builder 2020.3\scripts"\tableau-prep-cli.bat -c C:\tmp\mssql.json -t C:\tmp\order-flow.tfl
JAVA_HOME is set to : C:\Program Files\Tableau\Tableau Prep Builder 2020.3\scripts\..\Plugins\jre temporarily
WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
The connection file is in V2 format.
Preparing to run the flow : C:\tmp\order-flow.tfl
Loading the flow.
Creating temp directory at C:\Users\ANDYLE~1\AppData\Local\Temp\prep-cli
18336170787255573862
Loaded the flow.
Updating credential for connection 192.168.2.20
Updated the connections with supplied credentials.
Established input connections to remote connection: 192.168.2.20
Established input connections with remote data sources.
No server connections detected in input connections.
Starting to establish a server connection for publishing extract.
Signed in successfully as userabc to site labs (labs)
Checking the flow document for errors.
Flow Document has no errors.
Preparing to execute the flow.
Flow Execution Status: Running
Flow Execution Status: Finished
Finished running the flow successfully.
C:\Users\Andy Lee>

 

步驟4,建立排程作業

Windows為例,Windows作業系統下的工作排程器可以建立指定時間自動執行特定工作。

開啟工作排程器後,右方窗框內選擇建立工作,就可以開啟編輯工作視窗

一般頁籤內要注意的是下方最好是設定無論使用者登入與否均執行,避免使用者登出或電腦鎖定時無法繼續執行作業

在觸發程序頁籤,定義工作排程的時間。

以下圖為例,定義的是每周一~週五;每天上午8:00開始,每隔30分鐘執行一次;持續9小時至下午5點。

在動作頁籤內,輸入Script檔案位置,並將參數部分填寫再新增引數位置即可。

 

完成以上配置就算完成整個自動化的作業了。你可以在工作排程器上看到此工作的運行狀態;也可以在Tableau Server上檢視數據源的修訂歷史紀錄來確認是否有正常的刷新數據。

留言

  1. 1.請問contenturl 是要根據tableau server的什麼資訊填入?
    2.如果需要Flow需要連接多個database又需要怎麼在jason檔案填寫呢?

    謝謝

    回覆刪除
    回覆
    1. contentUrl(網站 ID。針對 Tableau Server 或 Tableau Online,此資訊會出現在 URL 中的 /site/ 之後。例如,「https://my.server/#/site/mysite」請設定 "contentUrl": "mysite"))。

      刪除
  2. 多的database連線時, 接著往下寫就好
    https://help.tableau.com/current/prep/zh-tw/prep_run_commandline.htm

    如下範例:
    {
    "databaseConnections":[
    {
    "hostname":"example123.redshift.amazonaws.com",
    "port": "5439",
    "username": "jsmith",
    "password": "p@s$w0rd!"
    },
    {
    "hostname":"mysql.mydb.tsi.lan",
    "port": "3306",
    "username": "jsmith",
    "password": "mspa$$w0rd"
    }
    ]
    }

    回覆刪除
  3. hello 有興趣一起寫prep extend 的 python library嗎? 還可以增加一些功能例如save log or 給一堆tfls 然後自動依照相依性排列執行順序 等等...我這邊已經有一些雛形,如果有興趣我們可以多聊聊

    回覆刪除
    回覆
    1. Hi weihao,
      好像有點意思, 但你沒留下聯絡方式@@
      方便的話, 發個信給我吧~
      Andy.Lee@vizdata.tw

      刪除
    2. 有阿~ 我們後來有聯繫阿 XD

      刪除
    3. XDD 忘記忘記 拍謝拍謝 怕我那時候後來放鳥
      新年快樂! 祝你工作持續順利!

      刪除
  4. 您好,想請問如果沒有用Server,是發佈到Tableau Cloud上的話,要怎麼做呢?謝謝您。

    回覆刪除
    回覆
    1. 我有陣子沒碰這段了,雖然應該可以參考這篇文章的第一則問題(HORSE2021年1月15日)我的答覆來試試看

      刪除

張貼留言

歡迎留言討論指教~~