-
Notifications
You must be signed in to change notification settings - Fork 7
Mohamad Bader AA #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
noneeeed
wants to merge
1
commit into
HackYourAssignment:main
Choose a base branch
from
noneeeed:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mohamad Bader AA #12
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ target/ | |
| dbt_packages/ | ||
| logs/ | ||
| profiles.yml | ||
| .user.yml | ||
|
|
||
| # System files | ||
| .DS_Store | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,6 @@ | ||
| -- safe_divide(numerator, denominator) | ||
| -- Returns numerator / denominator, or NULL when denominator is 0 or NULL. | ||
| -- Use for tip_pct = tip_amount / fare_amount and similar ratio columns. | ||
|
|
||
| {% macro safe_divide(numerator, denominator) %} | ||
| -- TODO: implement the macro body. | ||
| -- Use NULLIF(denominator, 0) to avoid division-by-zero errors. | ||
| -- Return only the SQL expression (no SELECT, no semicolon). | ||
| NULL | ||
| {% endmacro %} | ||
| case | ||
| when {{ denominator }} > 0 then round(({{ numerator }} / {{ denominator }})::numeric, 4) | ||
| else null | ||
| end | ||
| {% endmacro %} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,23 +2,35 @@ version: 2 | |
|
|
||
| models: | ||
| - name: fct_daily_borough_stats | ||
| description: > | ||
| TODO: state the grain (one row per ___), the source lineage | ||
| (built from ___ and ___), and at least one known caveat | ||
| (e.g. rows dropped in staging, any WARN-severity tests). | ||
| description: "One row per completed NYC green taxi trip in January 2024, with | ||
| pickup/dropoff zone attributes folded in (OBT-style mart). Queried | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does 'OBT-style mart' mean? |
||
| directly by dashboards and ad-hoc analysis. | ||
|
|
||
| **Grain:** one row per trip. | ||
| **Source:** `public.raw_trips` joined to `public.raw_zones` on | ||
| `pickup_location_id` and `dropoff_location_id`. | ||
| **Not included:** trips where `pickup_location_id` is NULL (dropped | ||
| in `stg_trips`); duplicate rows from the TLC source are kept as-is | ||
| and surfaced by `dbt_utils.unique_combination_of_columns`." | ||
| # TODO: Task 5 -- add the compound uniqueness test on the mart's primary | ||
| # key (pickup_borough, pickup_date). You need the dbt_utils package for | ||
| # this: declare it in packages.yml and run `dbt deps` first. | ||
| tests: | ||
| - dbt_utils.unique_combination_of_columns: | ||
| combination_of_columns: | ||
| - pickup_borough | ||
| - pickup_date | ||
| severity: warn | ||
| columns: | ||
| - name: pickup_borough | ||
| description: "TODO: explain what this column contains and where it comes from" | ||
| description: "TLC borough where the trip started" | ||
| - name: pickup_date | ||
| description: "TODO: explain units and how it is derived" | ||
| description: "the day the trip started (date only, no time)" | ||
| - name: trip_count | ||
| description: "TODO: explain what is counted (unit: number of trips)" | ||
| description: "total trips that started in this borough on this day" | ||
| - name: total_fare | ||
| description: "TODO: explain units (USD) and what fare_amount represents" | ||
| description: "total revenue from trips that started in this borough on this day in USD" | ||
| - name: avg_tip_pct | ||
| description: "TODO: explain the ratio (tip_amount / fare_amount)" | ||
| description: "average tip percentage for trips that started in this borough on this day, expressed as a decimal (e.g. 0.15 = 15%)" | ||
| - name: avg_trip_distance | ||
| description: "TODO: explain units (miles, from TLC source data)" | ||
| description: "average distance of trips that started in this borough on this day, in miles" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,25 +14,15 @@ zones AS ( | |
| ) | ||
|
|
||
| SELECT | ||
| -- TODO: join trips to zones on pickup_location_id = location_id. | ||
| -- Use an INNER JOIN: a few trips have a pickup_location_id with no matching | ||
| -- zone (e.g. 999). INNER JOIN drops those so pickup_borough is never NULL and | ||
| -- can serve as part of the mart's primary key (your not_null test needs this). | ||
| -- TODO: aggregate to grain (pickup_borough, pickup_date) | ||
| -- Required output columns: | ||
| -- pickup_borough TEXT - z.borough | ||
| -- pickup_date DATE - pickup_datetime::date | ||
| -- trip_count BIGINT - count(*) | ||
| -- total_fare NUMERIC - sum(fare_amount) | ||
| -- avg_tip_pct NUMERIC - avg(tip_pct) | ||
| -- avg_trip_distance NUMERIC - avg(trip_distance) | ||
| NULL AS pickup_borough, | ||
| NULL AS pickup_date, | ||
| NULL AS trip_count, | ||
| NULL AS total_fare, | ||
| NULL AS avg_tip_pct, | ||
| NULL AS avg_trip_distance | ||
|
|
||
| z.borough::text AS pickup_borough, | ||
| t.pickup_datetime::date AS pickup_date, | ||
| COUNT(*) AS trip_count, | ||
| SUM(t.fare_amount)::numeric(10,2) AS total_fare, | ||
| AVG(t.tip_pct)::numeric(10,2) AS avg_tip_pct, | ||
| AVG(t.trip_distance)::numeric(10,2) AS avg_trip_distance | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't necessarily need to add typecasting to each row (it's not wrong, but likely unnecessary) |
||
|
|
||
| FROM trips t | ||
| -- TODO: add JOIN to zones here | ||
| -- TODO: add GROUP BY here | ||
| INNER JOIN zones z | ||
| ON t.pickup_location_id = z.location_id | ||
| GROUP BY pickup_borough, pickup_date | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| packages: | ||
| - name: dbt_utils | ||
| package: dbt-labs/dbt_utils | ||
| version: 1.4.1 | ||
| sha1_hash: e6424ba9e5a22487e47f023803aa4f0411946808 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| # TODO: Task 5 -- declare the dbt-labs/dbt_utils package here, then run | ||
| # `dbt deps` to install it. You need it for the compound uniqueness test | ||
| # on the mart. See https://hub.getdbt.com/dbt-labs/dbt_utils/latest/ | ||
| # for the package block syntax. | ||
| packages: [] | ||
| packages: | ||
| - package: dbt-labs/dbt_utils | ||
| version: [">=1.1.0", "<2.0.0"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not wrong but you can also use NULLIF as per instruction for a cleaner expression