Skip to content

Commit 61c39a0

Browse files
Devdutt Shenoinikhilsinhaparseable
authored andcommitted
bounds are concrete
1 parent 0ef3b9d commit 61c39a0

File tree

1 file changed

+24
-42
lines changed

1 file changed

+24
-42
lines changed

src/query/mod.rs

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ pub struct DateBinRecord {
250250
pub log_count: u64,
251251
}
252252

253+
struct DateBinBounds {
254+
start: DateTime<Utc>,
255+
end: DateTime<Utc>,
256+
}
257+
253258
/// DateBin Request.
254259
#[derive(Debug, Deserialize, Clone)]
255260
#[serde(rename_all = "camelCase")]
@@ -284,20 +289,8 @@ impl DateBinRequest {
284289
let mut date_bin_records = Vec::new();
285290

286291
for bin in final_date_bins {
287-
let date_bin_timestamp = match &bin[0] {
288-
PartialTimeFilter::Low(Bound::Included(ts)) => ts.and_utc().timestamp_millis(),
289-
_ => unreachable!(),
290-
};
291-
292292
// extract start and end time to compare
293-
let bin_start = match &bin[0] {
294-
PartialTimeFilter::Low(Bound::Included(ts)) => ts,
295-
_ => unreachable!(),
296-
};
297-
let bin_end = match &bin[1] {
298-
PartialTimeFilter::High(Bound::Included(ts) | Bound::Excluded(ts)) => ts,
299-
_ => unreachable!(),
300-
};
293+
let date_bin_timestamp = bin.start.timestamp_millis();
301294

302295
let total_num_rows: u64 = all_manifest_files
303296
.iter()
@@ -307,10 +300,9 @@ impl DateBinRequest {
307300
c.name == time_partition
308301
&& match &c.stats {
309302
Some(crate::catalog::column::TypedStatistics::Int(int64_type)) => {
310-
let min = DateTime::from_timestamp_millis(int64_type.min)
311-
.unwrap()
312-
.naive_utc();
313-
bin_start <= &min && bin_end >= &min
303+
let min =
304+
DateTime::from_timestamp_millis(int64_type.min).unwrap();
305+
bin.start <= min && bin.end >= min
314306
}
315307
_ => false,
316308
}
@@ -329,9 +321,8 @@ impl DateBinRequest {
329321
Ok(date_bin_records)
330322
}
331323

332-
/// calculate the endTime for each bin based on num bins
333-
fn get_bins(&self, time_range: &TimeRange) -> Vec<[PartialTimeFilter; 2]> {
334-
// get total minutes elapsed between start and end time
324+
/// Calculate the end time for each bin based on the number of bins
325+
fn get_bins(&self, time_range: &TimeRange) -> Vec<DateBinBounds> {
335326
let total_minutes = time_range
336327
.end
337328
.signed_duration_since(time_range.start)
@@ -354,33 +345,24 @@ impl DateBinRequest {
354345
self.num_bins - 1
355346
};
356347

348+
// Create bins for all but the last date
357349
for _ in 0..loop_end {
358-
let bin_end = start + Duration::minutes(quotient as i64);
359-
final_date_bins.push([
360-
PartialTimeFilter::Low(Bound::Included(start.naive_utc())),
361-
PartialTimeFilter::High(Bound::Excluded(bin_end.naive_utc())),
362-
]);
363-
364-
start = bin_end;
350+
let end = start + Duration::minutes(quotient as i64);
351+
final_date_bins.push(DateBinBounds { start, end });
352+
start = end;
365353
}
366354

367-
// construct the last bin
368-
// if we have remainder, then the last bin will be as long as the remainder
369-
// else it will be as long as the quotient
355+
// Add the last bin, accounting for any remainder, should we include it?
370356
if have_remainder {
371-
final_date_bins.push([
372-
PartialTimeFilter::Low(Bound::Included(start.naive_utc())),
373-
PartialTimeFilter::High(Bound::Excluded(
374-
(start + Duration::minutes(remainder as i64)).naive_utc(),
375-
)),
376-
]);
357+
final_date_bins.push(DateBinBounds {
358+
start,
359+
end: start + Duration::minutes(remainder as i64),
360+
});
377361
} else {
378-
final_date_bins.push([
379-
PartialTimeFilter::Low(Bound::Included(start.naive_utc())),
380-
PartialTimeFilter::High(Bound::Excluded(
381-
(start + Duration::minutes(quotient as i64)).naive_utc(),
382-
)),
383-
]);
362+
final_date_bins.push(DateBinBounds {
363+
start,
364+
end: start + Duration::minutes(quotient as i64),
365+
});
384366
}
385367

386368
final_date_bins

0 commit comments

Comments
 (0)