@@ -27,7 +27,7 @@ use crate::{
27
27
use arrow_array:: RecordBatch ;
28
28
use arrow_schema:: { Schema , SchemaRef , SortOptions } ;
29
29
use bytes:: Bytes ;
30
- use chrono:: { DateTime , NaiveDateTime , Timelike , Utc } ;
30
+ use chrono:: { DateTime , NaiveDateTime , TimeDelta , Timelike , Utc } ;
31
31
use datafusion:: catalog:: Session ;
32
32
use datafusion:: common:: stats:: Precision ;
33
33
use datafusion:: logical_expr:: utils:: conjunction;
@@ -442,7 +442,7 @@ impl TableProvider for StandardTableProvider {
442
442
return Err ( DataFusionError :: Plan ( "potentially unbounded query on time range. Table scanning requires atleast one time bound" . to_string ( ) ) ) ;
443
443
}
444
444
445
- if include_now ( filters , & time_partition ) {
445
+ if is_within_staging_window ( & time_filters ) {
446
446
if let Ok ( staging) = PARSEABLE . get_stream ( & self . stream ) {
447
447
let records = staging. recordbatches_cloned ( & self . schema ) ;
448
448
let reversed_mem_table = reversed_mem_table ( records, self . schema . clone ( ) ) ?;
@@ -730,23 +730,21 @@ fn return_listing_time_filters(
730
730
}
731
731
}
732
732
733
- pub fn include_now ( filters : & [ Expr ] , time_partition : & Option < String > ) -> bool {
734
- let current_minute = Utc :: now ( )
733
+ /// We should consider data in staging for queries concerning a time period,
734
+ /// ending within 5 minutes from now. e.g. If current time is 5
735
+ pub fn is_within_staging_window ( time_filters : & [ PartialTimeFilter ] ) -> bool {
736
+ let five_minutes_back = ( Utc :: now ( ) - TimeDelta :: minutes ( 5 ) )
735
737
. with_second ( 0 )
736
738
. and_then ( |x| x. with_nanosecond ( 0 ) )
737
739
. expect ( "zeroed value is valid" )
738
740
. naive_utc ( ) ;
739
741
740
- let time_filters = extract_primary_filter ( filters, time_partition) ;
741
-
742
- let upper_bound_matches = time_filters. iter ( ) . any ( |filter| match filter {
742
+ if time_filters. iter ( ) . any ( |filter| match filter {
743
743
PartialTimeFilter :: High ( Bound :: Excluded ( time) )
744
744
| PartialTimeFilter :: High ( Bound :: Included ( time) )
745
- | PartialTimeFilter :: Eq ( time) => time > & current_minute ,
745
+ | PartialTimeFilter :: Eq ( time) => time >= & five_minutes_back ,
746
746
_ => false ,
747
- } ) ;
748
-
749
- if upper_bound_matches {
747
+ } ) {
750
748
return true ;
751
749
}
752
750
@@ -828,7 +826,7 @@ pub async fn collect_manifest_files(
828
826
}
829
827
830
828
// Extract start time and end time from filter predicate
831
- fn extract_primary_filter (
829
+ pub fn extract_primary_filter (
832
830
filters : & [ Expr ] ,
833
831
time_partition : & Option < String > ,
834
832
) -> Vec < PartialTimeFilter > {
0 commit comments