@@ -345,7 +345,7 @@ impl CountsRequest {
345
345
. get_stream ( & self . stream )
346
346
. map_err ( |err| anyhow:: Error :: msg ( err. to_string ( ) ) ) ?
347
347
. get_time_partition ( )
348
- . unwrap_or_else ( || event:: DEFAULT_TIMESTAMP_KEY . to_owned ( ) ) ;
348
+ . unwrap_or ( event:: DEFAULT_TIMESTAMP_KEY . to_owned ( ) ) ;
349
349
350
350
// get time range
351
351
let time_range = TimeRange :: parse_human_time ( & self . start_time , & self . end_time ) ?;
@@ -445,26 +445,32 @@ impl CountsRequest {
445
445
// unwrap because we have asserted that it is some
446
446
let count_conditions = self . conditions . as_ref ( ) . unwrap ( ) ;
447
447
448
+ // get time partition column
449
+ let time_partition = PARSEABLE
450
+ . get_stream ( & self . stream ) ?
451
+ . get_time_partition ( )
452
+ . unwrap_or ( DEFAULT_TIMESTAMP_KEY . into ( ) ) ;
453
+
448
454
let time_range = TimeRange :: parse_human_time ( & self . start_time , & self . end_time ) ?;
449
455
450
456
let dur = time_range. end . signed_duration_since ( time_range. start ) ;
451
457
452
458
let date_bin = if dur. num_minutes ( ) <= 60 * 10 {
453
459
// date_bin 1 minute
454
460
format ! (
455
- "CAST(DATE_BIN('1 minute', \" {}\" .p_timestamp , TIMESTAMP '1970-01-01 00:00:00+00') AS TEXT) as start_time, DATE_BIN('1 minute', p_timestamp , TIMESTAMP '1970-01-01 00:00:00+00') + INTERVAL '1 minute' as end_time" ,
461
+ "CAST(DATE_BIN('1 minute', \" {}\" .\" {time_partition} \" , TIMESTAMP '1970-01-01 00:00:00+00') AS TEXT) as start_time, DATE_BIN('1 minute', \" {time_partition} \" , TIMESTAMP '1970-01-01 00:00:00+00') + INTERVAL '1 minute' as end_time" ,
456
462
self . stream
457
463
)
458
464
} else if dur. num_minutes ( ) > 60 * 10 && dur. num_minutes ( ) < 60 * 240 {
459
465
// date_bin 1 hour
460
466
format ! (
461
- "CAST(DATE_BIN('1 hour', \" {}\" .p_timestamp , TIMESTAMP '1970-01-01 00:00:00+00') AS TEXT) as start_time, DATE_BIN('1 hour', p_timestamp , TIMESTAMP '1970-01-01 00:00:00+00') + INTERVAL '1 hour' as end_time" ,
467
+ "CAST(DATE_BIN('1 hour', \" {}\" .\" {time_partition} \" , TIMESTAMP '1970-01-01 00:00:00+00') AS TEXT) as start_time, DATE_BIN('1 hour', \" {time_partition} \" , TIMESTAMP '1970-01-01 00:00:00+00') + INTERVAL '1 hour' as end_time" ,
462
468
self . stream
463
469
)
464
470
} else {
465
471
// date_bin 1 day
466
472
format ! (
467
- "CAST(DATE_BIN('1 day', \" {}\" .p_timestamp , TIMESTAMP '1970-01-01 00:00:00+00') AS TEXT) as start_time, DATE_BIN('1 day', p_timestamp , TIMESTAMP '1970-01-01 00:00:00+00') + INTERVAL '1 day' as end_time" ,
473
+ "CAST(DATE_BIN('1 day', \" {}\" .\" {time_partition} \" , TIMESTAMP '1970-01-01 00:00:00+00') AS TEXT) as start_time, DATE_BIN('1 day', \" {time_partition} \" , TIMESTAMP '1970-01-01 00:00:00+00') + INTERVAL '1 day' as end_time" ,
468
474
self . stream
469
475
)
470
476
} ;
@@ -653,7 +659,7 @@ fn table_contains_any_time_filters(
653
659
} )
654
660
. any ( |expr| {
655
661
matches ! ( & * expr. left, Expr :: Column ( Column { name, .. } )
656
- if name == time_column)
662
+ if name == & default_timestamp || name == time_column)
657
663
} )
658
664
}
659
665
0 commit comments