Repository navigation
fix(#4287): split comma/pipe-separated relTypes string in extractRelTypes - #4360
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Coverage variation | ✅ -7.84% coverage variation |
| Diff coverage | ✅ 45.83% diff coverage |
Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (f2a41f8) 127753 94277 73.80% Head commit (1bfcf30) 159446 (+31693) 105165 (+10888) 65.96% (-7.84%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>
Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#4360) 24 11 45.83% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where passing comma- or pipe-separated relationship types to algorithm and path procedures (such as algo.leiden()) incorrectly treated the entire string as a single type, resulting in singleton communities. The changes split the input string on commas and pipes and trim the individual tokens. The review feedback points out an inconsistency where single relationship types are not trimmed, whereas split types are. It also highlights that if the input string contains only delimiters or spaces, the methods might return empty arrays instead of null consistently.
| private static String[] splitRelTypeString(final String s) { | ||
| if (s.isEmpty()) | ||
| return null; | ||
| if (!s.contains(",") && !s.contains("|")) | ||
| return new String[]{s}; | ||
| final List<String> types = new ArrayList<>(); | ||
| for (final String part : s.split("[,|]")) { | ||
| final String trimmed = part.trim(); | ||
| if (!trimmed.isEmpty()) | ||
| types.add(trimmed); | ||
| } | ||
| return types.isEmpty() ? null : types.toArray(new String[0]); | ||
| } |
There was a problem hiding this comment.
There is an inconsistency in how single vs. multiple relationship types are handled regarding whitespace. If a single relationship type with leading/trailing spaces is passed (e.g., " TYPE_A "), it is returned untrimmed because it doesn't contain , or |. However, if multiple types are passed (e.g., "TYPE_A, TYPE_B"), they are trimmed. To ensure consistent behavior and prevent potential matching issues due to accidental whitespace, we should trim the input string first.
| private static String[] splitRelTypeString(final String s) { | |
| if (s.isEmpty()) | |
| return null; | |
| if (!s.contains(",") && !s.contains("|")) | |
| return new String[]{s}; | |
| final List<String> types = new ArrayList<>(); | |
| for (final String part : s.split("[,|]")) { | |
| final String trimmed = part.trim(); | |
| if (!trimmed.isEmpty()) | |
| types.add(trimmed); | |
| } | |
| return types.isEmpty() ? null : types.toArray(new String[0]); | |
| } | |
| private static String[] splitRelTypeString(final String s) { | |
| final String trimmedSource = s.trim(); | |
| if (trimmedSource.isEmpty()) | |
| return null; | |
| if (!trimmedSource.contains(",") && !trimmedSource.contains("|")) | |
| return new String[]{trimmedSource}; | |
| final List<String> types = new ArrayList<>(); | |
| for (final String part : trimmedSource.split("[,|]")) { | |
| final String trimmed = part.trim(); | |
| if (!trimmed.isEmpty()) | |
| types.add(trimmed); | |
| } | |
| return types.isEmpty() ? null : types.toArray(new String[0]); | |
| } |
| if (s.isEmpty()) | ||
| return null; | ||
|
|
||
| // Handle pipe-separated format "REL1|REL2|REL3" | ||
| if (s.contains("|")) | ||
| return s.split("\\|"); | ||
| // Handle pipe- or comma-separated format "REL1|REL2" or "REL1,REL2" | ||
| if (s.contains("|") || s.contains(",")) | ||
| return Arrays.stream(s.split("[,|]")).map(String::trim).filter(t -> !t.isEmpty()).toArray(String[]::new); | ||
|
|
||
| return new String[]{s}; | ||
| } |
There was a problem hiding this comment.
Similar to AbstractAlgoProcedure, there is an inconsistency where single relationship types are not trimmed, while split types are. Additionally, if the input string contains only delimiters/spaces (e.g., ","), this method returns an empty array String[0] instead of null, which is inconsistent with how empty strings are handled. Trimming the source string first and returning null if no valid types are found resolves both issues.
final String trimmedSource = s.trim();
if (trimmedSource.isEmpty())
return null;
// Handle pipe- or comma-separated format "REL1|REL2" or "REL1,REL2"
if (trimmedSource.contains("|") || trimmedSource.contains(",")) {
final String[] types = Arrays.stream(trimmedSource.split("[,|]")).map(String::trim).filter(t -> !t.isEmpty()).toArray(String[]::new);
return types.length == 0 ? null : types;
}
return new String[]{trimmedSource};
Code ReviewOverviewThis PR fixes a real bug: Issues1. Spurious documentation file ( This file is an implementation planning/debugging document and should not be committed to the repository. It duplicates information already in the PR description and git history, and will rot quickly as the codebase evolves. Please drop it from the PR. 2. Code duplication between the two base classes
3. Inconsistent trimming in When the string contains no delimiter, the fast-path returns the original string verbatim: if (!s.contains(",") && !s.contains("|"))
return new String[]{s}; // no trim hereBut when a delimiter is present, each token is trimmed. So 4. Test method comments reference the fix Per project conventions, comments should not reference the current task or pre-fix behaviour. Lines like: // Without the fix, the whole string is treated as one non-existent type so
// every node appears isolated (all singleton communities).describe what used to happen rather than a non-obvious invariant. Please remove them. 5. Duplicated test methods - consider
Minor NitIn SummaryThe bug fix itself is correct and the approach is clean. The main things to address before merging: drop the documentation file, fix the no-delimiter trim inconsistency, and clean up the test comments. |
Code ReviewOverviewThis PR fixes a real bug (#4287): IssuesCritical1. This file is Claude Code's internal working notes (review cycles, commit SHAs, gemini reviewer status). It is not project documentation and should be removed from the PR before merging. Per CLAUDE.md: "do not create planning, decision, or analysis documents unless the user asks for them." Medium2.
3. No regression tests for The path procedures ( Minor / Style4. Duplicated split logic in two base classes
5. Style inconsistency between the two implementations
for (final String part : trimmedSource.split("[,|]")) {
final String trimmed = part.trim();
if (!trimmed.isEmpty())
types.add(trimmed);
}
return types.isEmpty() ? null : types.toArray(new String[0]);While final String[] types = Arrays.stream(trimmedSource.split("[,|]"))
.map(String::trim).filter(t -> !t.isEmpty()).toArray(String[]::new);
return types.length == 0 ? null : types;The stream form in 6. Line length in The project's Prettier config uses 7. Test method comments reference the bug fix context Per CLAUDE.md: "Don't reference the current task, fix, or callers - those belong in the PR description and rot as the codebase evolves." The block comments 8. Near-duplicate test methods are candidates for
SummaryThe fix itself is correct. The two blocking items before merge are: (1) remove the docs file, and (2) either fix |
|
test |
Code ReviewSummary: This PR correctly identifies and fixes a real bug - What works well
Issues and suggestions1. Redundant delimiter pre-check in The guard below is unnecessary: if (!trimmedSource.contains(",") && !trimmedSource.contains("|"))
return new String[]{trimmedSource};
2. Inconsistent style between the two fixed methods (minor)
3. Duplicated split logic across two base classes (suggestion) Both classes now independently implement the same comma/pipe-split-and-trim pattern. This is acceptable for a targeted bug fix, but if a third caller ever needs it a shared utility (e.g., a package-private 4. Overly verbose test comments (style, per CLAUDE.md) The comment blocks inside the two new test methods explain what happens "without the fix." CLAUDE.md asks for comments only when the WHY is non-obvious. The test names already communicate intent ( Overall assessmentThe fix is correct, the tests cover both separator styles, and there are no security or performance regressions introduced. The items above are all minor style and simplification points - none of them block merging. The most actionable one is removing the redundant delimiter pre-check in |
… test, remove tracking doc
Code ReviewOverviewThis PR correctly identifies and fixes a real bug: CorrectnessThe core fix is correct. The regex Consistency gap - Trim behavior on old pipe split: The pre-existing code in Code QualityStyle inconsistency between the two classes: Duplicated splitting logic: Minor - Test CoverageGood:
Gaps to consider:
Summary
The fix itself is solid and the main regression test covers the reported issue well. The suggestions above are mostly polish - the duplication point is the most worth addressing before merge to avoid the two implementations drifting apart in the future. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4360 +/- ##
============================================
- Coverage 64.65% 64.27% -0.39%
- Complexity 423 424 +1
============================================
Files 1647 1647
Lines 127753 127768 +15
Branches 27382 27389 +7
============================================
- Hits 82599 82120 -479
- Misses 33507 34103 +596
+ Partials 11647 11545 -102 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Closes #4287
Summary
algo.leiden("TYPE_A,TYPE_B")and all otheralgo.*procedures returned singletoncommunities for every node when a comma- or pipe-separated
relTypesstring was passed.The root cause was in
AbstractAlgoProcedure.extractRelTypes(), which wrapped the entirestring as a single array element instead of splitting it:
Because no edge type named
"TYPE_A,TYPE_B"exists, the graph appeared to have no edges,so each node was placed in its own community.
The fix adds a
splitRelTypeString()helper that splits on,or|, trims whitespacefrom each token, and drops empty tokens. A second fix extends
AbstractPathProcedure.extractRelTypes()to also handle comma separators (it previouslyhandled only
|).Both changes are single-method fixes in the two base classes; all derived procedures
(
AlgoLouvain,AlgoSCC,AlgoWCC,PathExpand,PathSubgraphAll, etc.) inherit thecorrected behaviour automatically.
Test plan
AlgoLeidenTest.leidenWithCommaRelTypesYieldsMultiNodeCommunities— callsalgo.leiden('KNOWS,NONEXISTENT')on the standard 6-node / 2-community test graph andasserts that at least two nodes share a community (proving KNOWS edges were matched after
the split).
AlgoLeidenTest.leidenWithPipeRelTypesYieldsMultiNodeCommunities— same with'KNOWS|NONEXISTENT'.AlgoLeidenTesttests pass.Algo*Testtests pass.🤖 Generated with Claude Code