@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.
Files changed (42) hide show
  1. package/includes/column_descriptions.js +137 -95
  2. package/includes/definitions/sources/stg_ytc_annotation.js +16 -31
  3. package/includes/definitions/sources/stg_ytc_basic.js +15 -31
  4. package/includes/definitions/sources/stg_ytc_cards.js +16 -31
  5. package/includes/definitions/sources/stg_ytc_combined.js +15 -31
  6. package/includes/definitions/sources/stg_ytc_demographics.js +16 -31
  7. package/includes/definitions/sources/stg_ytc_device_os.js +16 -31
  8. package/includes/definitions/sources/stg_ytc_end_screens.js +14 -29
  9. package/includes/definitions/sources/stg_ytc_list_basic.js +15 -31
  10. package/includes/definitions/sources/stg_ytc_list_combined.js +16 -30
  11. package/includes/definitions/sources/stg_ytc_list_device_os.js +16 -30
  12. package/includes/definitions/sources/stg_ytc_list_playback.js +16 -30
  13. package/includes/definitions/sources/stg_ytc_list_province.js +15 -31
  14. package/includes/definitions/sources/stg_ytc_list_traffic_source.js +16 -30
  15. package/includes/definitions/sources/stg_ytc_lu_operating_systems.js +1 -1
  16. package/includes/definitions/sources/stg_ytc_playback.js +16 -31
  17. package/includes/definitions/sources/stg_ytc_province.js +15 -31
  18. package/includes/definitions/sources/stg_ytc_share_platform.js +16 -31
  19. package/includes/definitions/sources/stg_ytc_subtitles.js +15 -30
  20. package/includes/definitions/sources/stg_ytc_traffic_source.js +16 -49
  21. package/includes/definitions/ytc_annotation.js +14 -29
  22. package/includes/definitions/ytc_basic.js +14 -30
  23. package/includes/definitions/ytc_cards.js +14 -29
  24. package/includes/definitions/ytc_combined.js +14 -31
  25. package/includes/definitions/ytc_demographics.js +14 -28
  26. package/includes/definitions/ytc_demographics_views.js +15 -29
  27. package/includes/definitions/ytc_device_os.js +14 -28
  28. package/includes/definitions/ytc_end_screens.js +14 -28
  29. package/includes/definitions/ytc_list_basic.js +14 -28
  30. package/includes/definitions/ytc_list_combined.js +14 -27
  31. package/includes/definitions/ytc_list_device_os.js +14 -27
  32. package/includes/definitions/ytc_list_playback.js +14 -27
  33. package/includes/definitions/ytc_list_province.js +14 -28
  34. package/includes/definitions/ytc_list_traffic_source.js +14 -27
  35. package/includes/definitions/ytc_playback.js +14 -28
  36. package/includes/definitions/ytc_province.js +14 -28
  37. package/includes/definitions/ytc_share_platform.js +14 -28
  38. package/includes/definitions/ytc_subtitles.js +14 -27
  39. package/includes/definitions/ytc_traffic_source.js +14 -28
  40. package/includes/helpers.js +12 -0
  41. package/index.js +12 -2
  42. 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.datasetIntermediate,
12
+ schema: config.target.outputSchema,
12
13
  tags: ["youtube", "output", "daily"],
13
14
  bigquery: {
14
- partitionBy: "interaction_date",
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
- (ctx) => `
22
- declare interaction_date_checkpoint default (
23
- select date("${config.startDate}")
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
- where interaction_date > interaction_date_checkpoint
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.datasetIntermediate,
12
+ schema: config.target.outputSchema,
12
13
  tags: ["youtube", "output", "daily"],
13
14
  bigquery: {
14
- partitionBy: "interaction_date",
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
- (ctx) => `
22
- -- Calculate date checkpoint for incremental updates.
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
- where interaction_date > interaction_date_checkpoint
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.datasetIntermediate,
12
+ schema: config.target.outputSchema,
12
13
  tags: ["youtube", "output", "daily"],
13
14
  bigquery: {
14
- partitionBy: "interaction_date",
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
- (ctx) => `
22
- declare interaction_date_checkpoint default (
23
- select date("${config.startDate}")
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
- where interaction_date > interaction_date_checkpoint
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.datasetIntermediate,
12
+ schema: config.target.outputSchema,
12
13
  tags: ["youtube", "output", "daily"],
13
14
  bigquery: {
14
- partitionBy: "interaction_date",
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
- (ctx) => `
22
- -- Calculate date checkpoint for incremental updates.
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
- where interaction_date > interaction_date_checkpoint
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.datasetIntermediate,
12
+ schema: config.target.outputSchema,
12
13
  tags: ["youtube", "output", "daily"],
13
14
  bigquery: {
14
- partitionBy: "interaction_date",
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
- (ctx) => `
22
- declare interaction_date_checkpoint default (
23
- select date("${config.startDate}")
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
- where interaction_date > interaction_date_checkpoint
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.datasetIntermediate,
12
+ schema: config.target.outputSchema,
12
13
  tags: ["youtube", "output", "daily"],
13
14
  bigquery: {
14
- partitionBy: "interaction_date",
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
- (ctx) => `
22
- declare interaction_date_checkpoint default (
23
- select date("${config.startDate}")
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
- interaction_date,
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
- where interaction_date > interaction_date_checkpoint
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.datasetIntermediate,
16
+ schema: config.target.outputSchema,
16
17
  tags: ["youtube", "output", "daily"],
17
18
  bigquery: {
18
- partitionBy: "interaction_date",
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
- (ctx) => `
26
- declare interaction_date_checkpoint default (
27
- select date("${config.startDate}")
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
- where interaction_date > interaction_date_checkpoint
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.datasetIntermediate,
12
+ schema: config.target.outputSchema,
12
13
  tags: ["youtube", "output", "daily"],
13
14
  bigquery: {
14
- partitionBy: "interaction_date",
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
- (ctx) => `
22
- declare interaction_date_checkpoint default (
23
- select date("${config.startDate}")
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
- where interaction_date > interaction_date_checkpoint
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.datasetIntermediate,
12
+ schema: config.target.outputSchema,
12
13
  tags: ["youtube", "output", "daily"],
13
14
  bigquery: {
14
- partitionBy: "interaction_date",
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
- (ctx) => `
22
- declare interaction_date_checkpoint default (
23
- select date("${config.startDate}")
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
- where interaction_date > interaction_date_checkpoint
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 (