Skip to main content
InterviewHubPRO
Section Overview
Q47

Question 47 of 50

Part 3: Enterprise Scale, Performance & CI/CD Pipelines (Senior / Staff)

94%
dbt Analytics Engineering (50 Qs)•Part 3: Enterprise Scale, Performance & CI/CD Pipelines (Senior / Staff)

Hooks in dbt: `on-run-start`, `on-run-end`, `pre-hook`, and `post-hook`.

senior LevelMost AskedCode ExampleHooksFormsPerformance

In Simple Words: Executing arbitrary SQL before and after model or run execution:

yaml
# dbt_project.yml
on-run-start:
  - "CREATE TABLE IF NOT EXISTS audit_log (event STRING, timestamp TIMESTAMP);"
on-run-end:
  - "INSERT INTO audit_log VALUES ('dbt_run_completed', CURRENT_TIMESTAMP());"

# In a specific model config:
{{ config(
    post_hook = [
      "GRANT SELECT ON {{ this }} TO ROLE bi_analyst;",
      "OPTIMIZE {{ this }} ZORDER BY (customer_id);"
    ]
) }}