Skip to content

Commit d473745

Browse files
committed
make numBins optional instead
1 parent 312778c commit d473745

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/handlers/http/query.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ async fn handle_count_query(
167167
stream: table_name.to_string(),
168168
start_time: query_request.start_time.clone(),
169169
end_time: query_request.end_time.clone(),
170+
num_bins: Some(1),
170171
conditions: None,
171172
};
172173
let count_records = counts_req.get_bin_density().await?;

src/prism/logstream/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ impl PrismDatasetRequest {
351351
stream: stream.to_owned(),
352352
start_time: "1h".to_owned(),
353353
end_time: "now".to_owned(),
354+
num_bins: Some(10),
354355
conditions: None,
355356
};
356357

src/query/mod.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ pub struct CountsRequest {
332332
pub start_time: String,
333333
/// Excluded end time for counts query
334334
pub end_time: String,
335+
/// optional number of bins to divide the time range into
336+
pub num_bins: Option<u64>,
335337
/// Conditions
336338
pub conditions: Option<CountConditions>,
337339
}
@@ -400,19 +402,23 @@ impl CountsRequest {
400402
.signed_duration_since(time_range.start)
401403
.num_minutes() as u64;
402404

403-
// create number of bins based on total minutes
404-
let num_bins = if total_minutes <= 60 * 5 {
405-
// till 5 hours, 1 bin = 1 min
406-
total_minutes
407-
} else if total_minutes <= 60 * 24 {
408-
// till 1 day, 1 bin = 5 min
409-
total_minutes.div_ceil(5)
410-
} else if total_minutes <= 60 * 24 * 10 {
411-
// till 10 days, 1 bin = 1 hour
412-
total_minutes.div_ceil(60)
405+
let num_bins = if let Some(num_bins) = self.num_bins {
406+
num_bins
413407
} else {
414-
// > 10 days, 1 bin = 1 day
415-
total_minutes.div_ceil(1440)
408+
// create number of bins based on total minutes
409+
if total_minutes <= 60 * 5 {
410+
// till 5 hours, 1 bin = 1 min
411+
total_minutes
412+
} else if total_minutes <= 60 * 24 {
413+
// till 1 day, 1 bin = 5 min
414+
total_minutes.div_ceil(5)
415+
} else if total_minutes <= 60 * 24 * 10 {
416+
// till 10 days, 1 bin = 1 hour
417+
total_minutes.div_ceil(60)
418+
} else {
419+
// > 10 days, 1 bin = 1 day
420+
total_minutes.div_ceil(1440)
421+
}
416422
};
417423

418424
// divide minutes by num bins to get minutes per bin

0 commit comments

Comments
 (0)