Skip to content

Commit ab6b3bf

Browse files
author
Devdutt Shenoi
committed
feat: standardize field names
1 parent 800118b commit ab6b3bf

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/handlers/http/query.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ pub async fn query(req: HttpRequest, query_request: Query) -> Result<HttpRespons
114114
};
115115
let count_records = counts_req.get_bin_density().await?;
116116
// NOTE: this should not panic, since there is atleast one bin, always
117-
let log_count = count_records[0].log_count;
117+
let count = count_records[0].count;
118118
let response = if query_request.fields {
119119
json!({
120120
"fields": [&column_name],
121-
"records": [json!({column_name: log_count})]
121+
"records": [json!({column_name: count})]
122122
})
123123
} else {
124-
Value::Array(vec![json!({column_name: log_count})])
124+
Value::Array(vec![json!({column_name: count})])
125125
};
126126

127127
let time = time.elapsed().as_secs_f64();
@@ -164,11 +164,7 @@ pub async fn get_counts(
164164
let records = counts_request.get_bin_density().await?;
165165

166166
Ok(web::Json(CountsResponse {
167-
fields: vec![
168-
"counts_start_timestamp".into(),
169-
"counts_end_timestamp".into(),
170-
"log_count".into(),
171-
],
167+
fields: vec!["start_time".into(), "end_time".into(), "count".into()],
172168
records,
173169
}))
174170
}

src/query/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ impl Query {
248248
#[derive(Debug, Serialize, Clone)]
249249
pub struct CountsRecord {
250250
/// Start time of the bin
251-
pub counts_start_timestamp: String,
251+
pub start_time: String,
252252
/// End time of the bin
253-
pub counts_end_timestamp: String,
253+
pub end_time: String,
254254
/// Number of logs in the bin
255-
pub log_count: u64,
255+
pub count: u64,
256256
}
257257

258258
struct TimeBounds {
@@ -299,10 +299,14 @@ impl CountsRequest {
299299

300300
for bin in counts {
301301
// extract start and end time to compare
302-
let counts_start_timestamp = bin.start.timestamp_millis();
303-
let counts_end_timestamp = bin.end.timestamp_millis();
302+
let start_time = DateTime::from_timestamp_millis(bin.start.timestamp_millis())
303+
.unwrap()
304+
.to_rfc3339();
305+
let end_time = DateTime::from_timestamp_millis(bin.end.timestamp_millis())
306+
.unwrap()
307+
.to_rfc3339();
304308
// Sum up the number of rows that fall within the bin
305-
let log_count: u64 = all_manifest_files
309+
let count: u64 = all_manifest_files
306310
.iter()
307311
.flat_map(|m| &m.files)
308312
.filter_map(|f| {
@@ -324,13 +328,9 @@ impl CountsRequest {
324328
.sum();
325329

326330
counts_records.push(CountsRecord {
327-
counts_start_timestamp: DateTime::from_timestamp_millis(counts_start_timestamp)
328-
.unwrap()
329-
.to_rfc3339(),
330-
counts_end_timestamp: DateTime::from_timestamp_millis(counts_end_timestamp)
331-
.unwrap()
332-
.to_rfc3339(),
333-
log_count,
331+
start_time,
332+
end_time,
333+
count,
334334
});
335335
}
336336
Ok(counts_records)

0 commit comments

Comments
 (0)