-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/dbt-labs/new-python-wrench-…
- Loading branch information
Showing
8 changed files
with
124 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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,12 @@ | ||
WITH | ||
stg_input AS (SELECT * FROM {{ ref('stg_fruit_user_input') }}), | ||
|
||
stg_fact AS (SELECT * FROM {{ ref('stg_fruit_prices_fact') }}) | ||
|
||
SELECT | ||
stg_fact."fruit_name", | ||
stg_input."user_name", | ||
stg_input."quantity" * stg_fact."cost" AS "total" | ||
FROM | ||
stg_input LEFT JOIN stg_fact | ||
ON stg_input."fruit_name" = stg_fact."fruit_name" |
This file contains 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,13 @@ | ||
WITH | ||
fruit_join AS ( | ||
SELECT * FROM {{ ref('fruit_join') }} | ||
) | ||
|
||
SELECT | ||
"user_name", | ||
SUM("total") AS "total_final" | ||
|
||
FROM fruit_join | ||
WHERE "user_name" IS NOT NULL | ||
GROUP BY "user_name" | ||
ORDER BY SUM("total") DESC |
This file contains 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,43 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: stg_fruit_user_input | ||
description: prepare to fuzzymatch | ||
columns: | ||
- name: fruit_user_input | ||
quote: true | ||
description: what the user manually typed in the app | ||
tests: | ||
- not_null | ||
- name: quantity | ||
quote: true | ||
description: how many user wants to buy | ||
tests: | ||
- not_null | ||
- name: user_name | ||
quote: true | ||
description: the internal ID of the app user | ||
tests: | ||
- not_null | ||
- name: fruit_name | ||
quote: true | ||
description: best possible fuzzy match b/w user input and fact table | ||
tests: | ||
- not_null: | ||
config: | ||
severity: warn | ||
error_if: ">5" | ||
warn_if: ">2" | ||
- name: fruit_summary | ||
description: total each customer definitely owes minus mismatches | ||
columns: | ||
- name: user_name | ||
quote: true | ||
description: what the user manually typed in the app | ||
tests: | ||
- not_null | ||
- name: total_final | ||
quote: true | ||
description: total amount each user owes | ||
tests: | ||
- not_null |
This file contains 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,3 @@ | ||
SELECT | ||
* | ||
FROM {{ ref('fruit_prices_fact') }} |
This file contains 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,28 @@ | ||
from fuzzywuzzy import process | ||
|
||
|
||
def model(dbt, session): | ||
dbt.config( | ||
materialized="table", | ||
packages=["fuzzywuzzy"] | ||
) | ||
|
||
df_price = dbt.ref("stg_fruit_prices_fact").to_pandas() | ||
|
||
def custom_scorer(string): | ||
''' | ||
for a given string | ||
return the best match out of the `fruit_name` column in the df_to table | ||
''' | ||
|
||
x = process.extractOne(string, df_price["fruit_name"], score_cutoff=60) | ||
|
||
if x is not None: | ||
return x[0] | ||
else: | ||
return None | ||
|
||
return (dbt.ref("fruit_user_input").to_pandas() | ||
# make new col, `fruit_name`, with best match against actual table | ||
.assign(fruit_name=lambda df: df["fruit_user_input"].apply(custom_scorer)) | ||
) |
File renamed without changes.