Homework 14 — Cost & Governance
Lesson 14 · Data Engineering with Python · 3 exercises
All three tasks build on the governance/ tree added in Lesson 14. Task 1 is a
SQL cost-reporting exercise. Task 2 involves extending grants.yml with a new
role. Task 3 is a GDPR audit-log exercise for a declined (not approved) erasure request.
Task 1 — Detect the most expensive team last week
Write a single query that returns the one team with the highest cost in
the last 7 days. Use the DuckDB _query_costs table (local) or
SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY (Snowflake, optional).
The result must be a single row with at least two columns: team and a cost column.
Self-check:
- The query returns exactly 1 row.
- The
teamcolumn contains a value extracted from the tag (not the raw tag string). - The cost column is a numeric aggregate (
SUM, not a raw row value).
Task 2 — Add a new role to grants.yml
Define a data_scientist role in governance/grants.yml with
read-only (SELECT) access to fact_events AND read-only access
to a hypothetical feature_store table. Reuse the existing YAML structure
exactly — same indentation, same key names, same list syntax.
Self-check:
-
python -c "import yaml; yaml.safe_load(open('governance/grants.yml'))"runs without error. -
The new role appears under the
roles:key (not at the top level, and not undermasking_policies:). - Both grants specify only
[SELECT]— not[SELECT, INSERT].
Task 3 — Audit-log a declined deletion request
Write a .jsonl entry for a GDPR erasure request that you decline.
Invent a fictional public-figure account whose data falls under a journalistic exemption
(GDPR Article 85). The entry must include these fields:
ts, action: "gdpr_decline", subject,
reason, legal_basis.
Append the entry to governance/gdpr/deletion_log.jsonl (do not replace the
file; use open(..., 'a')).
Self-check:
- The entry parses cleanly:
json.loads(line)returns a dict with all 5 required fields. - The file has at least two lines (the lab-step-7 entry from the lab + your new entry).
- The
actionvalue is exactly"gdpr_decline"(not"gdpr_delete").