Skip to content
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

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

VGalaxies
Copy link
Contributor

@VGalaxies VGalaxies commented Sep 8, 2024

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.

Code formatting will be done separately in the next PR.

Related to:

TODO:
Client(Toolchain) need adapter it ASAP (BREAKING CHANGE)

Copy link

codecov bot commented Sep 8, 2024

Codecov Report

Attention: Patch coverage is 59.67153% with 221 lines in your changes missing coverage. Please review.

Project coverage is 47.77%. Comparing base (a529c02) to head (14c99e2).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
...in/java/org/apache/hugegraph/schema/EdgeLabel.java 52.43% 35 Missing and 4 partials ⚠️
.../hugegraph/backend/store/AbstractBackendStore.java 0.00% 30 Missing ⚠️
...che/hugegraph/schema/builder/EdgeLabelBuilder.java 71.76% 14 Missing and 10 partials ⚠️
...ugegraph/backend/serializer/TableSerializerV2.java 62.00% 18 Missing and 1 partial ⚠️
.../org/apache/hugegraph/api/schema/EdgeLabelAPI.java 7.14% 11 Missing and 2 partials ⚠️
.../apache/hugegraph/backend/tx/GraphTransaction.java 80.59% 5 Missing and 8 partials ⚠️
.../apache/hugegraph/io/GraphSONSchemaSerializer.java 56.66% 9 Missing and 4 partials ⚠️
...he/hugegraph/backend/cache/CachedBackendStore.java 0.00% 12 Missing ⚠️
...hugegraph/backend/serializer/BinarySerializer.java 38.88% 9 Missing and 2 partials ⚠️
...gegraph/backend/store/memory/InMemoryDBTables.java 65.62% 8 Missing and 3 partials ⚠️
... and 10 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2662      +/-   ##
============================================
+ Coverage     47.60%   47.77%   +0.16%     
- Complexity      820      821       +1     
============================================
  Files           718      719       +1     
  Lines         58469    58914     +445     
  Branches       7496     7595      +99     
============================================
+ Hits          27835    28146     +311     
- Misses        27854    27954     +100     
- Partials       2780     2814      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +178 to +189
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;
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mark, see #2408

Comment on lines +183 to +188
EdgeLabel label = edge.schemaLabel();
if (label.hasFather()) {
for (Id id : graph().edgeLabel(label.fatherId()).indexLabels()) {
this.updateIndex(id, edge, removed);
}
}
Copy link
Contributor Author

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")
Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many diffs...

@VGalaxies VGalaxies marked this pull request as ready for review September 21, 2024 07:18
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. feature New feature labels Sep 21, 2024
Comment on lines +1052 to +1083
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();

Copy link
Contributor Author

@VGalaxies VGalaxies Sep 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBD.

because of #1737

Comment on lines +1898 to +1915
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;
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBD.

Comment on lines +1629 to +1637
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());
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBD.

@imbajin imbajin added this to the 1.5.0 milestone Sep 21, 2024
@javeme
Copy link
Contributor

javeme commented Sep 22, 2024

@VGalaxies Nice feature, can you add design documentation?

@imbajin imbajin changed the title feat(server): support father and sub edge label BREAKING CHANGE(server): support "parent & child" EdgeLabel type Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

3 participants