-
Notifications
You must be signed in to change notification settings - Fork 113
Add SQL, schema, metadata, and DAG for modeling prospects table from … #7368
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
chelseatroy
wants to merge
33
commits into
main
Choose a base branch
from
snowfake-migration-stg-prospects
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.
+250
−0
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e068213
Add SQL, schema, metadata, and DAG for modeling prospects table from …
chelseatroy 2de77bb
Remove superfluous newlines
chelseatroy 74522d0
Add TODO for confirming partition field
chelseatroy 1f55a21
Add clustering fields:
chelseatroy 6e0c816
ran ./bqetl format sql
chelseatroy 9fdb6ea
Ran sql
chelseatroy bb75cba
Merge branch 'main' into snowfake-migration-stg-prospects
chelseatroy a0cc45b
Add dataset_base_acl key to dataset_metadata
chelseatroy 3b34a95
Merge branch 'main' into snowfake-migration-stg-prospects
chelseatroy 3141658
Fix yaml formatting
chelseatroy c693706
Matt Cooper's handle has his middle initial in it unfortunately
chelseatroy 77325de
rename prospects table to adhere to naming conventions of bigquery
chelseatroy afddcf8
Merge branch 'main' into snowfake-migration-stg-prospects
jpetto b205eaf
Change array columns to strings
chelseatroy b598372
Change record columns to strings also
chelseatroy 010f9a6
Partition by a field in the table
chelseatroy 3b4f373
Try changing the stringified timestamps to standard timestamps
chelseatroy d92312c
Remove superfluous created_at
chelseatroy f363b67
Remove incompatible default value for status_reasons
chelseatroy 35a9e47
Convert arrays from source table to string
chelseatroy daf16e5
Convert arrays from source table to string
chelseatroy e4816e3
Change partition to match SQL
chelseatroy aa85a2e
See if we can set the type of an object coming from snowflake to json…
chelseatroy 30d22f0
stringify struct fields to be parsed by ML
chelseatroy b904fee
Remove unnecessary fields and update schema to match query output
chelseatroy a8cfd69
./bqetl format path_to_sql
chelseatroy f7c9ef4
Maybe changing this from string to JSON will fix the schema issue?
chelseatroy 3195139
use TO_BASE64 to convert bytes object, which is used as a key, to a s…
chelseatroy a7678f1
sql format
chelseatroy 71bb76a
Merge branch 'main' into snowfake-migration-stg-prospects
chelseatroy 2987031
Merge branch 'main' into snowfake-migration-stg-prospects
chelseatroy d59c0ed
Merge branch 'main' into snowfake-migration-stg-prospects
chelseatroy 1238a4a
Merge branch 'main' into snowfake-migration-stg-prospects
chelseatroy 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 |
---|---|---|
|
@@ -2323,6 +2323,19 @@ bqetl_monitoring_hourly: | |
- impact/tier_1 | ||
- repo/bigquery-etl | ||
|
||
bqetl_content_ml_daily: | ||
schedule_interval: 0 4 * * * | ||
description: | | ||
Daily extracts for corpus item data to be evaluated for new tab presentation. | ||
default_args: | ||
owner: [email protected] | ||
start_date: "2025-05-05" #TODO: Change to merge date | ||
email: ["[email protected]", "[email protected]"] | ||
retries: 2 | ||
retry_delay: 30m | ||
tags: | ||
- impact/tier_2 | ||
|
||
bqetl_ech_adoption_rate: | ||
default_args: | ||
depends_on_past: false | ||
|
12 changes: 12 additions & 0 deletions
12
sql/moz-fx-data-shared-prod/snowflake_migration/dataset_metadata.yaml
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,12 @@ | ||
friendly_name: Snowflake Migration | ||
description: |- | ||
Queries for modeling raw snowplow data about prospects | ||
(candidate links to be curated by ML models and the editorial team for New Tab). | ||
|
||
user_facing: false | ||
dataset_base_acl: derived | ||
labels: {} | ||
workgroup_access: | ||
- role: roles/bigquery.dataViewer | ||
members: | ||
- workgroup:mozilla-confidential |
28 changes: 28 additions & 0 deletions
28
sql/moz-fx-data-shared-prod/snowflake_migration/prospects_v1/metadata.yaml
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,28 @@ | ||
friendly_name: Prospects v1 | ||
description: Model prospective article options for the Fx New Tab from raw Snowplow data | ||
owners: | ||
- [email protected] | ||
- [email protected] | ||
labels: | ||
schedule: daily | ||
incremental: true | ||
owner1: skamath | ||
owner2: mlcooper | ||
scheduling: | ||
dag_name: bqetl_content_ml_daily | ||
# destination is the whole table, not a single partition, | ||
# so don't use date_partition_parameter | ||
date_partition_parameter: null | ||
bigquery: | ||
time_partitioning: | ||
type: day | ||
# TODO: confirm | ||
field: happened_at | ||
require_partition_filter: true | ||
expiration_days: 775 | ||
clustering: | ||
fields: | ||
- prospect_source | ||
- language | ||
- topic | ||
- publisher |
81 changes: 81 additions & 0 deletions
81
sql/moz-fx-data-shared-prod/snowflake_migration/prospects_v1/query.sql
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,81 @@ | ||
WITH stg_prospects AS ( | ||
SELECT | ||
event_id, | ||
unstruct_event_com_pocket_object_update_1.trigger AS object_update_trigger, | ||
-- prospect info | ||
contexts_com_pocket_prospect_1[0].prospect_id AS prospect_id, | ||
contexts_com_pocket_prospect_1[0].url AS url, | ||
contexts_com_pocket_prospect_1[0].scheduled_surface_id AS scheduled_surface_id, | ||
contexts_com_pocket_prospect_1[0].prospect_source AS prospect_source, | ||
TIMESTAMP_SECONDS(contexts_com_pocket_prospect_1[0].created_at) AS created_at, | ||
TIMESTAMP_SECONDS(DIV(contexts_com_pocket_prospect_1[0].reviewed_at, 1000)) AS reviewed_at, | ||
contexts_com_pocket_prospect_1[0].prospect_review_status AS prospect_review_status, | ||
ARRAY_TO_STRING(contexts_com_pocket_prospect_1[0].status_reasons, ",") AS status_reasons, | ||
contexts_com_pocket_prospect_1[0].status_reason_comment AS status_reason_comment, | ||
contexts_com_pocket_prospect_1[0].reviewed_by AS reviewed_by, | ||
contexts_com_pocket_prospect_1[0].title AS title, | ||
contexts_com_pocket_prospect_1[0].excerpt AS excerpt, | ||
contexts_com_pocket_prospect_1[0].image_url AS image_url, | ||
contexts_com_pocket_prospect_1[0].language AS LANGUAGE, | ||
contexts_com_pocket_prospect_1[0].topic AS topic, | ||
contexts_com_pocket_prospect_1[0].is_collection AS is_collection, | ||
contexts_com_pocket_prospect_1[0].is_syndicated AS is_syndicated, | ||
ARRAY_TO_STRING(contexts_com_pocket_prospect_1[0].authors, ",") AS authors, | ||
contexts_com_pocket_prospect_1[0].publisher AS publisher, | ||
contexts_com_pocket_prospect_1[0].domain AS domain, | ||
TO_JSON(contexts_com_pocket_prospect_1[0].features) AS features, | ||
TO_JSON(contexts_com_pocket_prospect_1[0].run_details) AS run_details, | ||
contexts_com_pocket_prospect_1[0]._schema_version AS schema_version, | ||
-- event info | ||
derived_tstamp AS happened_at, | ||
FROM | ||
`moz-fx-data-shared-prod.snowplow_external.events` | ||
WHERE | ||
event_name = 'object_update' | ||
AND unstruct_event_com_pocket_object_update_1.object = 'prospect' | ||
AND SAFE_CAST(contexts_com_pocket_prospect_1[0].created_at AS INT64) IS NOT NULL | ||
AND SAFE_CAST(contexts_com_pocket_prospect_1[0].created_at AS INT64) | ||
BETWEEN 946684800 | ||
AND UNIX_MILLIS(CURRENT_TIMESTAMP()) | ||
AND SAFE_CAST(contexts_com_pocket_prospect_1[0].reviewed_at AS INT64) IS NOT NULL | ||
-- reviewed_at is in miliseconds (for some reason), so we need to divide | ||
AND SAFE_CAST(DIV(contexts_com_pocket_prospect_1[0].reviewed_at, 1000) AS INT64) | ||
BETWEEN 946684800 | ||
AND UNIX_MILLIS(CURRENT_TIMESTAMP()) | ||
-- This ensures recommended_at is between Jan 1, 2000, and the current time to remain within BQ limits for dates | ||
QUALIFY | ||
ROW_NUMBER() OVER (PARTITION BY happened_at ORDER BY happened_at) = 1 | ||
) | ||
SELECT | ||
p.prospect_id, | ||
p.object_update_trigger, | ||
p.url, | ||
p.scheduled_surface_id, | ||
p.prospect_source, | ||
p.created_at, | ||
p.reviewed_at, | ||
p.prospect_review_status, | ||
p.status_reasons, | ||
p.status_reason_comment, | ||
p.reviewed_by, | ||
p.title, | ||
p.excerpt, | ||
p.image_url, | ||
p.language, | ||
p.topic, | ||
p.authors, | ||
p.publisher, | ||
p.domain, | ||
p.is_collection, | ||
p.is_syndicated, | ||
p.happened_at, | ||
p.features, | ||
p.run_details, | ||
p.schema_version, | ||
TO_BASE64( | ||
SHA256(CONCAT(p.prospect_id, p.object_update_trigger)) | ||
) AS prospect_id_object_update_trigger_key | ||
FROM | ||
stg_prospects p | ||
QUALIFY | ||
ROW_NUMBER() OVER (PARTITION BY prospect_id, object_update_trigger ORDER BY happened_at DESC) = 1; |
116 changes: 116 additions & 0 deletions
116
sql/moz-fx-data-shared-prod/snowflake_migration/prospects_v1/schema.yaml
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,116 @@ | ||
fields: | ||
- mode: NULLABLE | ||
type: STRING | ||
name: prospect_id | ||
description: Unique identifier for prospects | ||
- mode: NULLABLE | ||
type: STRING | ||
name: url | ||
description: The url of the prospects item | ||
- mode: NULLABLE | ||
type: STRING | ||
name: scheduled_surface_id | ||
description: Recommended destination where the prospect item is expected to appear | ||
(NEW_TAB_EN_INTL, NEW_TAB_EN_US, NEW_TAB_DE_DE, NEW_TAB_EN_GB). | ||
- mode: NULLABLE | ||
type: STRING | ||
name: prospect_source | ||
description: Source identified by the ML process for the prospect (SYNDICATED, ORGANIC_TIMESPENT, | ||
GLOBAL). | ||
- mode: NULLABLE | ||
type: TIMESTAMP | ||
name: created_at | ||
description: timestamp when the prospect was first created | ||
- mode: NULLABLE | ||
type: TIMESTAMP | ||
name: reviewed_at | ||
description: timestamp when the prospect was reviewed by the curator. It is also | ||
the timestamp that caused this event action | ||
- mode: NULLABLE | ||
type: STRING | ||
name: prospect_review_status | ||
description: The curator's review status for the prospect | ||
- mode: NULLABLE | ||
type: STRING | ||
name: status_reasons | ||
description: The list of curator review status reasons | ||
- mode: NULLABLE | ||
type: STRING | ||
name: status_reason_comment | ||
description: Curator review status reason comment | ||
- mode: NULLABLE | ||
type: STRING | ||
name: reviewed_by | ||
description: The curator who reviewed the prospect | ||
- mode: NULLABLE | ||
type: STRING | ||
name: title | ||
description: The title of the reviewed corpus item | ||
- mode: NULLABLE | ||
type: STRING | ||
name: excerpt | ||
description: The excerpt for the reviewed corpus item | ||
- mode: NULLABLE | ||
type: STRING | ||
name: image_url | ||
description: The url of the main image of the reviewed corpus item | ||
- mode: NULLABLE | ||
type: STRING | ||
name: language | ||
description: The language of the reviewed_corpus_item | ||
- mode: NULLABLE | ||
type: STRING | ||
name: topic | ||
description: The topic of the reviewed_corpus_item | ||
- mode: NULLABLE | ||
type: STRING | ||
name: authors | ||
description: The list of authors of the reviewed_corpus_item | ||
- mode: NULLABLE | ||
type: STRING | ||
name: publisher | ||
description: The name of the online publication that published this story. | ||
- mode: NULLABLE | ||
type: BOOLEAN | ||
name: is_collection | ||
description: Indicates whether the reviewed_corpus_item is a collection | ||
- mode: NULLABLE | ||
type: BOOLEAN | ||
name: is_syndicated | ||
description: Indicates whether the reviewed_corpus_item is a syndicated article | ||
- mode: NULLABLE | ||
type: JSON | ||
name: features | ||
description: 'ML features for the prospect item. Note: These features are being | ||
passed through for ML use and will not be engineered in the warehouse | ||
|
||
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. These new lines look slightly odd. They should be safe to delete? |
||
' | ||
- mode: NULLABLE | ||
type: JSON | ||
name: run_details | ||
description: 'Details about the run, including the flow name and run ID. Note: The | ||
ML team could include additional debug properties about the run, but these properties | ||
will not be engineered in the warehouse | ||
|
||
' | ||
- mode: NULLABLE | ||
type: STRING | ||
name: schema_version | ||
description: Snowplow version identifier. | ||
- mode: NULLABLE | ||
type: TIMESTAMP | ||
name: happened_at | ||
description: Event creation timestamp | ||
- mode: NULLABLE | ||
type: STRING | ||
name: prospect_id_object_update_trigger_key | ||
description: 'A combination of the prospect_id and object_update_trigger columns | ||
to create a unique event identifier | ||
|
||
' | ||
- mode: NULLABLE | ||
type: STRING | ||
name: object_update_trigger | ||
- mode: NULLABLE | ||
type: STRING | ||
name: domain |
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.
just for consistency