iT邦幫忙

2023 iThome 鐵人賽

DAY 25
0

昨天聊了 dbt Core 在本機開發的基本操作,但和 dbt Cloud 相比起來,還是麻煩很多。

今天要來介紹一個常用的 VS Code extension: dbt Power User,能讓開發體驗更加順暢。


安裝 extension

由 Extensions 搜尋 dbt Power User 就可以安裝
https://ithelp.ithome.com.tw/upload/images/20230910/20159575XjvkTOmjVN.png

設定專案 Interpreter

先讓 interpreter 顯示在下方狀態列,方便使用。

File -> Preferences -> Settings -> 搜尋 python interpreter
Python > Interpreter: Info Visibility 選 Always
https://ithelp.ithome.com.tw/upload/images/20231008/20159575xoJdHtxA4g.png

此時回到主畫面,在右下角的 interpreter 路徑,選擇我們 DAY 23 所安裝的 venv
https://ithelp.ithome.com.tw/upload/images/20231008/20159575uvsYBJjlqu.png

files association

File -> Preferences -> Settings
搜尋 association,在 files: association 點選 Add Item,輸入

  • Item: *.sql
  • Value: Jinja-sql
    https://ithelp.ithome.com.tw/upload/images/20230910/201595753O6BNW2hf2.png

完成安裝後,就能開始使用 dbt Power User 的各項功能。


generate model

在 source yaml 可以選擇 generate model,依據 table schema 自動產生 model。
https://ithelp.ithome.com.tw/upload/images/20230910/20159575oKwdaS9sGL.png

自動產生的 model:
https://ithelp.ithome.com.tw/upload/images/20230910/20159575K3wHGlM4i3.png

side bar & model 右鍵選單

安裝完成後,請先開啟任一 dbt model 的檔案,例如 customers.sql。

左邊有 dbt Power User 的 side bar 可以點選。
可以檢視 model tests, parent models, children models, 以及 documentation。

再來,按右鍵也可以發現多了一些 dbt 的選項。
https://ithelp.ithome.com.tw/upload/images/20230910/20159575EbMLfC7Eri.png

可以按 Go to definition 切換到上游 model。
https://ithelp.ithome.com.tw/upload/images/20230910/20159575QdvFfJnhdx.png

昨天提到的:執行 dbt 指令、查看 target/compiled 及 target/run,都可以從右鍵選單點選。
target/compiled 及 target/run 的檔案,會以分割視窗開在右邊。
https://ithelp.ithome.com.tw/upload/images/20230910/20159575HdvlANmMvu.png

Query Results 頁籤

在 model 按 ctrl + enter 可以預覽 500 筆資料,與 dbt Cloud 相同。
https://ithelp.ithome.com.tw/upload/images/20230910/20159575XnrUUYXjiL.png

點 Dispatched SQL 可以查看 compiled SQL 語法。
https://ithelp.ithome.com.tw/upload/images/20230910/20159575ktjAeQJxq0.png

Lineage View 頁籤

Lineage View 和 dbt Cloud 有點不一樣。
一樣可以點選上下游 model 切換檔案,但除了 models 之外,這裡還多列了 tests。
https://ithelp.ithome.com.tw/upload/images/20230910/20159575ip4VfugN7e.png

Document Editor 頁籤

最後,Document Editor 也是 dbt Cloud 沒有的功能。
https://ithelp.ithome.com.tw/upload/images/20230910/20159575KEXvCTWqhB.png


今日小結&明日預告

明天的主題:用 GitHub Actions 建立排程

參考資料


歡迎加入 dbt community
對 dbt 或 data 有興趣 👋?歡迎加入 dbt community 到 #local-taipei 找我們,也有實體 Meetup 請到 dbt Taipei Meetup 報名參加


上一篇
DAY 24 - dbt Core 入門 (2) - 在本機開發的基本操作
下一篇
DAY 26 - dbt Core 入門 (4) - 用 GitHub Actions 建立排程
系列文
dbt: 告別過時的SQL開發流程30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
justinhsu
iT邦新手 5 級 ‧ 2024-02-07 11:25:20

我在dbt run 那些都沒有問題
但是在vscode dbt power user中的query result 會出現這個問題
ORA-00933: SQL command not properly ended
請問該怎麼解決呢 謝謝

看更多先前的回應...收起先前的回應...
Stacy Lo iT邦新手 4 級 ‧ 2024-02-07 12:44:16 檢舉

你的SQL最後有分號 ';' 嗎?

justinhsu iT邦新手 5 級 ‧ 2024-02-07 15:21:09 檢舉

沒有ㄟ

justinhsu iT邦新手 5 級 ‧ 2024-02-07 15:23:09 檢舉

加上;會出現這個錯誤
ORA-00907: missing right parenthesis

Stacy Lo iT邦新手 4 級 ‧ 2024-02-07 20:58:11 檢舉

原本猜說可能多了分號
如果不是的話我就沒頭緒了

如果 dbt run 沒錯誤
Compile出來的SQL也都可以跑查詢
那比較有可能是dbt power user加了筆數的限制之後才壞掉的
你可以找看看筆數限制能不能拿掉(我不確定)

再來就是我最近懷疑
修改完的語法第一次按preview不會生效
按第二次好像才正確😂

研究不出來的話看要開issue給dbt power user
或是到Slack發問
可以去dbt power user的頻道發問
也可以到 #local-taipei 請大家一起幫忙看

我要留言

立即登入留言