ABS(-2147483648) remains negative in Apache IoTDB table model
14:17 30 Jul 2026

A controller on one production line sends signed 32-bit pulse deltas. I calculate their magnitude in Apache IoTDB 2.0.8 table model before applying an alarm threshold.

The smallest sample below is a real value emitted during a counter rollover:

CREATE TABLE counter_samples (
time TIMESTAMP TIME,
line_id STRING TAG,
pulse_delta INT32 FIELD
);

INSERT INTO counter_samples(time, line_id, pulse_delta)
VALUES (1000, 'line-a', -2147483648);
INSERT INTO counter_samples(time, line_id, pulse_delta)
VALUES (2000, 'line-a', -2147483647);

The direct calculation returns a negative magnitude for only the boundary value:

SELECT time, pulse_delta, ABS(pulse_delta) AS magnitude
FROM counter_samples
ORDER BY time;
+-----------------------------+-----------+-----------+
| time|pulse_delta| magnitude|
+-----------------------------+-----------+-----------+
|1970-01-01T08:00:01.000+08:00|-2147483648|-2147483648|
|1970-01-01T08:00:02.000+08:00|-2147483647| 2147483647|
+-----------------------------+-----------+-----------+

Widening before applying ABS produces the positive value I expected:

SELECT time, pulse_delta,
ABS(CAST(pulse_delta AS INT64)) AS magnitude
FROM counter_samples
ORDER BY time;
+-----------------------------+-----------+----------+
| time|pulse_delta| magnitude|
+-----------------------------+-----------+----------+
|1970-01-01T08:00:01.000+08:00|-2147483648|2147483648|
|1970-01-01T08:00:02.000+08:00|-2147483647|2147483647|
+-----------------------------+-----------+----------+

The negative result can bypass a predicate such as ABS(pulse_delta) > 1000000. Is ABS(INT32) defined to keep the input type even when the positive magnitude cannot fit, or should IoTDB widen the result or report overflow for this boundary?

time-series apache-iotdb