Skip to content

Commit 6b444c8

Browse files
committed
fix query generation
1 parent 00fae36 commit 6b444c8

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

definitions/output/reports/reports_dynamic.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,32 @@ const bucket = 'httparchive'
55
const storagePath = '/reports/'
66

77
function generateExportQuery (metric, sql, params, ctx) {
8+
let query = ''
89
if (sql.type === 'histogram') {
9-
return `
10+
query = `
1011
SELECT
1112
* EXCEPT(date)
1213
FROM ${ctx.self()}
1314
WHERE date = '${params.date}'
14-
`
15-
} else if (sql.type === 'timeseries') {
16-
return `
15+
`} else if (sql.type === 'timeseries') {
16+
query = `
1717
SELECT
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

2729
function 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 = []
3840
for (
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

@@ -66,7 +69,7 @@ SELECT
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

Comments
 (0)