javeme commented on code in PR #2295:
URL:
https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311595120
##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -85,6 +89,9 @@ public class HugeTraverser {
// Empirical value of scan limit, with which results can be returned in 3s
public static final String DEFAULT_PAGE_LIMIT = "100000";
public static final long NO_LIMIT = -1L;
+ // algorithms
Review Comment:
to be improved
##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -164,6 +171,17 @@ public static void checkSkipDegree(long skipDegree, long
degree,
}
}
+ public static void checkAlgorithm(String algorithm) {
Review Comment:
also update it
##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1574,14 +1597,14 @@ private void checkNonnullProperty(HugeVertex vertex) {
// Check whether passed all non-null property
@SuppressWarnings("unchecked")
Collection<Id> nonNullKeys = CollectionUtils.subtract(
- vertexLabel.properties(),
- vertexLabel.nullableKeys());
+ vertexLabel.properties(),
+ vertexLabel.nullableKeys());
if (!keys.containsAll(nonNullKeys)) {
@SuppressWarnings("unchecked")
Collection<Id> missed = CollectionUtils.subtract(nonNullKeys,
keys);
HugeGraph graph = this.graph();
E.checkArgument(false, "All non-null property keys %s of " +
- "vertex label '%s' must be set, missed keys %s",
+ "vertex label '%s' must be set, missed keys
%s",
Review Comment:
try this style:
```java
E.checkArgument(false,
"All non-null property keys %s of " +
"vertex label '%s' must be set, missed keys %s",
```
##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1018,9 +1211,7 @@ protected Iterator<HugeEdge> queryEdgesFromBackend(Query
query) {
if (vertex == null) {
return null;
}
- if (query.idsSize() == 1) {
- assert vertex.getEdges().size() == 1;
- }
+ assert query.idsSize() != 1 || vertex.getEdges().size() == 1;
Review Comment:
seems like you are trying to reduce the number of lines of code, I think we
prefer to keep the origin logic for more readable
##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1608,11 +1639,11 @@ private void checkVertexExistIfCustomizedId(Map<Id,
HugeVertex> vertices) {
HugeVertex newVertex = vertices.get(existedVertex.id());
if (!existedVertex.label().equals(newVertex.label())) {
throw new HugeException(
- "The newly added vertex with id:'%s' label:'%s' " +
- "is not allowed to insert, because already exist " +
- "a vertex with same id and different label:'%s'",
- newVertex.id(), newVertex.label(),
- existedVertex.label());
+ "The newly added vertex with id:'%s' label:'%s' " +
+ "is not allowed to insert, because already exist " +
+ "a vertex with same id and different label:'%s'",
+ newVertex.id(), newVertex.label(),
+ existedVertex.label());
Review Comment:
ditto
##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -171,6 +171,199 @@ public GraphTransaction(HugeGraphParams graph,
BackendStore store) {
this.edgesCapacity);
}
+ /**
+ * Construct one edge condition query based on source vertex, direction and
+ * edge labels
+ *
+ * @param sourceVertex source vertex of edge
+ * @param direction only be "IN", "OUT" or "BOTH"
+ * @param edgeLabels edge labels of queried edges
+ * @return constructed condition query
+ */
+ @Watched
+ public static ConditionQuery constructEdgesQuery(Id sourceVertex,
+ Directions direction,
+ Id... edgeLabels) {
+ E.checkState(sourceVertex != null,
+ "The edge query must contain source vertex");
+ E.checkState(direction != null,
+ "The edge query must contain direction");
+
+ ConditionQuery query = new ConditionQuery(HugeType.EDGE);
+
+ // Edge source vertex
+ query.eq(HugeKeys.OWNER_VERTEX, sourceVertex);
+
+ // Edge direction
+ if (direction == Directions.BOTH) {
+ query.query(Condition.or(
+ Condition.eq(HugeKeys.DIRECTION, Directions.OUT),
+ Condition.eq(HugeKeys.DIRECTION, Directions.IN)));
+ } else {
+ assert direction == Directions.OUT || direction == Directions.IN;
+ query.eq(HugeKeys.DIRECTION, direction);
+ }
+
+ // Edge labels
+ if (edgeLabels.length == 1) {
+ query.eq(HugeKeys.LABEL, edgeLabels[0]);
+ } else if (edgeLabels.length > 1) {
+ query.query(Condition.in(HugeKeys.LABEL,
+ Arrays.asList(edgeLabels)));
+ }
+
+ return query;
+ }
+
+ public static ConditionQuery constructEdgesQuery(Id sourceVertex,
+ Directions direction,
+ List<Id> edgeLabels) {
+ E.checkState(sourceVertex != null,
+ "The edge query must contain source vertex");
+ E.checkState(direction != null,
+ "The edge query must contain direction");
+
+ ConditionQuery query = new ConditionQuery(HugeType.EDGE);
+
+ // Edge source vertex
+ query.eq(HugeKeys.OWNER_VERTEX, sourceVertex);
+
+ // Edge direction
+ if (direction == Directions.BOTH) {
+ query.query(Condition.or(
+ Condition.eq(HugeKeys.DIRECTION, Directions.OUT),
+ Condition.eq(HugeKeys.DIRECTION, Directions.IN)));
+ } else {
+ assert direction == Directions.OUT || direction == Directions.IN;
+ query.eq(HugeKeys.DIRECTION, direction);
+ }
+
+ // Edge labels
+ if (edgeLabels.size() == 1) {
+ query.eq(HugeKeys.LABEL, edgeLabels.get(0));
+ } else if (edgeLabels.size() > 1) {
+ query.query(Condition.in(HugeKeys.LABEL, edgeLabels));
+ }
+
+ return query;
+ }
+
+ public static boolean matchFullEdgeSortKeys(ConditionQuery query,
+ HugeGraph graph) {
+ // All queryKeys in sortKeys
+ return matchEdgeSortKeys(query, true, graph);
+ }
+
+ public static boolean matchPartialEdgeSortKeys(ConditionQuery query,
+ HugeGraph graph) {
+ // Partial queryKeys in sortKeys
+ return matchEdgeSortKeys(query, false, graph);
+ }
+
+ private static boolean matchEdgeSortKeys(ConditionQuery query,
+ boolean matchAll,
+ HugeGraph graph) {
+ assert query.resultType().isEdge();
+ Id label = query.condition(HugeKeys.LABEL);
+ if (label == null) {
+ return false;
+ }
+ List<Id> sortKeys = graph.edgeLabel(label).sortKeys();
+ if (sortKeys.isEmpty()) {
+ return false;
+ }
+ Set<Id> queryKeys = query.userpropKeys();
+ for (int i = sortKeys.size(); i > 0; i--) {
+ List<Id> subFields = sortKeys.subList(0, i);
+ if (queryKeys.containsAll(subFields)) {
+ if (queryKeys.size() == subFields.size() || !matchAll) {
+ /*
+ * Return true if:
+ * matchAll=true and all queryKeys are in sortKeys
+ * or
+ * partial queryKeys are in sortKeys
+ */
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static void verifyVerticesConditionQuery(ConditionQuery query) {
+ assert query.resultType().isVertex();
+
+ int total = query.conditionsSize();
+ if (total == 1) {
+ /*
+ * Supported query:
+ * 1.query just by vertex label
+ * 2.query just by PROPERTIES (like containsKey,containsValue)
+ * 3.query with scan
+ */
+ if (query.containsCondition(HugeKeys.LABEL) ||
+ query.containsCondition(HugeKeys.PROPERTIES) ||
+ query.containsScanRelation()) {
+ return;
+ }
+ }
+
+ int matched = 0;
+ if (query.containsCondition(HugeKeys.PROPERTIES)) {
+ matched++;
+ if (query.containsCondition(HugeKeys.LABEL)) {
+ matched++;
+ }
+ }
+
+ if (matched != total) {
+ throw new HugeException("Not supported querying vertices by %s",
+ query.conditions());
+ }
+ }
+
+ private static void verifyEdgesConditionQuery(ConditionQuery query) {
+ assert query.resultType().isEdge();
+
+ int total = query.conditionsSize();
+ if (total == 1) {
+ /*
+ * Supported query:
+ * 1.query just by edge label
+ * 2.query just by PROPERTIES (like containsKey,containsValue)
+ * 3.query with scan
+ */
+ if (query.containsCondition(HugeKeys.LABEL) ||
+ query.containsCondition(HugeKeys.PROPERTIES) ||
+ query.containsScanRelation()) {
+ return;
+ }
+ }
+
+ int matched = 0;
+ for (HugeKeys key : EdgeId.KEYS) {
+ Object value = query.condition(key);
+ if (value == null) {
+ break;
+ }
+ matched++;
+ }
+ int count = matched;
+
+ if (query.containsCondition(HugeKeys.PROPERTIES)) {
+ matched++;
+ if (count < 3 && query.containsCondition(HugeKeys.LABEL)) {
+ matched++;
+ }
+ }
+
+ if (matched != total) {
+ throw new HugeException(
+ "Not supported querying edges by %s, expect %s",
+ query.conditions(), EdgeId.KEYS[count]);
+ }
+ }
+
Review Comment:
move to line 1385?
##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java:
##########
@@ -310,9 +311,9 @@ public static void extractAggregateFunc(Step<?, ?> newStep,
}
public static ConditionQuery fillConditionQuery(
- ConditionQuery query,
- List<HasContainer> hasContainers,
- HugeGraph graph) {
+ ConditionQuery query,
+ List<HasContainer> hasContainers,
+ HugeGraph graph) {
Review Comment:
can we revert the style changes in all files.
##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -85,6 +89,9 @@ public class HugeTraverser {
// Empirical value of scan limit, with which results can be returned in 3s
public static final String DEFAULT_PAGE_LIMIT = "100000";
public static final long NO_LIMIT = -1L;
+ // algorithms
+ public static final String ALGORITHM_BFS = "breadth_first_search";
Review Comment:
prefer TRAVERSE_MODE_BFS
##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/KoutTraverser.java:
##########
@@ -138,6 +138,38 @@ public KoutRecords customizedKout(Id source, EdgeStep step,
return records;
}
+ public KoutRecords DFSKout(Id source, Steps steps,
+ int maxDepth, boolean nearest,
+ long capacity, long limit) {
+ E.checkNotNull(source, "source vertex id");
+ this.checkVertexExist(source, "source vertex");
+ checkPositive(maxDepth, "k-out max_depth");
Review Comment:
not addressed
##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1753,7 +1784,7 @@ private boolean rightResultFromIndexQuery(Query query,
HugeElement elem) {
}
private <T extends HugeElement> Iterator<T> filterExpiredResultFromBackend(
- Query query, Iterator<T> results) {
+ Query query, Iterator<T> results) {
Review Comment:
ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]