Skip to content

Fix: Numeric Comparison Precision Loss in JsonPathFilterEvaluationEngine [From: Deepanjan-Fork Repo]#8

Merged
Tushar-Naik merged 2 commits intoPhonePe:mainfrom
DeepanjanKowar:USPOD-5701_Fix-filter-logic
Jan 16, 2026
Merged

Fix: Numeric Comparison Precision Loss in JsonPathFilterEvaluationEngine [From: Deepanjan-Fork Repo]#8
Tushar-Naik merged 2 commits intoPhonePe:mainfrom
DeepanjanKowar:USPOD-5701_Fix-filter-logic

Conversation

@DeepanjanKowar
Copy link
Collaborator

Problem

Numeric filter comparisons (less than, greater than, etc.) were using floatValue() for comparisons, which caused precision loss for large integers. This resulted in incorrect filter evaluation results.

Example of the Bug

// Before fix (using floatValue):
26011303 < 26011304  // Returns FALSE (incorrect!)
// Both values convert to same float: 2.6011304E7
     
// After fix (using doubleValue):
26011303 < 26011304  // Returns TRUE (correct!)
// Values preserved: 2.6011303E7 vs 2.6011304E7

Root Cause

Float has only ~7 significant decimal digits of precision, while double has ~15-17 significant digits.

Solution

Changed all numeric comparison methods in JsonPathFilterEvaluationEngine from using floatValue() to doubleValue():
- lessThan()
- lessThanEquals()
- greaterThan()
- greaterThanEquals()
- between()

Testing

Added comprehensive test coverage for large integer comparisons:
- testLessThanFilterWithLargeIntegers - Tests < operator with large integers
- testLessEqualFilterWithLargeIntegers - Tests <= operator with large integers
- testGreaterThanFilterWithLargeIntegers - Tests > operator with large integers
- testGreaterEqualFilterWithLargeIntegers - Tests >= operator with large integers
- testBetweenFilterWithLargeIntegers - Tests between filter with large integers

All existing tests (90 total) continue to pass, ensuring no regressions.

@Tushar-Naik Tushar-Naik self-assigned this Jan 16, 2026
@DeepanjanKowar
Copy link
Collaborator Author

Duplicate of:
#9

@DeepanjanKowar DeepanjanKowar changed the title Fix: Numeric Comparison Precision Loss in JsonPathFilterEvaluationEngine Fix: Numeric Comparison Precision Loss in JsonPathFilterEvaluationEngine [From: Deepanjan-Fork Repo] Jan 16, 2026
@Tushar-Naik Tushar-Naik added the approved-for-actions Approved for running action pipelines label Jan 16, 2026
@Tushar-Naik Tushar-Naik merged commit dba41f8 into PhonePe:main Jan 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved-for-actions Approved for running action pipelines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants