apache / apache/pinot

InputFileSegmentNameGenerator raised NullPointerException when pattern contains optional group

Open Beginner friendly
#13,531 1 comment 0 reactions 0 assignees View on GitHub
bug
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.