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

Commit 6a064d2

Browse files
Dan Leedataform.co
authored andcommitted
specifically reference timestamp fields
1 parent bddc8a5 commit 6a064d2

6 files changed

Lines changed: 18 additions & 18 deletions

File tree

includes/page_events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ module.exports = (params) => {
1414
1515
-- format page calls into a format suitable to join with track calls
1616
select
17-
"timestamp",
17+
pages.timestamp,
1818
user_id,
1919
anonymous_id,
2020
id as page_id,
2121
${Object.entries({...segmentCommon.PAGE_FIELDS, ...segmentCommon.customPageFieldsObj}).map(
2222
([key, value]) => `${key} as ${value}`).join(",\n ")}
2323
from
24-
${ctx.ref(params.segmentSchema, "pages")}
24+
${ctx.ref(params.segmentSchema, "pages")} as pages
2525
2626
`)
2727
}

includes/sessionized_events.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ module.exports = (params) => {
88
with segment_events_combined as (
99
-- combine page and track tables into a full events table
1010
select
11-
"timestamp",
11+
track_events.timestamp,
1212
user_id,
1313
anonymous_id,
1414
track_id,
1515
null as page_id
1616
from
17-
${params.segmentSchema, ctx.ref("segment_track_events")}
17+
${params.segmentSchema, ctx.ref("segment_track_events")} as track_events
1818
union all
1919
select
20-
"timestamp",
20+
page_events.timestamp,
2121
user_id,
2222
anonymous_id,
2323
null as track_id,
2424
page_id
2525
from
26-
${params.segmentSchema, ctx.ref("segment_page_events")}
26+
${params.segmentSchema, ctx.ref("segment_page_events")} as page_events
2727
),
2828
2929
segment_events_mapped as (
3030
-- map anonymous_id to user_id (where possible)
3131
select
32-
"timestamp",
32+
segment_events_combined.timestamp,
3333
coalesce(
3434
segment_events_combined.user_id,
3535
segment_user_anonymous_map.user_id,
@@ -49,7 +49,7 @@ select
4949
*,
5050
coalesce(
5151
(
52-
${crossdb.timestampDiff(`millisecond`, `"timestamp"`,
52+
${crossdb.timestampDiff(`millisecond`, `segment_events_mapped.timestamp`,
5353
crossdb.windowFunction({
5454
func: "lag",
5555
value: "timestamp",
@@ -75,7 +75,7 @@ select
7575
value: "case when session_start_event then 1 else 0 end",
7676
ignore_nulls: false,
7777
partition_fields: "user_id",
78-
order_fields: '"timestamp" asc',
78+
order_fields: 'session_starts.timestamp asc',
7979
frame_clause: "rows between unbounded preceding and current row"
8080
})} as session_index
8181
from

includes/sessions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ select distinct
2222
value: value,
2323
ignore_nulls: true,
2424
partition_fields: "session_id",
25-
order_fields: '"timestamp" asc',
25+
order_fields: 'sessionized_pages.timestamp asc',
2626
})} as first_${value}`).join(",\n ")},
2727
${Object.entries({...segmentCommon.PAGE_FIELDS, ...segmentCommon.customPageFieldsObj}).map(
2828
([key, value]) => `${crossdb.windowFunction({
2929
func: "last_value",
3030
value: value,
3131
ignore_nulls: true,
3232
partition_fields: "session_id",
33-
order_fields: '"timestamp" asc',
33+
order_fields: 'sessionized_pages.timestamp asc',
3434
})} as last_${value}`).join(",\n ")}
3535
from
36-
${ctx.ref(params.defaultConfig.schema, "segment_sessionized_pages")}
36+
${ctx.ref(params.defaultConfig.schema, "segment_sessionized_pages")} as sessionized_pages
3737
)
3838
3939
select

includes/track_events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ module.exports = (params) => {
1212
1313
-- format track calls into a format suitable to join with page calls
1414
select
15-
"timestamp",
15+
tracks.timestamp,
1616
user_id,
1717
anonymous_id,
1818
id as track_id,
1919
${Object.entries({...segmentCommon.TRACK_FIELDS, ...segmentCommon.customTrackFieldsObj}).map(
2020
([key, value]) => `${key} as ${value}`).join(",\n ")}
2121
from
22-
${ctx.ref(params.segmentSchema, "tracks")}
22+
${ctx.ref(params.segmentSchema, "tracks")} as tracks
2323
`)
2424
}

includes/user_map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ select distinct
4343
value: "user_id",
4444
ignore_nulls: false,
4545
partition_fields: "anonymous_id",
46-
order_fields: '"timestamp" asc',
46+
order_fields: "anonymous_id_user_id_pairs.timestamp asc",
4747
})} as user_id
4848
from
4949
anonymous_id_user_id_pairs

includes/users.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ select distinct
2020
${USER} as user_id,
2121
${crossdb.windowFunction({
2222
func: "first_value",
23-
value: '"timestamp"',
23+
value: "identifies.timestamp",
2424
ignore_nulls: true,
2525
partition_fields: USER,
26-
order_fields: '"timestamp" asc',
26+
order_fields: "identifies.timestamp asc",
2727
})} as timestamp
2828
${params.customUserFields.length ? `,` : ``}
2929
${params.customUserFields.map(f=> `${crossdb.windowFunction({
3030
func: "first_value",
3131
value: f,
3232
ignore_nulls: true,
3333
partition_fields: USER,
34-
order_fields: '"timestamp" desc',
34+
order_fields: "identifies.timestamp desc",
3535
})} as ${f}`).join(",\n ")}
3636
from
3737
${ctx.ref(params.defaultConfig.schema, "segment_user_map")} as segment_user_anonymous_map

0 commit comments

Comments
 (0)