Skip to content

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
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Apr 29, 2025
2de77bb
Remove superfluous newlines
chelseatroy Apr 29, 2025
74522d0
Add TODO for confirming partition field
chelseatroy Apr 29, 2025
1f55a21
Add clustering fields:
chelseatroy Apr 30, 2025
6e0c816
ran ./bqetl format sql
chelseatroy May 1, 2025
9fdb6ea
Ran sql
chelseatroy May 1, 2025
bb75cba
Merge branch 'main' into snowfake-migration-stg-prospects
chelseatroy May 1, 2025
a0cc45b
Add dataset_base_acl key to dataset_metadata
chelseatroy May 1, 2025
3b34a95
Merge branch 'main' into snowfake-migration-stg-prospects
chelseatroy May 2, 2025
3141658
Fix yaml formatting
chelseatroy May 2, 2025
c693706
Matt Cooper's handle has his middle initial in it unfortunately
chelseatroy May 2, 2025
77325de
rename prospects table to adhere to naming conventions of bigquery
chelseatroy May 2, 2025
afddcf8
Merge branch 'main' into snowfake-migration-stg-prospects
jpetto May 5, 2025
b205eaf
Change array columns to strings
chelseatroy May 5, 2025
b598372
Change record columns to strings also
chelseatroy May 5, 2025
010f9a6
Partition by a field in the table
chelseatroy May 5, 2025
3b4f373
Try changing the stringified timestamps to standard timestamps
chelseatroy May 6, 2025
d92312c
Remove superfluous created_at
chelseatroy May 6, 2025
f363b67
Remove incompatible default value for status_reasons
chelseatroy May 6, 2025
35a9e47
Convert arrays from source table to string
chelseatroy May 6, 2025
daf16e5
Convert arrays from source table to string
chelseatroy May 6, 2025
e4816e3
Change partition to match SQL
chelseatroy May 8, 2025
aa85a2e
See if we can set the type of an object coming from snowflake to json…
chelseatroy May 8, 2025
30d22f0
stringify struct fields to be parsed by ML
chelseatroy May 8, 2025
b904fee
Remove unnecessary fields and update schema to match query output
chelseatroy May 8, 2025
a8cfd69
./bqetl format path_to_sql
chelseatroy May 8, 2025
f7c9ef4
Maybe changing this from string to JSON will fix the schema issue?
chelseatroy May 12, 2025
3195139
use TO_BASE64 to convert bytes object, which is used as a key, to a s…
chelseatroy May 13, 2025
a7678f1
sql format
chelseatroy May 13, 2025
71bb76a
Merge branch 'main' into snowfake-migration-stg-prospects
chelseatroy May 15, 2025
2987031
Merge branch 'main' into snowfake-migration-stg-prospects
chelseatroy May 16, 2025
d59c0ed
Merge branch 'main' into snowfake-migration-stg-prospects
chelseatroy May 16, 2025
1238a4a
Merge branch 'main' into snowfake-migration-stg-prospects
chelseatroy May 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions dags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
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
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
contexts_com_pocket_prospect_1[0].language AS LANGUAGE,
contexts_com_pocket_prospect_1[0].language AS language,

just for consistency

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;
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

Copy link
Collaborator

Choose a reason for hiding this comment

The 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