InputFileSegmentNameGenerator raised NullPointerException when pattern contains optional group
- Dominant language
- Java
- Stars
- 6.1k
- Forks
- 1.5k
- Avg merge
- 2d 55m
- Merged PRs (30d)
- 182
Description
When using segment name generator type inputFile, I found a issue that when my file.path.pattern contains an optional part, it will cause a NullPointerException.
For example, pattern is '.+/(\w+)(.parquet)?', and template is '\${filePathPattern:\1}'. Because not all my files have parquet extension, so I added an optional part in the pattern, even I didn't use the second group in template, it still get NullPointerException.
The reason is current code loop all groups and do string replacement, but the group may be null for optional group, then the replace method will raise NullPointerException.
```
for (int i = 1; i <= m.groupCount(); i++) {
segmentName = segmentName.replace(String.format(PARAMETER_TEMPLATE, i), m.group(i));
}
```
To fix it, need to check null on groups, if null, skip replacement or replace with empty string.
Contributor guide
Research direction
Start at InputFileSegmentNameGenerator and reproduce the issue with the optional-group pattern `.+/(\w+)(.parquet)?` and template `${filePathPattern:\1}`. Verify that an unmatched optional group no longer raises a NullPointerException and that the existing replacement behavior remains unchanged for matched groups.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- data
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100