-
Notifications
You must be signed in to change notification settings - Fork 529
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
BREAKING CHANGE(server): support "parent & child" EdgeLabel type #2662
Conversation
...ph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java
Outdated
Show resolved
Hide resolved
...ph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java
Outdated
Show resolved
Hide resolved
return this.links.stream().anyMatch(pair -> { | ||
Id sourceLabel = pair.getLeft(); | ||
Id targetLabel = pair.getRight(); | ||
if (dir.equals(Directions.IN)) { | ||
return targetLabel.equals(label); | ||
} else if (dir.equals(Directions.OUT)) { | ||
return sourceLabel.equals(label); | ||
} else if (dir.equals(Directions.BOTH)) { | ||
return targetLabel.equals(label) || sourceLabel.equals(label); | ||
} | ||
return false; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mark, see #2408
EdgeLabel label = edge.schemaLabel(); | ||
if (label.hasFather()) { | ||
for (Id id : graph().edgeLabel(label.fatherId()).indexLabels()) { | ||
this.updateIndex(id, edge, removed); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing in internal version
@@ -183,10 +185,16 @@ private static class JsonEdgeLabel implements Checkable { | |||
public long id; | |||
@JsonProperty("name") | |||
public String name; | |||
@JsonProperty("edge_label_type") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edgelabel_type or edge_label_type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep edgelabel_type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too many diffs...
...ph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java
Outdated
Show resolved
Hide resolved
This reverts commit e44aaf3.
if (query instanceof ConditionQuery && !query.paging()) { | ||
// TODO: support: paging + parent label | ||
boolean supportIn = this.storeFeatures().supportsQueryWithInCondition(); | ||
// consider multi labels + properties, see org.apache.hugegraph.core.EdgeCoreTest.testQueryInEdgesOfVertexByLabels | ||
Stream<ConditionQuery> flattenedQueries = ConditionQueryFlatten.flatten((ConditionQuery) query, supportIn).stream(); | ||
|
||
Stream<Iterator<HugeEdge>> edgeIterators = flattenedQueries.map(cq -> { | ||
Id label = cq.condition(HugeKeys.LABEL); | ||
if (this.storeFeatures().supportsFatherAndSubEdgeLabel() && | ||
label != null && | ||
graph().edgeLabel(label).isFather() && | ||
cq.condition(HugeKeys.SUB_LABEL) == null && | ||
cq.condition(HugeKeys.OWNER_VERTEX) != null && | ||
cq.condition(HugeKeys.DIRECTION) != null && | ||
matchEdgeSortKeys(cq, false, this.graph())) { | ||
// g.V("V.id").outE("parentLabel").has("sortKey","value") | ||
return parentElQueryWithSortKeys( | ||
graph().edgeLabel(label), graph().edgeLabels(), cq); | ||
} else { | ||
return queryEdgesFromBackendInternal(cq); | ||
} | ||
}); | ||
|
||
return edgeIterators.reduce(ExtendableIterator::concat).orElse(Collections.emptyIterator()); | ||
} | ||
|
||
return queryEdgesFromBackendInternal(query); | ||
} | ||
|
||
private Iterator<HugeEdge> queryEdgesFromBackendInternal(Query query) { | ||
assert query.resultType().isEdge(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBD.
because of #1737
if (cq.condition(HugeKeys.LABEL) != null && cq.resultType().isEdge()) { | ||
if (cq.conditions().size() == 1) { | ||
// g.E().hasLabel(xxx) | ||
return true; | ||
} | ||
if (cq.optimized() == OptimizedType.INDEX) { | ||
// g.E().hasLabel(xxx).has(yyy) | ||
// consider OptimizedType.INDEX_FILTER occurred in org.apache.hugegraph.core.EdgeCoreTest.testQueryCount | ||
try { | ||
this.indexTx.asyncRemoveIndexLeft(cq, elem); | ||
} catch (Throwable e) { | ||
LOG.warn("Failed to remove left index for query '{}', " + | ||
"element '{}'", cq, elem, e); | ||
} | ||
return true; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBD.
if (this.storeFeatures().supportsFatherAndSubEdgeLabel() && byLabel && query.resultType().isEdge()) { | ||
// for memory backend | ||
EdgeLabel edgeLabel = graph().edgeLabel(label); | ||
if (edgeLabel.hasFather()) { | ||
query.resetConditions(); | ||
query.eq(HugeKeys.LABEL, edgeLabel.fatherId()); | ||
query.eq(HugeKeys.SUB_LABEL, edgeLabel.id()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBD.
@VGalaxies Nice feature, can you add design documentation? |
…st#testEdgeExistenceGet" This reverts commit 81fcf27.
// fix org.apache.hugegraph.api.traverser.EdgeExistenceAPITest#testEdgeExistenceGet | ||
// add sub label if only the sub label is missing | ||
ConditionQuery finalQuery = query; | ||
if (this.storeFeatures().supportsFatherAndSubEdgeLabel() && | ||
query.condition(HugeKeys.SUB_LABEL) == null && | ||
Arrays.stream(EdgeId.KEYS) | ||
.filter(key -> !Objects.equals(key, HugeKeys.SUB_LABEL)) | ||
.allMatch(key -> finalQuery.condition(key) != null)) { | ||
EdgeLabel el = this.graph().edgeLabel(label); | ||
if (!el.isFather()) { | ||
query.eq(HugeKeys.SUB_LABEL, el.id()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBD.
Some specialized adaptations have been made for parent-child edges in existing tests, as seen in the aforementioned comments. Currently, paging + parent label queries are not supported. |
HugeGraph supports the parent-child edge feature, meaning that an Edgelabel can have a subordinate type. Using the bank transfer graph as an example, transfers may include person-to-person transfers (person-to-person), person-to-company transfers (person-to-company), and company-to-company transfers (company-to-company). These three different types of transfers share a common operation, transfer.
In actual business scenarios, it is often necessary to retrieve all transfer edges with a single query. Currently, competitors can only manually split the transfer edge types, perform multiple queries, and then aggregate the results. With HugeGraph's parent-child edge feature, it is possible to query the corresponding person-to-person transfers, person-to-company transfers, and other sub-edge types, and also conveniently and efficiently retrieve all transfer-related edges at once.
PS: The parent-child edge feature for the cassandra and scylladb backends has been temporarily disabled through the store feature.
Related to:
Design doc: https://hugegraph.feishu.cn/wiki/ZgLBwGAusiQFACkuIADcjSJtnof
Client(Toolchain) need adapter it ASAP (BREAKING CHANGE), see apache/incubator-hugegraph-toolchain#624
Test: hugegraph/hugegraph-test#17