Skip to content
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

blink_features.usage with ranks and partitioned #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 0 additions & 37 deletions definitions/output/blink_features/features.js

This file was deleted.

64 changes: 44 additions & 20 deletions definitions/output/blink_features/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,36 @@ publish('usage', {
schema: 'blink_features',
type: 'incremental',
protected: true,
bigquery: {
partitionBy: 'date',
clusterBy: ['client', 'rank', 'feature'],
requirePartitionFilter: true
},
tags: ['crawl_complete']
}).preOps(ctx => `
DELETE FROM ${ctx.self()}
WHERE yyyymmdd = REPLACE('${constants.currentMonth}', '-', '');
WHERE date = '${constants.currentMonth}';
`).query(ctx => `
WITH pages AS (
SELECT
REPLACE(CAST(date AS STRING), '-', '') AS yyyymmdd,
date,
client,
rank,
page,
features
FROM ${ctx.ref('crawl', 'pages')}
WHERE
date = '${constants.currentMonth}' AND
is_root_page = TRUE
${constants.devRankFilter}
), ranks AS (
SELECT DISTINCT rank FROM pages
)

SELECT
date,
client,
rank,
id,
feature,
type,
Expand All @@ -19,20 +41,22 @@ SELECT
sample_urls
FROM (
SELECT
yyyymmdd AS date,
date,
client,
id,
feature,
type,
COUNT(DISTINCT url) AS num_urls,
ARRAY_AGG(url ORDER BY rank, url LIMIT 100) AS sample_urls
FROM ${ctx.ref('blink_features', 'features')}
WHERE
yyyymmdd = '${constants.currentMonth}'
${constants.devRankFilter}
ranks.rank,
feature.id,
feature.feature,
feature.type,
COUNT(DISTINCT page) AS num_urls,
ARRAY_AGG(page ORDER BY pages.rank, page LIMIT 100) AS sample_urls
FROM pages
CROSS JOIN UNNEST(features) AS feature
FULL OUTER JOIN ranks
ON pages.rank <= ranks.rank
GROUP BY
yyyymmdd,
date,
client,
ranks.rank,
id,
feature,
type
Expand All @@ -41,15 +65,15 @@ JOIN (
SELECT
date,
client,
ranks.rank,
COUNT(DISTINCT page) AS total_urls
FROM ${ctx.ref('crawl', 'pages')}
WHERE
date = '${constants.currentMonth}' AND
is_root_page = TRUE
${constants.devRankFilter}
FROM pages
FULL OUTER JOIN ranks
ON pages.rank <= ranks.rank
GROUP BY
date,
client
client,
ranks.rank
)
USING (date, client)
USING (date, client, rank)
`)
Loading