0
0
dbtdata~20 mins

Model contracts and access controls in dbt - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Model Contracts and Access Controls Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Model Contracts in dbt

What is the primary purpose of a model contract in dbt?

ATo schedule dbt runs based on time intervals.
BTo control user access permissions to the dbt project files.
CTo automate the deployment of dbt models to production environments.
DTo define a fixed schema that a model must adhere to, ensuring consistent data structure.
Attempts:
2 left
💡 Hint

Think about how contracts help maintain data quality and structure.

Predict Output
intermediate
2:00remaining
Output of a dbt model contract test

Given a dbt model with a contract specifying columns id INT and name STRING, what will be the result if the model returns an extra column age INT?

dbt
version: 2
models:
  - name: customers
    columns:
      - name: id
        tests:
          - not_null
      - name: name
        tests:
          - not_null
    contract: true
AThe dbt run will fail due to schema mismatch because of the extra 'age' column.
BThe dbt run will succeed and ignore the extra 'age' column.
CThe dbt run will fail because 'name' column is missing.
DThe dbt run will succeed but the contract test will warn about missing columns.
Attempts:
2 left
💡 Hint

Contracts enforce exact schema matching, including no extra columns.

data_output
advanced
1:30remaining
Result of access control configuration in dbt

Consider a dbt project where access controls restrict the finance schema to only the finance_team role. If a user without this role runs a model targeting the finance schema, what will be the outcome?

AThe model run will be queued until the user gains access.
BThe model run will fail with a permission denied error.
CThe model run will succeed and write data to the <code>finance</code> schema.
DThe model run will succeed but the data will be masked.
Attempts:
2 left
💡 Hint

Think about how database permissions affect write operations.

🔧 Debug
advanced
2:00remaining
Identify the cause of contract test failure

A dbt model contract test fails with the error: Column 'id' missing in model output. The model SQL is:

select id as customer_id, name from customers

Why does the contract test fail?

AThe model output includes 'customer_id' but the contract expects 'customer_id' with different data type.
BThe model output is missing the 'name' column required by the contract.
CThe model renames 'id' to 'customer_id' but the contract expects 'id'.
DThe model SQL has a syntax error causing incomplete output.
Attempts:
2 left
💡 Hint

Check if the contract column names match the model output exactly.

🚀 Application
expert
3:00remaining
Designing access controls for multi-team dbt project

You manage a dbt project with multiple teams: sales, marketing, and finance. Each team should only access their own schema data. How should you configure model contracts and access controls to enforce this?

ADefine model contracts per schema and assign database roles with write/read permissions only to their respective schemas.
BUse a single model contract for all schemas and grant all teams full access to all schemas.
CGrant all teams access to a shared schema and filter data by team in SQL.
DDisable model contracts and rely on dbt run schedules to separate team data.
Attempts:
2 left
💡 Hint

Think about combining schema-level permissions with contracts for data integrity.