-
Notifications
You must be signed in to change notification settings - Fork 609
fix(query): clarify condition resolution semantics for label queries #2994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -415,8 +415,11 @@ private IdHolderList queryByLabel(ConditionQuery query) { | |
| HugeType queryType = query.resultType(); | ||
| IndexLabel il = IndexLabel.label(queryType); | ||
| validateIndexLabel(il); | ||
| Id label = query.condition(HugeKeys.LABEL); | ||
| assert label != null; | ||
| // Query-by-label builds a label index entry and requires one | ||
| // deterministically resolved label instead of best-effort fallback. | ||
| Id label = query.conditionValue(HugeKeys.LABEL); | ||
| E.checkState(label != null, "Expect one label value for query: %s", | ||
| query); | ||
|
|
||
| HugeType indexType; | ||
| SchemaLabel schemaLabel; | ||
|
|
@@ -482,7 +485,7 @@ private IdHolderList queryByUserprop(ConditionQuery query) { | |
| } | ||
| Set<MatchedIndex> indexes = this.collectMatchedIndexes(query); | ||
| if (indexes.isEmpty()) { | ||
| Id label = query.condition(HugeKeys.LABEL); | ||
| Id label = query.uniqueConditionValue(HugeKeys.LABEL); | ||
| throw noIndexException(this.graph(), query, label); | ||
| } | ||
|
|
||
|
|
@@ -756,11 +759,16 @@ private PageIds doIndexQueryOnce(IndexLabel indexLabel, | |
| @Watched(prefix = "index") | ||
| private Set<MatchedIndex> collectMatchedIndexes(ConditionQuery query) { | ||
| ISchemaTransaction schema = this.params().schemaTransaction(); | ||
| Id label = query.condition(HugeKeys.LABEL); | ||
| boolean hasLabel = query.containsCondition(HugeKeys.LABEL); | ||
| Set<Object> labels = query.conditionValues(HugeKeys.LABEL); | ||
|
|
||
| List<? extends SchemaLabel> schemaLabels; | ||
| if (label != null) { | ||
| // Query has LABEL condition | ||
| if (hasLabel && labels.isEmpty()) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Before this change, Please distinguish "LABEL EQ/IN conditions resolved to an empty intersection" from "LABEL exists but has no EQ/IN-resolvable value". The latter should keep the conservative fallback, or add regression coverage for a label |
||
| return Collections.emptySet(); | ||
| } | ||
| if (labels.size() == 1) { | ||
| Id label = (Id) labels.iterator().next(); | ||
| // Query has one resolved LABEL condition | ||
| SchemaLabel schemaLabel; | ||
| if (query.resultType().isVertex()) { | ||
| schemaLabel = schema.getVertexLabel(label); | ||
|
|
@@ -773,7 +781,8 @@ private Set<MatchedIndex> collectMatchedIndexes(ConditionQuery query) { | |
| } | ||
| schemaLabels = ImmutableList.of(schemaLabel); | ||
| } else { | ||
| // Query doesn't have LABEL condition | ||
| // Query doesn't have LABEL condition or it doesn't resolve | ||
| // to a single label, so keep the conservative fallback. | ||
| if (query.resultType().isVertex()) { | ||
| schemaLabels = schema.getVertexLabels(); | ||
| } else if (query.resultType().isEdge()) { | ||
|
|
@@ -1781,7 +1790,7 @@ protected long removeIndexLeft(ConditionQuery query, | |
| } | ||
|
|
||
| // Check label is matched | ||
| Id label = query.condition(HugeKeys.LABEL); | ||
| Id label = query.uniqueConditionValue(HugeKeys.LABEL); | ||
| // NOTE: original condition query may not have label condition, | ||
| // which means possibly label == null. | ||
| if (label != null && !element.schemaLabel().id().equals(label)) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.