File tree Expand file tree Collapse file tree 1 file changed +17
-8
lines changed
definitions/output/reports Expand file tree Collapse file tree 1 file changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -177,31 +177,40 @@ function generateOperationSQL(ctx, reportConfig) {
177177 return `
178178DECLARE job_config JSON;
179179
180- --/* First report run - uncomment to create table
180+ -- Run analysis once
181+ CREATE TEMP TABLE ${ tableName } _temp AS (
182+ ${ sql . query ( ctx , reportConfig ) }
183+ );
184+
185+ -- Create table on first run (schema only, no data)
181186CREATE TABLE IF NOT EXISTS ${ EXPORT_CONFIG . dataset } .${ tableName }
182187PARTITION BY date
183188CLUSTER BY metric, lens, client
184189AS
185- --*/
190+ SELECT
191+ client,
192+ DATE('${ date } ') AS date,
193+ '${ metric . id } ' AS metric,
194+ '${ lens . name } ' AS lens,
195+ * EXCEPT(client)
196+ FROM ${ tableName } _temp
197+ WHERE FALSE;
186198
187- /* Subsequent report run
199+ -- Delete existing data for this partition
188200DELETE FROM ${ EXPORT_CONFIG . dataset } .${ tableName }
189201WHERE date = '${ date } '
190202 AND metric = '${ metric . id } '
191203 AND lens = '${ lens . name } ';
192204
205+ -- Insert fresh data
193206INSERT INTO ${ EXPORT_CONFIG . dataset } .${ tableName }
194- */
195-
196207SELECT
197208 client,
198209 DATE('${ date } ') AS date,
199210 '${ metric . id } ' AS metric,
200211 '${ lens . name } ' AS lens,
201212 * EXCEPT(client)
202- FROM (
203- ${ sql . query ( ctx , reportConfig ) }
204- );
213+ FROM ${ tableName } _temp;
205214
206215SET job_config = TO_JSON(
207216 STRUCT(
You can’t perform that action at this time.
0 commit comments