Skip to content

Commit 1b42704

Browse files
committed
chroe: add testcase for time range predicate
1 parent 7c6ef04 commit 1b42704

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

table_engine/src/predicate.rs

+102
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,105 @@ impl<'a> TimeRangeExtractor<'a> {
426426
}
427427
}
428428
}
429+
430+
#[cfg(test)]
431+
mod tests {
432+
use common_types::{
433+
tests::build_schema_with_dictionary,
434+
time::{TimeRange, Timestamp},
435+
};
436+
use datafusion::{
437+
prelude::{col, Expr},
438+
scalar::ScalarValue,
439+
};
440+
441+
use crate::predicate::PredicateBuilder;
442+
443+
fn set_timestamp(ts: i64) -> Expr {
444+
Expr::Literal(ScalarValue::TimestampMillisecond(Some(ts), None))
445+
}
446+
#[test]
447+
fn test_extract_range() {
448+
// The actual range needs to be a subset of the predicate range
449+
let schema = build_schema_with_dictionary();
450+
let cases = vec![
451+
(
452+
col("key2").gt(set_timestamp(10000)),
453+
TimeRange::new(Timestamp::new(10001), Timestamp::MAX).unwrap(),
454+
),
455+
(
456+
col("key2")
457+
.gt(set_timestamp(10000))
458+
.and(col("key2").gt(set_timestamp(500))),
459+
TimeRange::new(Timestamp::new(10001), Timestamp::MAX).unwrap(),
460+
),
461+
(
462+
col("key2")
463+
.gt(set_timestamp(10000))
464+
.or(col("key2").gt(set_timestamp(500))),
465+
TimeRange::new(Timestamp::new(501), Timestamp::MAX).unwrap(),
466+
),
467+
(
468+
col("key2").gt(set_timestamp(10000)).or(col("key2")
469+
.gt(set_timestamp(500))
470+
.and(col("key2").gt(set_timestamp(300)))),
471+
TimeRange::new(Timestamp::new(501), Timestamp::MAX).unwrap(),
472+
),
473+
(
474+
col("key2").gt(set_timestamp(10000)).or(col("key2")
475+
.gt(set_timestamp(500))
476+
.and(col("key2").lt(set_timestamp(600)))),
477+
TimeRange::new(Timestamp::new(501), Timestamp::MAX).unwrap(),
478+
),
479+
(
480+
col("key2")
481+
.gt(set_timestamp(500))
482+
.and(col("key2").lt(set_timestamp(600))),
483+
TimeRange::new(Timestamp::new(501), Timestamp::new(600)).unwrap(),
484+
),
485+
(
486+
col("key2").gt(set_timestamp(10000)).and(
487+
col("key2")
488+
.gt(set_timestamp(500))
489+
.and(col("key2").lt(set_timestamp(600))),
490+
),
491+
TimeRange::new(Timestamp::new(0), Timestamp::new(0)).unwrap(),
492+
),
493+
(
494+
col("key2").gt(set_timestamp(10000)).and(
495+
col("key2")
496+
.gt(set_timestamp(500))
497+
.and(col("key2").gt(set_timestamp(600))),
498+
),
499+
TimeRange::new(Timestamp::new(10001), Timestamp::MAX).unwrap(),
500+
),
501+
(
502+
col("key2").gt(set_timestamp(10)).and(
503+
col("key2")
504+
.lt(set_timestamp(500))
505+
.and(col("key2").gt(set_timestamp(1))),
506+
),
507+
TimeRange::new(Timestamp::new(11), Timestamp::new(500)).unwrap(),
508+
),
509+
(
510+
col("key2")
511+
.lt(set_timestamp(10))
512+
.and(col("key2").gt(set_timestamp(11))),
513+
TimeRange::new(Timestamp::new(0), Timestamp::new(0)).unwrap(),
514+
),
515+
(
516+
col("key2")
517+
.lt(set_timestamp(10))
518+
.or(col("key2").gt(set_timestamp(11))),
519+
TimeRange::new(Timestamp::MIN, Timestamp::MAX).unwrap(),
520+
),
521+
];
522+
for (expr, expcted) in cases {
523+
let predict = PredicateBuilder::default()
524+
.add_pushdown_exprs(&vec![expr.clone()])
525+
.extract_time_range(&schema, &vec![expr])
526+
.build();
527+
assert_eq!(predict.time_range(), expcted);
528+
}
529+
}
530+
}

0 commit comments

Comments
 (0)