fix(query): handle conflicting edge label conditions safely#2990
Open
contrueCT wants to merge 3 commits intoapache:masterfrom
Open
fix(query): handle conflicting edge label conditions safely#2990contrueCT wants to merge 3 commits intoapache:masterfrom
contrueCT wants to merge 3 commits intoapache:masterfrom
Conversation
HugeGraph may read LABEL from a ConditionQuery before the query is flattened when optimizing edge traversals. In contradictory label combinations such as inE('created').hasLabel('created', 'look').hasLabel('authored'), the previous intersection logic reused an empty set to mean both 'not initialized yet' and 'already intersected to empty'. That allowed later IN conditions to repopulate the candidate set and raised an Illegal key 'LABEL' with more than one value error instead of returning an empty result.
Track whether the intersection has been initialized independently so an empty intersection remains empty. This keeps the existing protection for true multi-value results, while allowing conflicting label predicates to fall back safely and produce no matches.
Add regression coverage for the low-level ConditionQuery behavior and for the edge traversal scenario from issue apache#2933, including a match()-based equivalent query to assert consistent zero-count results.
Replace the match() control query in EdgeCoreTest with a direct inE() traversal instead of repeat(...).times(1). The revised form keeps the regression focused on comparing the direct traversal with an equivalent match()-based query while avoiding the generic mismatch that prevented the test from compiling.
Add a low-level regression test for ConditionQuery.condition(HugeKeys.LABEL) when multiple IN predicates intersect to more than one candidate label. This locks in the existing Illegal key 'LABEL' guard so the apache#2933 fix only changes the empty-intersection case and does not silently relax true multi-value results.
Member
|
当前修复我认为是合理的。 1. 当前问题这次问题的根因比较明确: 这会导致空交集在后续遇到 这次通过额外状态位把“未初始化”和“已为空”区分开,能够直接修正这条错误链路,而且改动范围比较小,不会在这个 bugfix 里额外引入太多变量。从修复当前 issue 的角度看,这个方案是合适的。 如果你希望进一步提升这段代码的可维护性,也可以考虑用更直观的状态表达方式,例如把“尚未初始化”直接编码到变量本身: Set<Object> intersectValues = null;
if (intersectValues == null) {
intersectValues = InsertionOrderUtil.newSet();
intersectValues.addAll(valueAsList);
} else {
CollectionUtil.intersectWithModify(intersectValues, valueAsList);
}这样是否比 2.
|
Contributor
Author
|
@imbajin |
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.
Purpose of the PR
HugeGraph may read
LABELfromConditionQuerybefore the query is flattened when optimizing edge traversals. For contradictory label conditions such as:the previous intersection logic used an empty set to mean both "not initialized yet" and "already intersected to empty". As a result, a later IN condition could repopulate the candidate labels and trigger:
Illegal key 'LABEL' with more than one value
instead of returning an empty result.
Main Changes
Update ConditionQuery.condition(Object key) to track whether the intersection has been initialized independently.
This keeps an empty intersection empty, so conflicting label predicates now fall back safely and produce no matches, while the existing protection for true multi-value results is preserved.
Verifying these changes
Added regression coverage for both the low-level query behavior and the traversal scenario from the issue:
QueryTest#testConditionWithEqAndIn
QueryTest#testConditionWithConflictingEqAndIn
EdgeCoreTest#testQueryInEdgesOfVertexByConflictingLabels
The edge traversal test also compares the direct traversal with an equivalent match()-based query and verifies that both return 0 instead of throwing an exception.
Does this PR potentially affect the following parts?
Documentation Status
Doc - TODODoc - DoneDoc - No Need