Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/src/reader/filter/time_operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ bool TimeBetween::satisfy(Statistic* statistic) {
return not_;
}
if (not_) {
return statistic->end_time_ < value1_ ||
statistic->start_time_ > value2_;
return statistic->start_time_ < value1_ ||
statistic->end_time_ > value2_;
} else {
return statistic->end_time_ >= value1_ &&
statistic->start_time_ <= value2_;
Expand Down
26 changes: 26 additions & 0 deletions cpp/test/reader/filter/time_operator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,32 @@ TEST(TimeOperatorTest, TimeBetweenNotBetweenSemantics) {
(std::vector<bool>{true, true, false, false, false, true}));
}

// Regression (TsFile-191): NOT BETWEEN's statistic-level pruning used to
// keep a page only when it lay entirely outside [value1_, value2_], so a page
// that partially overlapped the interval was silently skipped even though it
// contained out-of-interval times. The correct test is "may contain a time
// outside the interval": start_time_ < value1_ || end_time_ > value2_.
TEST(TimeOperatorTest, TimeBetweenNotBetweenStatisticPartialOverlap) {
TimeBetween not_between(3, 5, /*not_between=*/true);

// Pages partially overlapping [3, 5] still contain times outside it (e.g.
// 2 or 6), so NOT BETWEEN must keep them. The old pruning returned false
// here and silently dropped matching rows.
EXPECT_TRUE(satisfy_stat(not_between, 2, 4));
EXPECT_TRUE(satisfy_stat(not_between, 4, 6));
EXPECT_TRUE(satisfy_stat(not_between, 2, 6));

// Pages wholly inside [3, 5] match nothing and are correctly pruned.
EXPECT_FALSE(satisfy_stat(not_between, 3, 4));
EXPECT_FALSE(satisfy_stat(not_between, 3, 3));
EXPECT_FALSE(satisfy_stat(not_between, 5, 5));
EXPECT_FALSE(satisfy_stat(not_between, 3, 5));

// Pages wholly outside the interval are kept.
EXPECT_TRUE(satisfy_stat(not_between, 1, 2));
EXPECT_TRUE(satisfy_stat(not_between, 6, 9));
}

TEST(TimeOperatorTest, TimeBetweenInvertedRange) {
TimeBetween inverted(5, 3, /*not_between=*/false);
Statistic any = make_stat(0, 100);
Expand Down
Loading