@ken-e/dataform-youtube 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/includes/column_descriptions.js +137 -95
- package/includes/definitions/sources/stg_ytc_annotation.js +16 -31
- package/includes/definitions/sources/stg_ytc_basic.js +15 -31
- package/includes/definitions/sources/stg_ytc_cards.js +16 -31
- package/includes/definitions/sources/stg_ytc_combined.js +15 -31
- package/includes/definitions/sources/stg_ytc_demographics.js +16 -31
- package/includes/definitions/sources/stg_ytc_device_os.js +16 -31
- package/includes/definitions/sources/stg_ytc_end_screens.js +14 -29
- package/includes/definitions/sources/stg_ytc_list_basic.js +15 -31
- package/includes/definitions/sources/stg_ytc_list_combined.js +16 -30
- package/includes/definitions/sources/stg_ytc_list_device_os.js +16 -30
- package/includes/definitions/sources/stg_ytc_list_playback.js +16 -30
- package/includes/definitions/sources/stg_ytc_list_province.js +15 -31
- package/includes/definitions/sources/stg_ytc_list_traffic_source.js +16 -30
- package/includes/definitions/sources/stg_ytc_lu_operating_systems.js +1 -1
- package/includes/definitions/sources/stg_ytc_playback.js +16 -31
- package/includes/definitions/sources/stg_ytc_province.js +15 -31
- package/includes/definitions/sources/stg_ytc_share_platform.js +16 -31
- package/includes/definitions/sources/stg_ytc_subtitles.js +15 -30
- package/includes/definitions/sources/stg_ytc_traffic_source.js +16 -49
- package/includes/definitions/ytc_annotation.js +14 -29
- package/includes/definitions/ytc_basic.js +14 -30
- package/includes/definitions/ytc_cards.js +14 -29
- package/includes/definitions/ytc_combined.js +14 -31
- package/includes/definitions/ytc_demographics.js +14 -28
- package/includes/definitions/ytc_demographics_views.js +15 -29
- package/includes/definitions/ytc_device_os.js +14 -28
- package/includes/definitions/ytc_end_screens.js +14 -28
- package/includes/definitions/ytc_list_basic.js +14 -28
- package/includes/definitions/ytc_list_combined.js +14 -27
- package/includes/definitions/ytc_list_device_os.js +14 -27
- package/includes/definitions/ytc_list_playback.js +14 -27
- package/includes/definitions/ytc_list_province.js +14 -28
- package/includes/definitions/ytc_list_traffic_source.js +14 -27
- package/includes/definitions/ytc_playback.js +14 -28
- package/includes/definitions/ytc_province.js +14 -28
- package/includes/definitions/ytc_share_platform.js +14 -28
- package/includes/definitions/ytc_subtitles.js +14 -27
- package/includes/definitions/ytc_traffic_source.js +14 -28
- package/includes/helpers.js +12 -0
- package/index.js +12 -2
- package/package.json +3 -3
|
@@ -3,45 +3,25 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const column_descriptions = require("../column_descriptions");
|
|
6
|
+
const helpers = require("../helpers");
|
|
6
7
|
|
|
7
8
|
module.exports = (config) => {
|
|
8
9
|
// eslint-disable-next-line no-undef
|
|
9
10
|
return publish("ytc_annotation", {
|
|
10
11
|
type: "incremental",
|
|
11
|
-
schema: config.
|
|
12
|
+
schema: config.target.outputSchema,
|
|
12
13
|
tags: ["youtube", "output", "daily"],
|
|
13
14
|
bigquery: {
|
|
14
|
-
partitionBy: "
|
|
15
|
+
partitionBy: "data_date",
|
|
15
16
|
clusterBy: ["video_id", "annotation_type"],
|
|
16
17
|
},
|
|
17
18
|
columns: column_descriptions.column_descriptions,
|
|
18
19
|
description: "YT Channel Annotation Report Table - Intermediate",
|
|
19
20
|
})
|
|
20
|
-
.preOps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
--Set the incremental update checkpoint based on current max partition value minus lookback.
|
|
27
|
-
set interaction_date_checkpoint = (
|
|
28
|
-
${ctx.when(
|
|
29
|
-
ctx.incremental(),
|
|
30
|
-
`select
|
|
31
|
-
least(
|
|
32
|
-
(select date_sub(current_date(), interval ${config.daysBack} day)),
|
|
33
|
-
(select date_sub(max(interaction_date), interval ${config.daysBack} day) from ${ctx.self()})
|
|
34
|
-
)`,
|
|
35
|
-
`select date("${config.startDate}")`,
|
|
36
|
-
)}
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
${ctx.when(
|
|
40
|
-
ctx.incremental(),
|
|
41
|
-
`delete ${ctx.self()} where interaction_date > interaction_date_checkpoint`,
|
|
42
|
-
)}
|
|
43
|
-
`,
|
|
44
|
-
)
|
|
21
|
+
.preOps((ctx) => {
|
|
22
|
+
// Get pre_operations to find updated output partitions
|
|
23
|
+
return `${helpers.output_preops(ctx, config, ctx.ref("stg_ytc_annotation"))}`;
|
|
24
|
+
})
|
|
45
25
|
.query(
|
|
46
26
|
(ctx) => `
|
|
47
27
|
|
|
@@ -58,8 +38,13 @@ left join ${ctx.ref(
|
|
|
58
38
|
config.titlesTable,
|
|
59
39
|
)} as titles
|
|
60
40
|
using (video_id)
|
|
61
|
-
|
|
62
|
-
|
|
41
|
+
${ctx.when(
|
|
42
|
+
ctx.incremental(),
|
|
43
|
+
`where
|
|
44
|
+
data_date in unnest(partitions_to_update)`,
|
|
45
|
+
`where
|
|
46
|
+
data_date > date '${config.startDate}'`,
|
|
47
|
+
)}
|
|
63
48
|
`,
|
|
64
49
|
);
|
|
65
50
|
};
|
|
@@ -3,47 +3,25 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const column_descriptions = require("../column_descriptions");
|
|
6
|
+
const helpers = require("../helpers");
|
|
6
7
|
|
|
7
8
|
module.exports = (config) => {
|
|
8
9
|
// eslint-disable-next-line no-undef
|
|
9
10
|
return publish("ytc_basic", {
|
|
10
11
|
type: "incremental",
|
|
11
|
-
schema: config.
|
|
12
|
+
schema: config.target.outputSchema,
|
|
12
13
|
tags: ["youtube", "output", "daily"],
|
|
13
14
|
bigquery: {
|
|
14
|
-
partitionBy: "
|
|
15
|
+
partitionBy: "data_date",
|
|
15
16
|
clusterBy: ["video_id"],
|
|
16
17
|
},
|
|
17
18
|
columns: column_descriptions.column_descriptions,
|
|
18
19
|
description: "YT Channel Basic Report Table - Intermediate",
|
|
19
20
|
})
|
|
20
|
-
.preOps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
declare interaction_date_checkpoint default (
|
|
25
|
-
select date("${config.startDate}")
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
--Set the incremental update checkpoint based on current max partition value minus lookback.
|
|
29
|
-
set interaction_date_checkpoint = (
|
|
30
|
-
${ctx.when(
|
|
31
|
-
ctx.incremental(),
|
|
32
|
-
`select
|
|
33
|
-
least(
|
|
34
|
-
(select date_sub(current_date(), interval ${config.daysBack} day)),
|
|
35
|
-
(select date_sub(max(interaction_date), interval ${config.daysBack} day) from ${ctx.self()})
|
|
36
|
-
)`,
|
|
37
|
-
`select date("${config.startDate}")`,
|
|
38
|
-
)}
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
${ctx.when(
|
|
42
|
-
ctx.incremental(),
|
|
43
|
-
`delete ${ctx.self()} where interaction_date > interaction_date_checkpoint`,
|
|
44
|
-
)}
|
|
45
|
-
`,
|
|
46
|
-
)
|
|
21
|
+
.preOps((ctx) => {
|
|
22
|
+
// Get pre_operations to find updated output partitions
|
|
23
|
+
return `${helpers.output_preops(ctx, config, ctx.ref("stg_ytc_basic"))}`;
|
|
24
|
+
})
|
|
47
25
|
.query(
|
|
48
26
|
(ctx) => `
|
|
49
27
|
|
|
@@ -54,7 +32,13 @@ with int_ex_titles as (
|
|
|
54
32
|
views * safe_divide(average_view_duration_seconds, average_view_duration_percentage) as row_max_duration_seconds,
|
|
55
33
|
subscribers_gained - subscribers_lost as subscribers_net,
|
|
56
34
|
from ${ctx.ref("stg_ytc_basic")}
|
|
57
|
-
|
|
35
|
+
${ctx.when(
|
|
36
|
+
ctx.incremental(),
|
|
37
|
+
`where
|
|
38
|
+
data_date in unnest(partitions_to_update)`,
|
|
39
|
+
`where
|
|
40
|
+
data_date > date '${config.startDate}'`,
|
|
41
|
+
)}
|
|
58
42
|
)
|
|
59
43
|
|
|
60
44
|
select
|
|
@@ -3,45 +3,25 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const column_descriptions = require("../column_descriptions");
|
|
6
|
+
const helpers = require("../helpers");
|
|
6
7
|
|
|
7
8
|
module.exports = (config) => {
|
|
8
9
|
// eslint-disable-next-line no-undef
|
|
9
10
|
return publish("ytc_cards", {
|
|
10
11
|
type: "incremental",
|
|
11
|
-
schema: config.
|
|
12
|
+
schema: config.target.outputSchema,
|
|
12
13
|
tags: ["youtube", "output", "daily"],
|
|
13
14
|
bigquery: {
|
|
14
|
-
partitionBy: "
|
|
15
|
+
partitionBy: "data_date",
|
|
15
16
|
clusterBy: ["video_id", "card_type"],
|
|
16
17
|
},
|
|
17
18
|
columns: column_descriptions.column_descriptions,
|
|
18
19
|
description: "YT Channel Cards Report Table - Intermediate",
|
|
19
20
|
})
|
|
20
|
-
.preOps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
--Set the incremental update checkpoint based on current max partition value minus lookback.
|
|
27
|
-
set interaction_date_checkpoint = (
|
|
28
|
-
${ctx.when(
|
|
29
|
-
ctx.incremental(),
|
|
30
|
-
`select
|
|
31
|
-
least(
|
|
32
|
-
(select date_sub(current_date(), interval ${config.daysBack} day)),
|
|
33
|
-
(select date_sub(max(interaction_date), interval ${config.daysBack} day) from ${ctx.self()})
|
|
34
|
-
)`,
|
|
35
|
-
`select date("${config.startDate}")`,
|
|
36
|
-
)}
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
${ctx.when(
|
|
40
|
-
ctx.incremental(),
|
|
41
|
-
`delete ${ctx.self()} where interaction_date > interaction_date_checkpoint`,
|
|
42
|
-
)}
|
|
43
|
-
`,
|
|
44
|
-
)
|
|
21
|
+
.preOps((ctx) => {
|
|
22
|
+
// Get pre_operations to find updated output partitions
|
|
23
|
+
return `${helpers.output_preops(ctx, config, ctx.ref("stg_ytc_cards"))}`;
|
|
24
|
+
})
|
|
45
25
|
.query(
|
|
46
26
|
(ctx) => `
|
|
47
27
|
|
|
@@ -58,8 +38,13 @@ left join ${ctx.ref(
|
|
|
58
38
|
config.titlesTable,
|
|
59
39
|
)} as titles
|
|
60
40
|
using (video_id)
|
|
61
|
-
|
|
62
|
-
|
|
41
|
+
${ctx.when(
|
|
42
|
+
ctx.incremental(),
|
|
43
|
+
`where
|
|
44
|
+
data_date in unnest(partitions_to_update)`,
|
|
45
|
+
`where
|
|
46
|
+
data_date > date '${config.startDate}'`,
|
|
47
|
+
)}
|
|
63
48
|
|
|
64
49
|
`,
|
|
65
50
|
);
|
|
@@ -3,48 +3,25 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const column_descriptions = require("../column_descriptions");
|
|
6
|
+
const helpers = require("../helpers");
|
|
6
7
|
|
|
7
8
|
module.exports = (config) => {
|
|
8
9
|
// eslint-disable-next-line no-undef
|
|
9
10
|
return publish("ytc_combined", {
|
|
10
11
|
type: "incremental",
|
|
11
|
-
schema: config.
|
|
12
|
+
schema: config.target.outputSchema,
|
|
12
13
|
tags: ["youtube", "output", "daily"],
|
|
13
14
|
bigquery: {
|
|
14
|
-
partitionBy: "
|
|
15
|
+
partitionBy: "data_date",
|
|
15
16
|
clusterBy: ["video_id"],
|
|
16
17
|
},
|
|
17
18
|
columns: column_descriptions.column_descriptions,
|
|
18
19
|
description: "YT Channel Combined Report Table - Intermediate",
|
|
19
20
|
})
|
|
20
|
-
.preOps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
declare interaction_date_checkpoint default (
|
|
26
|
-
select date("${config.startDate}")
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
--Set the incremental update checkpoint based on current max partition value minus lookback.
|
|
30
|
-
set interaction_date_checkpoint = (
|
|
31
|
-
${ctx.when(
|
|
32
|
-
ctx.incremental(),
|
|
33
|
-
`select
|
|
34
|
-
least(
|
|
35
|
-
(select date_sub(current_date(), interval ${config.daysBack} day)),
|
|
36
|
-
(select date_sub(max(interaction_date), interval ${config.daysBack} day) from ${ctx.self()})
|
|
37
|
-
)`,
|
|
38
|
-
`select date("${config.startDate}")`,
|
|
39
|
-
)}
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
${ctx.when(
|
|
43
|
-
ctx.incremental(),
|
|
44
|
-
`delete ${ctx.self()} where interaction_date > interaction_date_checkpoint`,
|
|
45
|
-
)}
|
|
46
|
-
`,
|
|
47
|
-
)
|
|
21
|
+
.preOps((ctx) => {
|
|
22
|
+
// Get pre_operations to find updated output partitions
|
|
23
|
+
return `${helpers.output_preops(ctx, config, ctx.ref("stg_ytc_combined"))}`;
|
|
24
|
+
})
|
|
48
25
|
.query(
|
|
49
26
|
(ctx) => `
|
|
50
27
|
|
|
@@ -53,7 +30,13 @@ with int_ex_titles as (
|
|
|
53
30
|
* except (source_partition_date),
|
|
54
31
|
views * safe_divide(average_view_duration_seconds, average_view_duration_percentage) as row_max_duration_seconds,
|
|
55
32
|
from ${ctx.ref("stg_ytc_combined")}
|
|
56
|
-
|
|
33
|
+
${ctx.when(
|
|
34
|
+
ctx.incremental(),
|
|
35
|
+
`where
|
|
36
|
+
data_date in unnest(partitions_to_update)`,
|
|
37
|
+
`where
|
|
38
|
+
data_date > date '${config.startDate}'`,
|
|
39
|
+
)}
|
|
57
40
|
),
|
|
58
41
|
|
|
59
42
|
int_with_titles as (
|
|
@@ -3,45 +3,25 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const column_descriptions = require("../column_descriptions");
|
|
6
|
+
const helpers = require("../helpers");
|
|
6
7
|
|
|
7
8
|
module.exports = (config) => {
|
|
8
9
|
// eslint-disable-next-line no-undef
|
|
9
10
|
return publish("ytc_demographics", {
|
|
10
11
|
type: "incremental",
|
|
11
|
-
schema: config.
|
|
12
|
+
schema: config.target.outputSchema,
|
|
12
13
|
tags: ["youtube", "output", "daily"],
|
|
13
14
|
bigquery: {
|
|
14
|
-
partitionBy: "
|
|
15
|
+
partitionBy: "data_date",
|
|
15
16
|
clusterBy: ["video_id", "age_group", "gender"],
|
|
16
17
|
},
|
|
17
18
|
columns: column_descriptions.column_descriptions,
|
|
18
19
|
description: "YT Channel Demographics Report Table - Intermediate",
|
|
19
20
|
})
|
|
20
|
-
.preOps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
--Set the incremental update checkpoint based on current max partition value minus lookback.
|
|
27
|
-
set interaction_date_checkpoint = (
|
|
28
|
-
${ctx.when(
|
|
29
|
-
ctx.incremental(),
|
|
30
|
-
`select
|
|
31
|
-
least(
|
|
32
|
-
(select date_sub(current_date(), interval ${config.daysBack} day)),
|
|
33
|
-
(select date_sub(max(interaction_date), interval ${config.daysBack} day) from ${ctx.self()})
|
|
34
|
-
)`,
|
|
35
|
-
`select date("${config.startDate}")`,
|
|
36
|
-
)}
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
${ctx.when(
|
|
40
|
-
ctx.incremental(),
|
|
41
|
-
`delete ${ctx.self()} where interaction_date > interaction_date_checkpoint`,
|
|
42
|
-
)}
|
|
43
|
-
`,
|
|
44
|
-
)
|
|
21
|
+
.preOps((ctx) => {
|
|
22
|
+
// Get pre_operations to find updated output partitions
|
|
23
|
+
return `${helpers.output_preops(ctx, config, ctx.ref("stg_ytc_demographics"))}`;
|
|
24
|
+
})
|
|
45
25
|
.query(
|
|
46
26
|
(ctx) => `
|
|
47
27
|
|
|
@@ -50,7 +30,13 @@ with int_ex_titles as (
|
|
|
50
30
|
select
|
|
51
31
|
* except (source_partition_date)
|
|
52
32
|
from ${ctx.ref("stg_ytc_demographics")}
|
|
53
|
-
|
|
33
|
+
${ctx.when(
|
|
34
|
+
ctx.incremental(),
|
|
35
|
+
`where
|
|
36
|
+
data_date in unnest(partitions_to_update)`,
|
|
37
|
+
`where
|
|
38
|
+
data_date > date '${config.startDate}'`,
|
|
39
|
+
)}
|
|
54
40
|
)
|
|
55
41
|
|
|
56
42
|
select
|
|
@@ -3,45 +3,25 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const column_descriptions = require("../column_descriptions");
|
|
6
|
+
const helpers = require("../helpers");
|
|
6
7
|
|
|
7
8
|
module.exports = (config) => {
|
|
8
9
|
// eslint-disable-next-line no-undef
|
|
9
10
|
return publish("ytc_demographics_views", {
|
|
10
11
|
type: "incremental",
|
|
11
|
-
schema: config.
|
|
12
|
+
schema: config.target.outputSchema,
|
|
12
13
|
tags: ["youtube", "output", "daily"],
|
|
13
14
|
bigquery: {
|
|
14
|
-
partitionBy: "
|
|
15
|
+
partitionBy: "data_date",
|
|
15
16
|
clusterBy: ["video_id", "age_group", "gender"],
|
|
16
17
|
},
|
|
17
18
|
columns: column_descriptions.column_descriptions,
|
|
18
19
|
description: "YT Channel Demographics Report Table - Intermediate",
|
|
19
20
|
})
|
|
20
|
-
.preOps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
--Set the incremental update checkpoint based on current max partition value minus lookback.
|
|
27
|
-
set interaction_date_checkpoint = (
|
|
28
|
-
${ctx.when(
|
|
29
|
-
ctx.incremental(),
|
|
30
|
-
`select
|
|
31
|
-
least(
|
|
32
|
-
(select date_sub(current_date(), interval ${config.daysBack} day)),
|
|
33
|
-
(select date_sub(max(interaction_date), interval ${config.daysBack} day) from ${ctx.self()})
|
|
34
|
-
)`,
|
|
35
|
-
`select date("${config.startDate}")`,
|
|
36
|
-
)}
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
${ctx.when(
|
|
40
|
-
ctx.incremental(),
|
|
41
|
-
`delete ${ctx.self()} where interaction_date > interaction_date_checkpoint`,
|
|
42
|
-
)}
|
|
43
|
-
`,
|
|
44
|
-
)
|
|
21
|
+
.preOps((ctx) => {
|
|
22
|
+
// Get pre_operations to find updated output partitions
|
|
23
|
+
return `${helpers.output_preops(ctx, config, ctx.ref("stg_ytc_demographics"))}`;
|
|
24
|
+
})
|
|
45
25
|
.query(
|
|
46
26
|
(ctx) => `
|
|
47
27
|
|
|
@@ -54,14 +34,20 @@ with int_ex_titles as (
|
|
|
54
34
|
from ${ctx.ref("stg_ytc_demographics")} as stg
|
|
55
35
|
left join ${ctx.ref("ytc_basic")} as ytc_basic
|
|
56
36
|
using (
|
|
57
|
-
|
|
37
|
+
data_date,
|
|
58
38
|
channel_id,
|
|
59
39
|
video_id,
|
|
60
40
|
live_or_on_demand,
|
|
61
41
|
subscribed_status,
|
|
62
42
|
country_code
|
|
63
43
|
)
|
|
64
|
-
|
|
44
|
+
${ctx.when(
|
|
45
|
+
ctx.incremental(),
|
|
46
|
+
`where
|
|
47
|
+
data_date in unnest(partitions_to_update)`,
|
|
48
|
+
`where
|
|
49
|
+
data_date > date '${config.startDate}'`,
|
|
50
|
+
)}
|
|
65
51
|
)
|
|
66
52
|
|
|
67
53
|
select
|
|
@@ -7,45 +7,25 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
const column_descriptions = require("../column_descriptions");
|
|
10
|
+
const helpers = require("../helpers");
|
|
10
11
|
|
|
11
12
|
module.exports = (config) => {
|
|
12
13
|
// eslint-disable-next-line no-undef
|
|
13
14
|
return publish("ytc_device_os", {
|
|
14
15
|
type: "incremental",
|
|
15
|
-
schema: config.
|
|
16
|
+
schema: config.target.outputSchema,
|
|
16
17
|
tags: ["youtube", "output", "daily"],
|
|
17
18
|
bigquery: {
|
|
18
|
-
partitionBy: "
|
|
19
|
+
partitionBy: "data_date",
|
|
19
20
|
clusterBy: ["video_id", "device_type", "operating_system"],
|
|
20
21
|
},
|
|
21
22
|
columns: column_descriptions.column_descriptions,
|
|
22
23
|
description: "YT Channel Device and OS Report Table - Intermediate",
|
|
23
24
|
})
|
|
24
|
-
.preOps(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
--Set the incremental update checkpoint based on current max partition value minus lookback.
|
|
31
|
-
set interaction_date_checkpoint = (
|
|
32
|
-
${ctx.when(
|
|
33
|
-
ctx.incremental(),
|
|
34
|
-
`select
|
|
35
|
-
least(
|
|
36
|
-
(select date_sub(current_date(), interval ${config.daysBack} day)),
|
|
37
|
-
(select date_sub(max(interaction_date), interval ${config.daysBack} day) from ${ctx.self()})
|
|
38
|
-
)`,
|
|
39
|
-
`select date("${config.startDate}")`,
|
|
40
|
-
)}
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
${ctx.when(
|
|
44
|
-
ctx.incremental(),
|
|
45
|
-
`delete ${ctx.self()} where interaction_date > interaction_date_checkpoint`,
|
|
46
|
-
)}
|
|
47
|
-
`,
|
|
48
|
-
)
|
|
25
|
+
.preOps((ctx) => {
|
|
26
|
+
// Get pre_operations to find updated output partitions
|
|
27
|
+
return `${helpers.output_preops(ctx, config, ctx.ref("stg_ytc_device_os"))}`;
|
|
28
|
+
})
|
|
49
29
|
.query(
|
|
50
30
|
(ctx) => `
|
|
51
31
|
|
|
@@ -55,7 +35,13 @@ with int_ex_titles as (
|
|
|
55
35
|
* except (source_partition_date),
|
|
56
36
|
views * safe_divide(average_view_duration_seconds, average_view_duration_percentage) as row_max_duration_seconds
|
|
57
37
|
from ${ctx.ref("stg_ytc_device_os")}
|
|
58
|
-
|
|
38
|
+
${ctx.when(
|
|
39
|
+
ctx.incremental(),
|
|
40
|
+
`where
|
|
41
|
+
data_date in unnest(partitions_to_update)`,
|
|
42
|
+
`where
|
|
43
|
+
data_date > date '${config.startDate}'`,
|
|
44
|
+
)}
|
|
59
45
|
)
|
|
60
46
|
|
|
61
47
|
select
|
|
@@ -3,45 +3,25 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const column_descriptions = require("../column_descriptions");
|
|
6
|
+
const helpers = require("../helpers");
|
|
6
7
|
|
|
7
8
|
module.exports = (config) => {
|
|
8
9
|
// eslint-disable-next-line no-undef
|
|
9
10
|
return publish("ytc_end_screens", {
|
|
10
11
|
type: "incremental",
|
|
11
|
-
schema: config.
|
|
12
|
+
schema: config.target.outputSchema,
|
|
12
13
|
tags: ["youtube", "output", "daily"],
|
|
13
14
|
bigquery: {
|
|
14
|
-
partitionBy: "
|
|
15
|
+
partitionBy: "data_date",
|
|
15
16
|
clusterBy: ["video_id", "end_screen_element_type"],
|
|
16
17
|
},
|
|
17
18
|
columns: column_descriptions.column_descriptions,
|
|
18
19
|
description: "YT Channel End Screen Report Table - Intermediate",
|
|
19
20
|
})
|
|
20
|
-
.preOps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
--Set the incremental update checkpoint based on current max partition value minus lookback.
|
|
27
|
-
set interaction_date_checkpoint = (
|
|
28
|
-
${ctx.when(
|
|
29
|
-
ctx.incremental(),
|
|
30
|
-
`select
|
|
31
|
-
least(
|
|
32
|
-
(select date_sub(current_date(), interval ${config.daysBack} day)),
|
|
33
|
-
(select date_sub(max(interaction_date), interval ${config.daysBack} day) from ${ctx.self()})
|
|
34
|
-
)`,
|
|
35
|
-
`select date("${config.startDate}")`,
|
|
36
|
-
)}
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
${ctx.when(
|
|
40
|
-
ctx.incremental(),
|
|
41
|
-
`delete ${ctx.self()} where interaction_date > interaction_date_checkpoint`,
|
|
42
|
-
)}
|
|
43
|
-
`,
|
|
44
|
-
)
|
|
21
|
+
.preOps((ctx) => {
|
|
22
|
+
// Get pre_operations to find updated output partitions
|
|
23
|
+
return `${helpers.output_preops(ctx, config, ctx.ref("stg_ytc_end_screens"))}`;
|
|
24
|
+
})
|
|
45
25
|
.query(
|
|
46
26
|
(ctx) => `
|
|
47
27
|
|
|
@@ -58,7 +38,13 @@ left join ${ctx.ref(
|
|
|
58
38
|
config.titlesTable,
|
|
59
39
|
)} as titles
|
|
60
40
|
using (video_id)
|
|
61
|
-
|
|
41
|
+
${ctx.when(
|
|
42
|
+
ctx.incremental(),
|
|
43
|
+
`where
|
|
44
|
+
data_date in unnest(partitions_to_update)`,
|
|
45
|
+
`where
|
|
46
|
+
data_date > date '${config.startDate}'`,
|
|
47
|
+
)}
|
|
62
48
|
|
|
63
49
|
`,
|
|
64
50
|
);
|
|
@@ -3,45 +3,25 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const column_descriptions = require("../column_descriptions");
|
|
6
|
+
const helpers = require("../helpers");
|
|
6
7
|
|
|
7
8
|
module.exports = (config) => {
|
|
8
9
|
// eslint-disable-next-line no-undef
|
|
9
10
|
return publish("ytc_list_basic", {
|
|
10
11
|
type: "incremental",
|
|
11
|
-
schema: config.
|
|
12
|
+
schema: config.target.outputSchema,
|
|
12
13
|
tags: ["youtube", "output", "daily"],
|
|
13
14
|
bigquery: {
|
|
14
|
-
partitionBy: "
|
|
15
|
+
partitionBy: "data_date",
|
|
15
16
|
clusterBy: ["playlist_id", "video_id"],
|
|
16
17
|
},
|
|
17
18
|
columns: column_descriptions.column_descriptions,
|
|
18
19
|
description: "YT Channel Playlist Basic Report Table - Intermediate",
|
|
19
20
|
})
|
|
20
|
-
.preOps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
--Set the incremental update checkpoint based on current max partition value minus lookback.
|
|
27
|
-
set interaction_date_checkpoint = (
|
|
28
|
-
${ctx.when(
|
|
29
|
-
ctx.incremental(),
|
|
30
|
-
`select
|
|
31
|
-
least(
|
|
32
|
-
(select date_sub(current_date(), interval ${config.daysBack} day)),
|
|
33
|
-
(select date_sub(max(interaction_date), interval ${config.daysBack} day) from ${ctx.self()})
|
|
34
|
-
)`,
|
|
35
|
-
`select date("${config.startDate}")`,
|
|
36
|
-
)}
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
${ctx.when(
|
|
40
|
-
ctx.incremental(),
|
|
41
|
-
`delete ${ctx.self()} where interaction_date > interaction_date_checkpoint`,
|
|
42
|
-
)}
|
|
43
|
-
`,
|
|
44
|
-
)
|
|
21
|
+
.preOps((ctx) => {
|
|
22
|
+
// Get pre_operations to find updated output partitions
|
|
23
|
+
return `${helpers.output_preops(ctx, config, ctx.ref("stg_ytc_list_basic"))}`;
|
|
24
|
+
})
|
|
45
25
|
.query(
|
|
46
26
|
(ctx) => `
|
|
47
27
|
|
|
@@ -51,7 +31,13 @@ with int_ex_titles as (
|
|
|
51
31
|
* except (source_partition_date),
|
|
52
32
|
playlist_saves_added - playlist_saves_removed as playlist_saves_net
|
|
53
33
|
from ${ctx.ref("stg_ytc_list_basic")}
|
|
54
|
-
|
|
34
|
+
${ctx.when(
|
|
35
|
+
ctx.incremental(),
|
|
36
|
+
`where
|
|
37
|
+
data_date in unnest(partitions_to_update)`,
|
|
38
|
+
`where
|
|
39
|
+
data_date > date '${config.startDate}'`,
|
|
40
|
+
)}
|
|
55
41
|
),
|
|
56
42
|
|
|
57
43
|
int_with_video_titles as (
|