@@ -18,6 +18,7 @@ module.exports = (params) => {
1818 ...params . defaultConfig
1919 } ) . query ( ctx => `
2020
21+ /* TODO: optimise this code to make it work, or enable only for incremental builds
2122with first_and_last_page_values as (
2223select distinct
2324 session_id,
@@ -40,6 +41,7 @@ select distinct
4041 from
4142 ${ ctx . ref ( params . defaultConfig . schema , "segment_sessionized_pages" ) } as sessionized_pages
4243 )
44+ */
4345
4446select
4547 segment_sessionized_events.session_id,
@@ -54,21 +56,20 @@ select
5456 count(segment_sessionized_events.page_id) as total_pages,
5557 ${ crossdb . timestampDiff ( "millisecond" , "min(segment_sessionized_events.timestamp)" , "max(segment_sessionized_events.timestamp)" ) } as duration_millis
5658 ${ ctx . when ( global . session . config . warehouse == "bigquery" , `) as stats` ) } ,
57-
59+ /* See TODO at start of script
5860 -- first values in the session for page fields
5961 ${ ctx . when ( global . session . config . warehouse == "bigquery" , `struct(\n ` ) }
6062 ${ Object . entries ( { ...segmentCommon . PAGE_FIELDS , ...customPageFieldsObj } ) . map (
6163 ( [ key , value ] ) => `first_and_last_page_values.first_${ value } ` ) . join ( ",\n " ) }
6264 ${ ctx . when ( global . session . config . warehouse == "bigquery" , `) as first_page_values` ) } ,
63-
6465 -- last values in the session for page fields
6566 ${ ctx . when ( global . session . config . warehouse == "bigquery" , `struct(\n ` ) }
6667 ${ Object . entries ( { ...segmentCommon . PAGE_FIELDS , ...customPageFieldsObj } ) . map (
6768 ( [ key , value ] ) => `first_and_last_page_values.last_${ value } ` ) . join ( ",\n " ) }
6869 ${ ctx . when ( global . session . config . warehouse == "bigquery" , `) as last_page_values` ) }
69-
70+ */
7071 ${ ctx . when ( global . session . config . warehouse == "bigquery" , `-- repeated array of records
71- , array_agg(
72+ /*,*/ array_agg(
7273 struct(
7374 segment_sessionized_events.timestamp,
7475 struct(
@@ -87,17 +88,22 @@ select
8788 ) as records` ) }
8889from
8990 ${ ctx . ref ( params . defaultConfig . schema , "segment_sessionized_events" ) } as segment_sessionized_events
91+ /* See TODO at start of script
9092 left join first_and_last_page_values
9193 using(session_id)
94+ */
9295 ${ ctx . when ( global . session . config . warehouse == "bigquery" , `
9396 left join ${ ctx . ref ( params . defaultConfig . schema , "segment_sessionized_pages" ) } as segment_sessionized_pages
9497 using(page_id)
9598 left join ${ ctx . ref ( params . defaultConfig . schema , "segment_sessionized_tracks" ) } as segment_sessionized_tracks
9699 using(track_id)` ) }
97100group by
98- session_id, session_index, user_id ${ Object . entries ( { ...segmentCommon . PAGE_FIELDS , ...customPageFieldsObj } ) . map (
101+ session_id, session_index, user_id
102+ /* See TODO at start of script
103+ ${ Object . entries ( { ...segmentCommon . PAGE_FIELDS , ...customPageFieldsObj } ) . map (
99104 ( [ key , value ] ) => `, first_${ value } ` ) . join ( " " ) }
100105 ${ Object . entries ( { ...segmentCommon . PAGE_FIELDS , ...customPageFieldsObj } ) . map (
101106 ( [ key , value ] ) => `, last_${ value } ` ) . join ( " " ) }
107+ */
102108` )
103109}
0 commit comments