Skip to content

isthmus: normalize negative RANGE offsets before retyping #1291

Description

@alexandrefimov

Follow-up to #1206, as agreed in #1206 (comment).

Reproduced at ee9f3d20 with the test TPC-H ORDERS schema. Two cases remain:

SELECT SUM(O_TOTALPRICE) OVER (
  ORDER BY O_TOTALPRICE RANGE BETWEEN -5.5 PRECEDING AND CURRENT ROW
) FROM ORDERS;

The converter emits a Preceding bound with a decimal offset of -5.5. The magnitude should be positive and the direction should become Following.

SELECT SUM(O_ORDERKEY) OVER (
  ORDER BY O_ORDERKEY RANGE BETWEEN -2147483648 PRECEDING AND CURRENT ROW
) FROM ORDERS;

The converter now emits a Preceding bound with an i64 offset of -2147483648. It no longer throws the exception reported at a8bf3d5a; it produces an invalid negative distance instead. The positive magnitude 2147483648 fits the i64 ordering type, but the sign and direction are not normalized.

Spec v0.102.0 requires a non-negative RANGE distance. Normalize the sign and direction while preserving the exact value, then represent the magnitude in the ordering expression's compatible offset type.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions