@@ -5,30 +5,32 @@ const bucket = 'httparchive'
55const storagePath = '/reports/'
66
77function generateExportQuery ( metric , sql , params , ctx ) {
8+ let query = ''
89 if ( sql . type === 'histogram' ) {
9- return `
10+ query = `
1011SELECT
1112 * EXCEPT(date)
1213FROM ${ ctx . self ( ) }
1314WHERE date = '${ params . date } '
14- `
15- } else if ( sql . type === 'timeseries' ) {
16- return `
15+ ` } else if ( sql . type === 'timeseries' ) {
16+ query = `
1717SELECT
1818 FORMAT_DATE('%Y_%m_%d', date) AS date,
1919 * EXCEPT(date)
20- FROM reports.${ metric } _timeseries
21- `
22- } else {
20+ FROM ${ ctx . self ( ) }
21+ ` } else {
2322 throw new Error ( 'Unknown SQL type' )
2423 }
24+
25+ const queryOutput = query . replace ( / [ \r \n ] + / g, ' ' ) ;
26+ return queryOutput
2527}
2628
2729function generateExportPath ( metric , sql , params ) {
2830 if ( sql . type === 'histogram' ) {
29- return `${ storagePath } ${ params . date . replaceAll ( '-' , '_' ) } /${ metric } .json`
31+ return `${ storagePath } ${ params . date . replaceAll ( '-' , '_' ) } /${ metric . id } .json`
3032 } else if ( sql . type === 'timeseries' ) {
31- return `${ storagePath } ${ metric } .json`
33+ return `${ storagePath } ${ metric . id } .json`
3234 } else {
3335 throw new Error ( 'Unknown SQL type' )
3436 }
@@ -38,7 +40,8 @@ const iterations = []
3840for (
3941 let date = constants . currentMonth ; date >= constants . currentMonth ; date = constants . fnPastMonth ( date ) ) {
4042 iterations . push ( {
41- date
43+ date,
44+ devRankFilter : constants . devRankFilter
4245 } )
4346}
4447
6669 "bucket": "${ bucket } ",
6770 "name": "${ generateExportPath ( metric , sql , params ) } "
6871 },
69- "query": "${ generateExportQuery ( metric , sql , params , ctx ) } "}
72+ "query": "${ generateExportQuery ( metric , sql , params , ctx ) } "
7073 }'''
7174 );
7275 ` )
@@ -92,7 +95,7 @@ INSERT INTO reports.${metric.id}_${sql.type}` + sql.query(ctx, params)
9295 "bucket": "${ bucket } ",
9396 "name": "${ generateExportPath ( metric , sql , params ) } "
9497 },
95- "query": "${ generateExportQuery ( metric , sql , params , ctx ) } "}
98+ "query": "${ generateExportQuery ( metric , sql , params , ctx ) } "
9699 }'''
97100 );
98101 ` )
0 commit comments