Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit d8f90ba

Browse files
Dan Leedataform.co
authored andcommitted
switch from session.config to dataform.projectConfig
1 parent d803204 commit d8f90ba

5 files changed

Lines changed: 30 additions & 48 deletions

File tree

includes/crossdb.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function typeString(warehouse) {
55
postgres: "varchar",
66
snowflake: "varchar",
77
sqldatawarehouse: "string",
8-
})[warehouse || session.config.warehouse];
8+
})[warehouse || dataform.projectConfig.warehouse];
99
}
1010

1111
function timestampDiff(date_part, start_timestamp, end_timestamp, warehouse) {
@@ -21,7 +21,7 @@ function timestampDiff(date_part, start_timestamp, end_timestamp, warehouse) {
2121
} [date_part.toLowerCase()],
2222
snowflake: `datediff(${date_part}, ${start_timestamp}, ${end_timestamp})`,
2323
sqldatawarehouse: `datediff(${date_part}, ${start_timestamp}, ${end_timestamp})`
24-
})[warehouse || session.config.warehouse];
24+
})[warehouse || dataform.projectConfig.warehouse];
2525
}
2626

2727
function generateSurrogateKey(id_array, warehouse) {
@@ -31,7 +31,7 @@ function generateSurrogateKey(id_array, warehouse) {
3131
postgres: `md5(concat(${id_array.map((id) => (`cast(${id} as ${typeString()})`)).join(`,`)}))`,
3232
snowflake: `md5(concat(${id_array.map((id) => (`cast(${id} as ${typeString()})`)).join(`,`)}))`,
3333
sqldatawarehouse: `hashbytes("md5", (concat(${id_array.map((id) => (`cast(${id} as ${typeString()})`)).join(`,`)})))`,
34-
})[warehouse || session.config.warehouse];
34+
})[warehouse || dataform.projectConfig.warehouse];
3535
}
3636

3737
function windowFunction({
@@ -49,7 +49,7 @@ function windowFunction({
4949
postgres: `${func}(${value}) over (partition by ${partition_fields} order by ${ignore_nulls ? `case when ${value} is not null then 0 else 1 end asc` : ``} ${order_fields && ignore_nulls ? `,` : ``} ${order_fields} ${frame_clause ? frame_clause : `rows between unbounded preceding and unbounded following`})`,
5050
snowflake: `${func}(${value} ${ignore_nulls ? `ignore nulls` : ``}) over (partition by ${partition_fields} order by ${order_fields} ${frame_clause ? frame_clause : ``})`,
5151
sqldatawarehouse: `${func}(${value} ${ignore_nulls ? `ignore nulls` : ``}) over (partition by ${partition_fields} order by ${order_fields} ${frame_clause ? frame_clause : ``})`,
52-
})[warehouse || session.config.warehouse];
52+
})[warehouse || dataform.projectConfig.warehouse];
5353
}
5454

5555
module.exports = {

includes/sessions.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,38 +81,38 @@ select
8181
max(segment_sessionized_events.timestamp) as session_end_timestamp,
8282
8383
-- stats about the session
84-
${ctx.when(global.session.config.warehouse == "bigquery", `struct(\n `)}
84+
${ctx.when(global.dataform.projectConfig.warehouse == "bigquery", `struct(\n `)}
8585
${segmentCommon.enabledEvents(params).map((event) =>
8686
`count(segment_sessionized_events.${event}_id) as total_${event}s`).join(`,\n `)},
8787
${crossdb.timestampDiff("millisecond", "min(segment_sessionized_events.timestamp)", "max(segment_sessionized_events.timestamp)")} as duration_millis
88-
${ctx.when(global.session.config.warehouse == "bigquery", `) as stats`)}
88+
${ctx.when(global.dataform.projectConfig.warehouse == "bigquery", `) as stats`)}
8989
9090
-- first values in the session for page fields
9191
${params.includePages ?
92-
`, ${ctx.when(global.session.config.warehouse == "bigquery", `struct(\n `)}
92+
`, ${ctx.when(global.dataform.projectConfig.warehouse == "bigquery", `struct(\n `)}
9393
${Object.entries(segmentCommon.allPageFields(params)).map(
9494
([key, value]) => `first_and_last_page_values.first_${value}`).join(",\n ")}
95-
${ctx.when(global.session.config.warehouse == "bigquery", `) as first_page_values`)},
95+
${ctx.when(global.dataform.projectConfig.warehouse == "bigquery", `) as first_page_values`)},
9696
-- last values in the session for page fields
97-
${ctx.when(global.session.config.warehouse == "bigquery", `struct(\n `)}
97+
${ctx.when(global.dataform.projectConfig.warehouse == "bigquery", `struct(\n `)}
9898
${Object.entries(segmentCommon.allPageFields(params)).map(
9999
([key, value]) => `first_and_last_page_values.last_${value}`).join(",\n ")}
100-
${ctx.when(global.session.config.warehouse == "bigquery", `) as last_page_values`)}` : `` }
100+
${ctx.when(global.dataform.projectConfig.warehouse == "bigquery", `) as last_page_values`)}` : `` }
101101
102102
-- first values in the session for screen fields
103103
${params.includeScreens ?
104-
`, ${ctx.when(global.session.config.warehouse == "bigquery", `struct(\n `)}
104+
`, ${ctx.when(global.dataform.projectConfig.warehouse == "bigquery", `struct(\n `)}
105105
${Object.entries(segmentCommon.allScreenFields(params)).map(
106106
([key, value]) => `first_and_last_screen_values.first_${value}`).join(",\n ")}
107-
${ctx.when(global.session.config.warehouse == "bigquery", `) as first_screen_values`)},
107+
${ctx.when(global.dataform.projectConfig.warehouse == "bigquery", `) as first_screen_values`)},
108108
-- last values in the session for screen fields
109-
${ctx.when(global.session.config.warehouse == "bigquery", `struct(\n `)}
109+
${ctx.when(global.dataform.projectConfig.warehouse == "bigquery", `struct(\n `)}
110110
${Object.entries(segmentCommon.allScreenFields(params)).map(
111111
([key, value]) => `first_and_last_screen_values.last_${value}`).join(",\n ")}
112-
${ctx.when(global.session.config.warehouse == "bigquery", `) as last_screen_values`)}` : `` }
112+
${ctx.when(global.dataform.projectConfig.warehouse == "bigquery", `) as last_screen_values`)}` : `` }
113113
114114
115-
${ctx.when(global.session.config.warehouse == "bigquery", `-- repeated array of records
115+
${ctx.when(global.dataform.projectConfig.warehouse == "bigquery", `-- repeated array of records
116116
,array_agg(
117117
struct(
118118
segment_sessionized_events.timestamp
@@ -148,7 +148,7 @@ from
148148
${params.includeScreens ?
149149
`left join first_and_last_screen_values
150150
using(session_id)` : ``}
151-
${ctx.when(global.session.config.warehouse == "bigquery",
151+
${ctx.when(global.dataform.projectConfig.warehouse == "bigquery",
152152
segmentCommon.enabledEvents(params).map((event) =>
153153
`left join ${ctx.ref(params.defaultConfig.schema, `segment_sessionized_${event}s`)} as segment_sessionized_${event}s
154154
using(${event}_id)`).join(`\n `))}

package-lock.json

Lines changed: 13 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"dependencies": {
3-
"@dataform/core": "1.6.3"
3+
"@dataform/core": "1.13.0"
44
}
55
}

schedules.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)