@@ -123,8 +123,8 @@ function generateReportConfigurations() {
123123
124124 // Generate configurations for each date in range
125125 for ( let date = DATE_RANGE . endDate ;
126- date >= DATE_RANGE . startDate ;
127- date = constants . fnPastMonth ( date ) ) {
126+ date >= DATE_RANGE . startDate ;
127+ date = constants . fnPastMonth ( date ) ) {
128128
129129 // For each available metric
130130 availableMetrics . forEach ( metric => {
@@ -162,44 +162,44 @@ function generateOperationSQL(ctx, reportConfig) {
162162 const { date, metric, lens, sql, tableName } = reportConfig
163163
164164 return `
165- DECLARE job_config JSON;
166-
167- /* First report run - uncomment to create table
168- CREATE TABLE IF NOT EXISTS ${ EXPORT_CONFIG . dataset } .${ tableName }
169- PARTITION BY date
170- CLUSTER BY metric, lens, client
171- AS
172- */
173-
174- --/* Subsequent report run
175- DELETE FROM ${ EXPORT_CONFIG . dataset } .${ tableName }
176- WHERE date = '${ date } '
177- AND metric = '${ metric . id } '
178- AND lens = '${ lens . name } ';
179- INSERT INTO ${ EXPORT_CONFIG . dataset } .${ tableName }
180- --*/
181-
182- SELECT
183- '${ metric . id } ' AS metric,
184- '${ lens . name } ' AS lens,
185- *
186- FROM (
187- ${ sql . query ( ctx , reportConfig ) }
188- );
189-
190- SET job_config = TO_JSON(
191- STRUCT(
192- "cloud_storage" AS destination,
193- STRUCT(
194- "httparchive" AS bucket,
195- "${ buildExportPath ( reportConfig ) } " AS name
196- ) AS config,
197- r"${ buildExportQuery ( reportConfig ) } " AS query
198- )
199- );
200-
201- SELECT reports.run_export_job(job_config);
202- `
165+ DECLARE job_config JSON;
166+
167+ /* First report run - uncomment to create table
168+ CREATE TABLE IF NOT EXISTS ${ EXPORT_CONFIG . dataset } .${ tableName }
169+ PARTITION BY date
170+ CLUSTER BY metric, lens, client
171+ AS
172+ */
173+
174+ --/* Subsequent report run
175+ DELETE FROM ${ EXPORT_CONFIG . dataset } .${ tableName }
176+ WHERE date = '${ date } '
177+ AND metric = '${ metric . id } '
178+ AND lens = '${ lens . name } ';
179+ INSERT INTO ${ EXPORT_CONFIG . dataset } .${ tableName }
180+ --*/
181+
182+ SELECT
183+ '${ metric . id } ' AS metric,
184+ '${ lens . name } ' AS lens,
185+ *
186+ FROM (
187+ ${ sql . query ( ctx , reportConfig ) }
188+ );
189+
190+ SET job_config = TO_JSON(
191+ STRUCT(
192+ "cloud_storage" AS destination,
193+ STRUCT(
194+ "httparchive" AS bucket,
195+ "${ buildExportPath ( reportConfig ) } " AS name
196+ ) AS config,
197+ r"${ buildExportQuery ( reportConfig ) } " AS query
198+ )
199+ );
200+
201+ SELECT reports.run_export_job(job_config);
202+ `
203203}
204204
205205// Generate all report configurations
@@ -210,6 +210,6 @@ reportConfigurations.forEach(reportConfig => {
210210 const operationName = createOperationName ( reportConfig )
211211
212212 operate ( operationName )
213- . tags ( [ 'crawl_complete' , 'reports ' ] )
213+ . tags ( [ 'crawl_complete' , 'crawl_reports ' ] )
214214 . queries ( ctx => generateOperationSQL ( ctx , reportConfig ) )
215215} )
0 commit comments