Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/handlers/http/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ pub async fn query(req: HttpRequest, query_request: Query) -> Result<HttpRespons
};
let count_records = counts_req.get_bin_density().await?;
// NOTE: this should not panic, since there is atleast one bin, always
let log_count = count_records[0].log_count;
let count = count_records[0].count;
let response = if query_request.fields {
json!({
"fields": [&column_name],
"records": [json!({column_name: log_count})]
"records": [json!({column_name: count})]
})
} else {
Value::Array(vec![json!({column_name: log_count})])
Value::Array(vec![json!({column_name: count})])
};

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

Ok(web::Json(CountsResponse {
fields: vec![
"counts_start_timestamp".into(),
"counts_end_timestamp".into(),
"log_count".into(),
],
fields: vec!["start_time".into(), "end_time".into(), "count".into()],
records,
}))
}
Expand Down
20 changes: 7 additions & 13 deletions src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ impl Query {
#[derive(Debug, Serialize, Clone)]
pub struct CountsRecord {
/// Start time of the bin
pub counts_start_timestamp: String,
pub start_time: String,
/// End time of the bin
pub counts_end_timestamp: String,
pub end_time: String,
/// Number of logs in the bin
pub log_count: u64,
pub count: u64,
}

struct TimeBounds {
Expand Down Expand Up @@ -299,10 +299,8 @@ impl CountsRequest {

for bin in counts {
// extract start and end time to compare
let counts_start_timestamp = bin.start.timestamp_millis();
let counts_end_timestamp = bin.end.timestamp_millis();
// Sum up the number of rows that fall within the bin
let log_count: u64 = all_manifest_files
let count: u64 = all_manifest_files
.iter()
.flat_map(|m| &m.files)
.filter_map(|f| {
Expand All @@ -324,13 +322,9 @@ impl CountsRequest {
.sum();

counts_records.push(CountsRecord {
counts_start_timestamp: DateTime::from_timestamp_millis(counts_start_timestamp)
.unwrap()
.to_rfc3339(),
counts_end_timestamp: DateTime::from_timestamp_millis(counts_end_timestamp)
.unwrap()
.to_rfc3339(),
log_count,
start_time: bin.start.to_rfc3339(),
end_time: bin.end.to_rfc3339(),
count,
});
}
Ok(counts_records)
Expand Down
Loading