fix: pattern_match TVF crashes and parameter validation#17471
Open
linxt20 wants to merge 4 commits intoapache:masterfrom
Open
fix: pattern_match TVF crashes and parameter validation#17471linxt20 wants to merge 4 commits intoapache:masterfrom
linxt20 wants to merge 4 commits intoapache:masterfrom
Conversation
- Fix NaN from 0/0 in localHeightRatio when both data and pattern sections are flat (smooth=0): return 1.0 as perfect match - Fix NaN guard: treat NaN matchValue as exceeding threshold - Fix shapeError normalization 0/0 when data range and smooth are both zero: return 0 (no shape error) - Add validation: reject negative smooth and threshold parameters with descriptive error messages - Add IT tests for flat pattern, negative smooth, negative threshold
The previous ternary logic had two bugs: 1. The final else branch assigned (patternMaxHeight - patternMinHeight) which is an absolute range, not the intended ratio. 2. The middle condition checked if (dataRange / patternRange) == 0, but when patternRange is 0, Java double division yields Infinity, not 0, so the guard never triggered. Fix: check divisor/dividend for zero first, fallback to smoothValue, otherwise compute the correct ratio dataRange / patternRange.
Pattern '1,1,1,1,1,2,3,4,3' (flat->up->down) cannot match any data segment (up->down->flat), so expected result should be empty.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
pattern_matchTVF handling of edge cases:NaN crash — When both data and pattern sections are flat with
smooth=0, division0/0producedNaN, bypassing all branch conditions and hittingIndexOutOfBoundsExceptionon an emptynextSectionList. Fixed by returning1.0(perfect match) for flat-to-flat ratio, and adding aNaNguard.ShapeError normalization — Same
0/0scenario inshapeError / (heightNorm * pointCount)when height range and smooth are both zero. Fixed by returning0.Negative parameter validation —
smoothandthresholdaccepted negative values silently. Added validation inanalyze()to reject with descriptive errors.All fixes applied to both
MatchStateandRegexMatchState. IT tests added for each case.