You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Silent integer and long overflow wrapping in Calcite arithmetic path #5164
PPLPiped processing languagebugSomething isn't workinggood-for-agenttriage/parkedIntentionally parked — bulk-closed during triage, may be reopened later
Root cause: This is a Calcite engine behavior, not specific to the PPL/SQL plugin. Standard Calcite arithmetic operators (SqlStdOperatorTable.PLUS/MINUS/MULTIPLY) generate plain Java +/-/* in the Enumerable code path, which silently wrap on integer/long overflow. Confirmed by reproducing the same wrapping behavior in Calcite's own CsvTest — SELECT iv, iv+1 FROM STATUS with iv = 2147483647 returns -2147483648.
The V2 (legacy) engine does not have this issue — it already uses Math.addExact/subtractExact/multiplyExact.
Prototype Fix
A draft PR is available at #5204 demonstrating a Calcite-native fix using ConvertToChecked — Calcite's built-in visitor that rewrites PLUS → CHECKED_PLUS, MINUS → CHECKED_MINUS, TIMES → CHECKED_MULTIPLY. These checked operators generate SqlFunctions.checkedPlus(int, int) → Math.addExact() calls that throw ArithmeticException on overflow. The fix is controlled by a plugins.calcite.checked_arithmetic.enabled setting (default: true).
This aligns with how most SQL databases handle overflow (PostgreSQL, SQL Server, Oracle, BigQuery all error on integer overflow).
Why We Are Holding Off
Not a critical blocker. The overflow wrapping only manifests when computing boundary-value integer/long arithmetic in eval expressions. This is an edge case that does not block typical analytical workloads.
Auto-resolved by PPL-to-SQL translation. The long-term architecture direction is for PPL to translate to SQL, which then goes through Calcite's standard SQL pipeline. Once that path is in place, Calcite's SqlConformance.checkedArithmetic() can be enabled at the conformance level, and ConvertToChecked is applied automatically during Prepare.prepareSql() — no plugin-level changes needed.
The draft PR remains available if the fix is needed before the PPL-to-SQL translation is complete.
PPLPiped processing languagebugSomething isn't workinggood-for-agenttriage/parkedIntentionally parked — bulk-closed during triage, may be reopened later
Activity
Fix opensearch-project#5164: Replace standard Calcite arithmetic oper…
Fix opensearch-project#5164: Detect integer/long overflow using Calci…
penghuo commentedon Mar 5, 2026
Investigation Summary
Root cause: This is a Calcite engine behavior, not specific to the PPL/SQL plugin. Standard Calcite arithmetic operators (
SqlStdOperatorTable.PLUS/MINUS/MULTIPLY) generate plain Java+/-/*in the Enumerable code path, which silently wrap on integer/long overflow. Confirmed by reproducing the same wrapping behavior in Calcite's own CsvTest —SELECT iv, iv+1 FROM STATUSwithiv = 2147483647returns-2147483648.The V2 (legacy) engine does not have this issue — it already uses
Math.addExact/subtractExact/multiplyExact.Prototype Fix
A draft PR is available at #5204 demonstrating a Calcite-native fix using
ConvertToChecked— Calcite's built-in visitor that rewritesPLUS → CHECKED_PLUS,MINUS → CHECKED_MINUS,TIMES → CHECKED_MULTIPLY. These checked operators generateSqlFunctions.checkedPlus(int, int)→Math.addExact()calls that throwArithmeticExceptionon overflow. The fix is controlled by aplugins.calcite.checked_arithmetic.enabledsetting (default:true).This aligns with how most SQL databases handle overflow (PostgreSQL, SQL Server, Oracle, BigQuery all error on integer overflow).
Why We Are Holding Off
Not a critical blocker. The overflow wrapping only manifests when computing boundary-value integer/long arithmetic in
evalexpressions. This is an edge case that does not block typical analytical workloads.Auto-resolved by PPL-to-SQL translation. The long-term architecture direction is for PPL to translate to SQL, which then goes through Calcite's standard SQL pipeline. Once that path is in place, Calcite's
SqlConformance.checkedArithmetic()can be enabled at the conformance level, andConvertToCheckedis applied automatically duringPrepare.prepareSql()— no plugin-level changes needed.The draft PR remains available if the fix is needed before the PPL-to-SQL translation is complete.
Fix arithmetic overflow for BYTE/SHORT in V2 and all integral types i…
[BugFix] Fix silent integer overflow in arithmetic (opensearch-projec…
[BugFix] Fix silent integer and long overflow wrapping in Calcite ari…
Detect integer/long arithmetic overflow instead of silently wrapping
Detect long (BIGINT) arithmetic overflow instead of silently wrapping
Detect long (BIGINT) arithmetic overflow instead of silently wrapping
Detect long (BIGINT) arithmetic overflow instead of silently wrapping
Detect long (BIGINT) arithmetic overflow instead of silently wrapping
Detect long (BIGINT) arithmetic overflow instead of silently wrapping
Detect long (BIGINT) arithmetic overflow instead of silently wrapping
Detect long (BIGINT) arithmetic overflow instead of silently wrapping (…
Detect long (BIGINT) arithmetic overflow instead of silently wrapping (…