[BugFix] Fix silent integer and long overflow wrapping in Calcite arithmetic (#5164)#26
Conversation
…pensearch-project#5269) (opensearch-project#5293) When querying across indices with conflicting field mappings (boolean vs text), numeric values like 0 were not coerced to boolean, causing "node must be a boolean, found NUMBER" error. Added numeric handling to parseBooleanValue() consistent with ObjectContent.booleanValue(). Signed-off-by: Heng Qian <qianheng@amazon.com>
…thmetic (opensearch-project#5164) Replace SqlStdOperatorTable.PLUS/MINUS/MULTIPLY with overflow-safe UDFs that use Math.addExact/subtractExact/multiplyExact for integer and long types. Floating-point arithmetic is unchanged (IEEE 754 semantics). Signed-off-by: Heng Qian <hengq@amazon.com> Signed-off-by: Heng Qian <qianheng@amazon.com>
Decision LogRoot Cause: The Calcite execution path for PPL arithmetic registered Approach: Created Alternatives Rejected:
Pitfalls:
Things to Watch:
|
Description
Integer and long arithmetic in the Calcite execution path (
evalcommand) silently wraps on overflow. For example,2147483647 + 1returns-2147483648instead of raising an error.Root cause: The PPL function table registered
SqlStdOperatorTable.PLUS/MINUS/MULTIPLYfor numeric arithmetic, which use Java's default wrapping semantics for integer/long types.Fix: Created
SafeArithmeticFunctionUDFs that useMath.addExact,Math.subtractExact, andMath.multiplyExactfor integer and long types, throwingArithmeticExceptionon overflow. Floating-point and decimal arithmetic is unchanged (IEEE 754 semantics). The UDFs use the same operator symbols (+,-,*) andSqlSyntax.BINARYto preserve identical plan display and SQL generation.Related Issues
Resolves opensearch-project#5164
Check List
-s)spotlessCheckpassed (blocked — could not run gradle)Test files
SafeArithmeticFunctionTest.java— unit tests for the safe arithmetic methodsCalcitePPLArithmeticOverflowTest.java— PPL unit tests for overflow detectionCalciteArithmeticOverflowIT.java— integration tests5164.yml— YAML REST test