Skip to content

Value sign: subtraction of opposite-sign operands is Unknown instead of the left operand's sign #1269

Open

Description

@zzylol

Example

sum(rate(requests_total[5m])) - min(temperature_below_zero) over a counter (non-negative) and a source whose value is declared non-positive: the result is non-negative minus non-positive, which is non-negative, but the memo gives its value column the sign Unknown. Any error contract that needs a value of one sign (for example a relative error over a sum) then cannot use it, so a summary candidate above it is not offered.

Where

arithmetic_sign in crates/types/src/stages/logical/column_properties.rs (on the #1230 branch) handles +, * and /; every other operator, - included, falls into the Unknown arm. It is shared by vector BinaryOp and scalar expressions, so both lose the sign.

Proposed rule

Subtraction is addition of the negated right operand: arithmetic_sign(Sub, l, r) = arithmetic_sign(Add, l, flipped(r)):

left right left - right
NonNegative NonPositive NonNegative
NonPositive NonNegative NonPositive
same sign, or either Unknown Unknown

Under the sign-bit definition of ValueSign this holds for zeros and infinities too (x - y with both sign bits as above never yields NaN: +Inf - (-Inf) = +Inf).

This only adds precision; today's Unknown is safe. Found in the review of #1230 (part of #1207).

Done when

  • arithmetic_sign covers Sub as above, with no second copy of the add rule.
  • Tests for both rows (vector and scalar forms) and for a same-sign subtraction staying Unknown.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestirPre-ASAP or post-ASAP intermediate representation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions