## Debugging လမ်းညွှန်
- အခြား Program တွေ ရေးတဲ့အခါ ကြုံသလိုပဲ dbt project တွေမှာ Error တွေ အမြဲတစေ ကြုံနိုင်ပါတယ်။ အဲဒီအတွက် dbt က ထုတ်ပေးထားတဲ့ လမ်းညွှန် [Guide](https://docs.getdbt.com/guides/debug-errors) ကို အကျဥ်းခြုံးပြီး ပြန်မျှဝေချင်ပါတယ်။
1. Error Message ကို သေသေချာချာ ဖတ်ပါ။
2. Error ဖြစ်စေတဲ့ File ကို ရှာဖွေပြီး စစ်ဆေးပါ။ အလွယ်တကူ ပြင်လို့ ရနိုင်တာမျိုးလဲ တွေ့ကောင်းတွေ့နိုင်ပါတယ်။
3. အဲဒီမှာ ရှာမတွေ့သေးဘူးဆိုရင် ပြဿနာ Error ကို ခွဲခြားကြည့်ပါ။ (ဥပမာ - တစ်ကြိမ် ကို model တစ်ခုချင်းဆီ run ကြည့်တာမျိုး ၊ ပြဿနာဖြစ်စေတဲ့ Code အစိတ်အပိုင်းကို ခန ဖယ်ရှားထားပြီး စစ်ကြည့်တာမျိုး)
4. dbt ကနေ ထုတ်ပေးလိုက်တဲ့ Compiled files တွေနဲ့ Logs တွေကို ဖတ်ကျင့်ရှိအောင် လေ့ကျင့်ပါ။
- `target/compiled` folder အောက်မှာဆိုရင် `SELECT` statement နဲ့ SQL file တွေရှိပါတယ်။ အဲဒီ file တွေထဲက code ကို ကူးယူပြီး Query Editor မှာ သွား run ကြည့်လို့ ရပါတယ်။
- `target/run` folder ထဲမှာကျ dbt က နောက်ဆုံး last invocation မှာ အမှန်တကယ် execute ပြုလုပ်လိုက်တဲ့ final SQL statements တွေ ၊ files တွေ ပါဝင်ပါတယ်။
- `logs/dbt.log` folder ထဲမှာတော့ dbt run တာနဲ့ ပတ်သတ်သမျှ queries တွေ ၊ information တွေ အကုန် ပါဝင်ပါတယ်။ နောက်ဆုံး ဖြစ်ပွားသွားတဲ့ Error တွေက File ရဲ့ အောက်ဆုံးနားမှာ ရှိပါလိမ့်မယ်။
## Error အမျိုးအစားများ
- dbt မှာ ဖြစ်တဲ့ Error တွေကို အုပ်စုခွဲကြည့်တဲ့အခါမှာ dbt အနေနဲ့ နောက်ကွယ်မှာ ဘယ်လို ပြုလုပ်သွားသလဲ ဆိုတာကို နားလည်ရင် ပိုအဆင်ပြေပါလိမ့်မယ်။
#### dbt run - Error Table
- ဥပမာ - `dbt run` command ကို execute လုပ်ရင်း ဖြစ်လေ့ရှိနိုင်တဲ့ error တွေကို အောက်ပါ table အတိုင်း ခွဲခြား ကြည့်လို့ ရပါတယ်။
| Step | Description | Error type |
| ---------------- | --------------------------------------------------------------------------------- | ------------------- |
| Initialize | Check that this a dbt project, and that dbt can connect to the warehouse | `Runtime Error` |
| Parsing | Check that the Jinja snippets in `.sql` files valid, and that `.yml` files valid. | `Compilation Error` |
| Graph validation | Compile the dependencies into a graph. Check that it's acyclic. | `Dependency Error` |
| SQL execution | Run the models | `Database Error` |
#### dbt build - Error Table
- `dbt build` command ကို execute လုပ်ရင်း ဖြစ်နိုင်တဲ့ error တွေက အောက်ပါ table အတိုင်း ဖြစ်ပါတယ်။
| Step | Description | Error Type | Notes / common causes |
| ---------------------------------------- | -------------------------------------------------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Initialize | Load the project, profiles, connections | Runtime Error | Same as before: missing config, wrong dir, profile problems |
| Parsing | Parse models, macros, Jinja, YAML, config | Compilation Error | Invalid Jinja, invalid YAML, unsupported keys |
| Graph validation / dependency resolution | Build the DAG of models, tests, snapshots | Dependency Error | Cycles, unresolved ref() or source() references |
| SQL compile / generation | Produce compiled SQL for models, snapshots, seeds, tests | Compilation Error | Macro errors, SQL fragments malformed, incorrect use of config, etc. |
| SQL execution (models/snapshots/seeds) | Execute compiled SQL against the warehouse | Database Error | - **Models**: CREATE/REPLACE TABLE/VIEW errors (permissions, schema mismatch) <br>- **Seeds**: CSV load failures (bad formatting, missing file) <br>- **Snapshots**: SCD logic errors (bad unique key, merge/update/delete issues, missing permissions) |
| Test execution | Run tests against built models | Database Error | Test failures, constraint violations, SQL errors in test logic |
#### dbt test - Error Table
- `dbt test` command ကို execute လုပ်ရင်း ဖြစ်နိုင်တဲ့ error table ဖြစ်ပါတယ်။
| Step | Description | Error Type | Notes / common causes |
| ---------------------------------------- | ------------------------------------------------- | ----------------- | -------------------------------------------------------------------------------------------------------- |
| Initialize | Setup project and profile context | Runtime Error | Missing project file, wrong working dir, missing profile |
| Parsing | Parse test files, macros, Jinja, YAML test config | Compilation Error | Invalid YAML in .yml test configs, invalid Jinja in test SQL or macros |
| Graph validation / dependency resolution | Ensure tests map to existing models or sources | Dependency Error | A test refers to a model or source that doesn’t exist or is excluded |
| SQL compile / generation | Compile the test SQL statements to run | Compilation Error | Errors during macro expansion, or invalid SQL bocks inside test definitions |
| SQL execution | Actually run the tests against the database | Database Error | Failures such as constraint violations, query syntax errors, missing relations/tables, permission issues |
#### dbt compile - Error Table
- `dbt compile` command ကို execute လုပ်ရင်း ဖြစ်နိုင်တဲ့ error table ဖြစ်ပါတယ်။
| Step | Description | Error Type | Notes / common causes |
| ---------------------------------------- | ---------------------------------------------------------------------------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------- |
| Initialize | Confirm project context, profiles, connection setup (though compile won’t run SQL) | Runtime Error | Missing dbt_project.yml, missing or bad profile, unable to locate project directory |
| Parsing / Jinja parsing / YAML reading | Parse .sql files, Jinja expressions, YAML config files, macros | Compilation Error | Invalid Jinja syntax (unclosed tags, mismatched blocks), invalid YAML, incorrect config keys |
| Graph validation / Dependency resolution | Resolve DAG / references between nodes | Dependency Error | Cyclic ref() graph, ref() pointing to nodes that don’t exist |
| Compilation / SQL generation | Generate compiled SQL (without executing) | Compilation Error / Macro error | Errors in macro expansion, invalid use of functions, badly formed SQL fragments (though not executed) |
| | | | |