Skip to content

fix: pattern_match TVF crashes and parameter validation#17471

Open
linxt20 wants to merge 4 commits intoapache:masterfrom
linxt20:fix/shape_pattern
Open

fix: pattern_match TVF crashes and parameter validation#17471
linxt20 wants to merge 4 commits intoapache:masterfrom
linxt20:fix/shape_pattern

Conversation

@linxt20
Copy link
Copy Markdown
Contributor

@linxt20 linxt20 commented Apr 14, 2026

Fix pattern_match TVF handling of edge cases:

  1. NaN crash — When both data and pattern sections are flat with smooth=0, division 0/0 produced NaN, bypassing all branch conditions and hitting IndexOutOfBoundsException on an empty nextSectionList. Fixed by returning 1.0 (perfect match) for flat-to-flat ratio, and adding a NaN guard.

  2. ShapeError normalization — Same 0/0 scenario in shapeError / (heightNorm * pointCount) when height range and smooth are both zero. Fixed by returning 0.

  3. Negative parameter validationsmooth and threshold accepted negative values silently. Added validation in analyze() to reject with descriptive errors.

All fixes applied to both MatchState and RegexMatchState. IT tests added for each case.

linxt20 added 4 commits April 14, 2026 15:19
- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant