This is an automated email from the ASF dual-hosted git repository.

jin pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-hugegraph-toolchain.git


The following commit(s) were added to refs/heads/master by this push:
     new c672e356 chore(client): patch for father sub edge (#654)
c672e356 is described below

commit c672e356be717b8db810d264b289b40e9c6e1343
Author: John <thesp...@qq.com>
AuthorDate: Thu Feb 20 18:58:15 2025 +0800

    chore(client): patch for father sub edge (#654)
    
    
    
    ---------
    
    Co-authored-by: imbajin <j...@apache.org>
    Co-authored-by: VGalaxies <dyc1904821...@gmail.com>
---
 .../structure/constant/EdgeLabelType.java          | 12 ++++++--
 .../hugegraph/structure/schema/EdgeLabel.java      | 16 ++++++++++
 .../hugegraph/structure/schema/VertexLabel.java    |  8 +++++
 .../org/apache/hugegraph/api/EdgeLabelApiTest.java | 35 ++++++++++++++++++++++
 .../hugegraph/loader/builder/EdgeBuilder.java      | 16 ++++++++--
 5 files changed, 81 insertions(+), 6 deletions(-)

diff --git 
a/hugegraph-client/src/main/java/org/apache/hugegraph/structure/constant/EdgeLabelType.java
 
b/hugegraph-client/src/main/java/org/apache/hugegraph/structure/constant/EdgeLabelType.java
index befc7cf8..fb16edc2 100644
--- 
a/hugegraph-client/src/main/java/org/apache/hugegraph/structure/constant/EdgeLabelType.java
+++ 
b/hugegraph-client/src/main/java/org/apache/hugegraph/structure/constant/EdgeLabelType.java
@@ -23,10 +23,12 @@ public enum EdgeLabelType {
 
     PARENT(1, "PARENT"),
 
-    SUB(2, "SUB");
+    SUB(2, "SUB"),
 
-    private final byte code;
-    private final String name;
+    GENERAL(3, "GENERAL");
+
+    private byte code = 0;
+    private String name = null;
 
     EdgeLabelType(int code, String name) {
         assert code < 256;
@@ -46,6 +48,10 @@ public enum EdgeLabelType {
         return this == NORMAL;
     }
 
+    public boolean general() {
+        return this == GENERAL;
+    }
+
     public byte code() {
         return this.code;
     }
diff --git 
a/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java
 
b/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java
index 1ef60037..820a60e0 100644
--- 
a/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java
+++ 
b/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java
@@ -81,6 +81,14 @@ public class EdgeLabel extends SchemaLabel {
         return this.edgeLabelType.sub();
     }
 
+    public boolean normal() {
+        return this.edgeLabelType.normal();
+    }
+
+    public boolean general() {
+        return this.edgeLabelType.general();
+    }
+
     public String parentLabel() {
         return this.parentLabel;
     }
@@ -170,6 +178,8 @@ public class EdgeLabel extends SchemaLabel {
 
         Builder withBase(String fatherLabel);
 
+        Builder asGeneral();
+
         /**
          * Set the source label of the edge label
          */
@@ -277,6 +287,12 @@ public class EdgeLabel extends SchemaLabel {
             return this;
         }
 
+        @Override
+        public Builder asGeneral() {
+            this.edgeLabel.edgeLabelType = EdgeLabelType.GENERAL;
+            return this;
+        }
+
         /**
          * Set the source label of the edge label
          */
diff --git 
a/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/VertexLabel.java
 
b/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/VertexLabel.java
index 6a9f47ce..6581062e 100644
--- 
a/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/VertexLabel.java
+++ 
b/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/VertexLabel.java
@@ -59,10 +59,18 @@ public class VertexLabel extends SchemaLabel {
         return this.idStrategy;
     }
 
+    public void idStrategy(IdStrategy idStrategy) {
+        this.idStrategy = idStrategy;
+    }
+
     public List<String> primaryKeys() {
         return this.primaryKeys;
     }
 
+    public void primaryKeys(List<String> primaryKeys) {
+        this.primaryKeys = primaryKeys;
+    }
+
     public long ttl() {
         return this.ttl;
     }
diff --git 
a/hugegraph-client/src/test/java/org/apache/hugegraph/api/EdgeLabelApiTest.java 
b/hugegraph-client/src/test/java/org/apache/hugegraph/api/EdgeLabelApiTest.java
index 84a27f5c..68e6fe71 100644
--- 
a/hugegraph-client/src/test/java/org/apache/hugegraph/api/EdgeLabelApiTest.java
+++ 
b/hugegraph-client/src/test/java/org/apache/hugegraph/api/EdgeLabelApiTest.java
@@ -543,4 +543,39 @@ public class EdgeLabelApiTest extends BaseApiTest {
         createTime = DateUtil.parse(time);
         Utils.assertBeforeNow(createTime);
     }
+
+    @Test
+    public void testEdgeLabelType() {
+        EdgeLabel normalEdgeLabel = schema().edgeLabel("created")
+                                      .sourceLabel("person")
+                                      .targetLabel("software")
+                                      .singleTime()
+                                      .properties("date", "city")
+                                      .build();
+        Assert.assertTrue(normalEdgeLabel.normal());
+
+        EdgeLabel parentEdgeLabelType = schema().edgeLabel("write")
+                                  .link("person", "book")
+                                  .properties("date", "weight")
+                                  .singleTime()
+                                  .asBase()
+                                  .build();
+        Assert.assertTrue(parentEdgeLabelType.parent());
+
+        EdgeLabel subEdgeLabelType = schema().edgeLabel("knows")
+                                  .sourceLabel("person")
+                                  .targetLabel("person")
+                                  .singleTime()
+                                  .properties("date")
+                                  .withBase("write")
+                                  .build();
+        Assert.assertTrue(subEdgeLabelType.sub());
+
+        EdgeLabel generalEdgeLabelType = schema().edgeLabel("father")
+                                   .link("person", "person")
+                                   .properties("weight")
+                                   .asGeneral()
+                                   .build();
+        Assert.assertTrue(generalEdgeLabelType.general());
+    }
 }
diff --git 
a/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/builder/EdgeBuilder.java
 
b/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/builder/EdgeBuilder.java
index 72382366..2df3431a 100644
--- 
a/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/builder/EdgeBuilder.java
+++ 
b/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/builder/EdgeBuilder.java
@@ -28,6 +28,7 @@ import java.util.Set;
 import org.apache.hugegraph.loader.executor.LoadContext;
 import org.apache.hugegraph.loader.mapping.EdgeMapping;
 import org.apache.hugegraph.loader.mapping.InputStruct;
+import org.apache.hugegraph.structure.constant.IdStrategy;
 import org.apache.hugegraph.structure.graph.Edge;
 import org.apache.hugegraph.structure.graph.Vertex;
 import org.apache.hugegraph.structure.schema.EdgeLabel;
@@ -55,10 +56,19 @@ public class EdgeBuilder extends ElementBuilder<Edge> {
         super(context, struct);
         this.mapping = mapping;
         this.edgeLabel = this.getEdgeLabel(this.mapping.label());
-        this.sourceLabel = this.getVertexLabel(this.edgeLabel.sourceLabel());
-        this.targetLabel = this.getVertexLabel(this.edgeLabel.targetLabel());
         this.nonNullKeys = this.nonNullableKeys(this.edgeLabel);
-        // Ensure that the source/target id fields are matched with id strategy
+        if (this.edgeLabel.edgeLabelType().general()) {
+            // If create a general type edge, the loader can't obtain the 
vertexlabel info of both ends
+            // Therefore, the IdStrategy of both ends is uniformly set to 
CUSTOMIZE_STRING
+            this.sourceLabel = new VertexLabel("~general");
+            this.targetLabel = new VertexLabel("~general");
+            this.sourceLabel.idStrategy(IdStrategy.CUSTOMIZE_STRING);
+            this.targetLabel.idStrategy(IdStrategy.CUSTOMIZE_STRING);
+        } else {
+            this.sourceLabel = 
this.getVertexLabel(this.edgeLabel.sourceLabel());
+            this.targetLabel = 
this.getVertexLabel(this.edgeLabel.targetLabel());
+        }
+        // Ensure that the source/target id fileds are matched with id strategy
         this.checkIdFields(this.sourceLabel, this.mapping.sourceFields());
         this.checkIdFields(this.targetLabel, this.mapping.targetFields());
 

Reply via email to