fix abs monotonicity

Signed-off-by: Duc Canh Le <duccanh.le@ahrefs.com>
This commit is contained in:
Duc Canh Le 2024-04-29 01:33:48 +00:00
parent 0ac60137f0
commit 4b7abbce68
4 changed files with 11 additions and 3 deletions

View File

@ -45,7 +45,7 @@ template <> struct FunctionUnaryArithmeticMonotonicity<NameAbs>
if ((left_float < 0 && right_float > 0) || (left_float > 0 && right_float < 0))
return {};
return { .is_monotonic = true, .is_positive = left_float > 0, .is_strict = true, };
return { .is_monotonic = true, .is_positive = std::min(left_float, right_float) >= 0, .is_strict = true, };
}
};

View File

@ -2860,9 +2860,9 @@ bool KeyCondition::mayBeTrueInRange(
String KeyCondition::RPNElement::toString() const
{
if (argument_num_of_space_filling_curve)
return toString(fmt::format("argument {} of column {}", *argument_num_of_space_filling_curve, key_column), false);
return toString(fmt::format("argument {} of column {}", *argument_num_of_space_filling_curve, key_column), true);
else
return toString(fmt::format("column {}", key_column), false);
return toString(fmt::format("column {}", key_column), true);
}
String KeyCondition::RPNElement::toString(std::string_view column_name, bool print_constants) const

View File

@ -0,0 +1,2 @@
1 2023-05-04 22:17:23 0
2 2023-05-04 22:17:23 0

View File

@ -0,0 +1,6 @@
CREATE TABLE t (id UInt64, ts DateTime) ENGINE = MergeTree() ORDER BY (id, ts) SETTINGS index_granularity = 2;
INSERT INTO t VALUES (1, '2023-05-04 21:17:23') (1, '2023-05-04 22:17:23') (2, '2023-05-04 22:17:23') (2, '2023-05-04 23:17:23');
SELECT *, abs(toUnixTimestamp(ts) - toUnixTimestamp(1683238643)) AS error FROM t WHERE error < 3600;