VGalaxies commented on code in PR #624: URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/624#discussion_r1793688915
########## hugegraph-client/src/main/java/org/apache/hugegraph/structure/constant/EdgeLabelType.java: ########## @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package org.apache.hugegraph.structure.constant; + +public enum EdgeLabelType { + + NORMAL(0, "NORMAL"), + + PARENT(1, "PARENT"), + + SUB(2, "SUB"), + + GENERAL(3, "GENERAL"), Review Comment: the general edge label has not yet been introduced ########## hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java: ########## @@ -60,21 +68,59 @@ public String type() { return HugeType.EDGE_LABEL.string(); } + public boolean parent() { + return this.edgeLabelType.parent(); + } + + public boolean sub() { + return this.edgeLabelType.sub(); + } + + public String parentLabel(){ + return this.parentLabel; + } + + public EdgeLabelType edgeLabelType(){ + return this.edgeLabelType; + } + public Frequency frequency() { return this.frequency; } public String sourceLabel() { - return this.sourceLabel; + E.checkState(this.links.size() == 1, + "Only edge label has single vertex label pair can call " + + "sourceLabelName(), but current edge label got %s", + this.links.size()); + return this.links.iterator().next().keySet().iterator().next(); } public String targetLabel() { - return this.targetLabel; + E.checkState(this.links.size() == 1, + "Only edge label has single vertex label pair can call " + + "targetLabelName(), but current edge label got %s", + this.links.size()); + return this.links.iterator().next().values().iterator().next(); + } + + public Set<Map<String, String>> links() { + return this.links; } public boolean linkedVertexLabel(String vertexLabel) { - return this.sourceLabel.equals(vertexLabel) || - this.targetLabel.equals(vertexLabel); + if (this.edgeLabelType.parent() || this.links == null || this.links.isEmpty()) { + return false; + } + + for (Map<String, String> pair : this.links) { + for(String str : pair.keySet()){ Review Comment: format the code plz ########## hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java: ########## @@ -197,20 +255,65 @@ public Builder nullableKeys(String... keys) { @Override public Builder link(String sourceLabel, String targetLabel) { - this.edgeLabel.sourceLabel = sourceLabel; - this.edgeLabel.targetLabel = targetLabel; + HashMap<String, String> map = new HashMap<>(); + map.put(sourceLabel, targetLabel); + this.edgeLabel.links.add(map); + this.sourceLabel = null; + this.targetLabel = null; + return this; + } + + @Override + public Builder asBase() { + this.edgeLabel.edgeLabelType = EdgeLabelType.PARENT; + return this; + } + + @Override + public Builder withBase(String parentLabel) { + this.edgeLabel.edgeLabelType = EdgeLabelType.SUB; + this.edgeLabel.parentLabel = parentLabel; return this; } + @Override + public Builder asGeneral() { + this.edgeLabel.edgeLabelType = EdgeLabelType.GENERAL; + return this; + } + + + /** + * Set the source label of the edge label + * @deprecated + * Suggested use {@link #link(String, String)} to set the source and target label pair + */ + @Deprecated @Override public Builder sourceLabel(String label) { - this.edgeLabel.sourceLabel = label; + E.checkArgument(this.edgeLabel.links.isEmpty(), + "Not allowed add source label to an edge label which " + + "already has links"); + this.sourceLabel = label; Review Comment: refer to [apache/incubator-hugegraph@`87e76ff` (#2662)](https://github.com/apache/incubator-hugegraph/pull/2662/commits/87e76fff96573e2921bf5de19c0d4de550282f61) for modifications ########## hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java: ########## @@ -197,20 +255,65 @@ public Builder nullableKeys(String... keys) { @Override public Builder link(String sourceLabel, String targetLabel) { - this.edgeLabel.sourceLabel = sourceLabel; - this.edgeLabel.targetLabel = targetLabel; + HashMap<String, String> map = new HashMap<>(); + map.put(sourceLabel, targetLabel); + this.edgeLabel.links.add(map); + this.sourceLabel = null; + this.targetLabel = null; + return this; + } + + @Override + public Builder asBase() { + this.edgeLabel.edgeLabelType = EdgeLabelType.PARENT; + return this; + } + + @Override + public Builder withBase(String parentLabel) { + this.edgeLabel.edgeLabelType = EdgeLabelType.SUB; + this.edgeLabel.parentLabel = parentLabel; return this; } + @Override + public Builder asGeneral() { + this.edgeLabel.edgeLabelType = EdgeLabelType.GENERAL; + return this; + } + + + /** + * Set the source label of the edge label + * @deprecated + * Suggested use {@link #link(String, String)} to set the source and target label pair + */ + @Deprecated @Override public Builder sourceLabel(String label) { - this.edgeLabel.sourceLabel = label; + E.checkArgument(this.edgeLabel.links.isEmpty(), + "Not allowed add source label to an edge label which " + + "already has links"); + this.sourceLabel = label; return this; } + /** + * Set the target label of the edge label + * @deprecated + * Suggested use {@link #link(String, String)} to set the source and target label pair + */ + @Deprecated @Override public Builder targetLabel(String label) { - this.edgeLabel.targetLabel = label; + E.checkArgument(this.edgeLabel.links.isEmpty(), + "Not allowed add source label to an edge label which " + + "already has links"); + E.checkArgument(this.sourceLabel != null, + "Not allowed add target label to an edge label which " + + "not has source label yet"); + this.targetLabel = label; 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]
