In Apache IoTDB 2.0.10, gateway packets normally contain four-byte big-endian integers, but an upstream truncation occasionally leaves two bytes. Direct decoding returns 701 for that row and prevents both valid packets from being returned. I need to retain every row and mark only the malformed decode as NULL.
Reproducible setup:
Table model:
CREATE TABLE packets (gateway STRING TAG, payload BLOB FIELD);
INSERT INTO packets(time, gateway, payload) VALUES (1000, 'g1', X'0000002a'), (2000, 'g1', X'002a'), (3000, 'g1', X'ffffffff');
Unprotected decoder:
SELECT time, payload, FROM_BIG_ENDIAN_32(payload) AS decoded FROM packets ORDER BY time;
Observed result:
Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: Failed to execute function 'from_big_endian_32' due to an invalid input format. Problematic value: 0x002a
Row-preserving guard:
SELECT time, payload, CASE WHEN LENGTH(payload) = 4 THEN FROM_BIG_ENDIAN_32(payload) END AS decoded FROM packets ORDER BY time;
Comparison result:
+-----------------------------+----------+-------+
| time| payload|decoded|
+-----------------------------+----------+-------+
|1970-01-01T08:00:01.000+08:00|0x0000002a| 42|
|1970-01-01T08:00:02.000+08:00| 0x002a| null|
|1970-01-01T08:00:03.000+08:00|0xffffffff| -1|
+-----------------------------+----------+-------+
Does IoTDB provide a row-level TRY form for binary decoding? If not, does CASE WHEN LENGTH(payload)=4 guarantee that the decoder is not evaluated for the other rows, or should valid rows be filtered in a subquery and joined back?