ElectScholar commented on issue #1949:
URL:
https://github.com/apache/incubator-hugegraph/issues/1949#issuecomment-2896265359
Issue #150 appears to be very similar to the problem described here and it
seemed to have been cleared up and not a problem of multiple labels, but from
my perspective, it does not seem to have any bearing on the functionality of
the code today.
I used the schema mentioned above and successfully integrated it with my own
test Docker server container. During testing, I couldn't replicate the error. I
did make a small modification, adding a property key ep0 since it was missing,
and I believe this is necessary to construct an edge properly (at least as far
as I can tell as a newcomer).
Below is the sample code that I used, which is based on the provided schema:
## Code:
```java
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import org.apache.hugegraph.driver.GraphManager;
import org.apache.hugegraph.driver.GremlinManager;
import org.apache.hugegraph.driver.HugeClient;
import org.apache.hugegraph.driver.SchemaManager;
import org.apache.hugegraph.structure.graph.Edge;
import org.apache.hugegraph.structure.graph.Vertex;
import org.apache.hugegraph.structure.gremlin.Result;
import org.apache.hugegraph.structure.gremlin.ResultSet;
public class CustomExample {
public static void main(String[] args) throws IOException {
HugeClient hugeClient = null;
try {
hugeClient = HugeClient.builder("http://localhost:8080",
"hugegraph").build();
SchemaManager schema = hugeClient.schema();
createSchema(schema);
GraphManager graph = hugeClient.graph();
addData(graph);
executeGremlinQuery(hugeClient);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (hugeClient != null) {
hugeClient.close();
}
}
}
private static void createSchema(SchemaManager schema) {
try {
schema.propertyKey("ep0").asBoolean().ifNotExist().create();
schema.propertyKey("ep1").asBoolean().ifNotExist().create();
schema.propertyKey("vp0").asBoolean().ifNotExist().create();
schema.vertexLabel("vl0").properties("vp0").nullableKeys("vp0").ifNotExist().create();
schema.indexLabel("vl0Byvp0").onV("vl0").by("vp0").shard().ifNotExist().create();
schema.edgeLabel("el0").sourceLabel("vl0").targetLabel("vl0")
.properties("ep0").ifNotExist().create();
schema.edgeLabel("el1").sourceLabel("vl0").targetLabel("vl0")
.properties("ep1").ifNotExist().create();
schema.indexLabel("el0Byep0").onE("el0").by("ep0").shard().ifNotExist().create();
schema.indexLabel("el1Byep0").onE("el1").by("ep1").shard().ifNotExist().create();
System.out.println("Schema created successfully");
} catch (Exception e) {
System.err.println("Schema creation failed:");
e.printStackTrace();
}
}
private static void addData(GraphManager graph) {
Vertex vertex1 = new Vertex("vl0").property("vp0", true);
Vertex vertex2 = new Vertex("vl0").property("vp0", false);
Vertex vertex3 = new Vertex("vl0").property("vp0", true);
graph.addVertices(Arrays.asList(vertex1, vertex2, vertex3));
Edge edge1 = new
Edge("el0").source(vertex1).target(vertex2).property("ep0", true);
Edge edge2 = new
Edge("el1").source(vertex1).target(vertex3).property("ep1", false);
graph.addEdges(Arrays.asList(edge1, edge2));
}
private static void executeGremlinQuery(HugeClient hugeClient) {
GremlinManager gremlin = hugeClient.gremlin();
String query = "g.V().outE('el0', 'el1').has('ep0', true)";
try {
// Execute the Gremlin query
ResultSet resultSet = gremlin.gremlin(query).execute();
// Iterate through the result set explicitly
System.out.println("Query Results:");
Iterator<Result> resultIterator = resultSet.iterator();
if (!resultIterator.hasNext()) {
System.out.println("No results found for the query.");
return;
}
// Iterate through the results
while (resultIterator.hasNext()) {
Result result = resultIterator.next();
Object obj = result.getObject();
System.out.println("" + obj);
}
} catch (Exception e) {
System.err.println("Gremlin query execution failed:");
e.printStackTrace();
}
}
}
```
## Output:
```
Schema created successfully
Query Results:
{id=L989706117179244544>1>1>>L989706117179244545,
sourceId=989706117179244544, sourceLabel=vl0, targetId=989706117179244545,
targetLabel=vl0, label=el0, properties={ep0=true}}
{id=L989711128814682112>1>1>>L989711128814682113,
sourceId=989711128814682112, sourceLabel=vl0, targetId=989711128814682113,
targetLabel=vl0, label=el0, properties={ep0=true}}
{id=L989711551285952512>1>1>>L989711551285952513,
sourceId=989711551285952512, sourceLabel=vl0, targetId=989711551285952513,
targetLabel=vl0, label=el0, properties={ep0=true}}
```
As you can see edges were populated
## Conclusion:
At this point, I haven’t encountered any issues with the schema or query
execution. While I’m still new to this project and may have missed something,
based on the documentation I followed, the schema appears to be implemented
correctly, and everything seems to be working fine. I’m not sure where the
issue lies, but I am open to any suggestions or further debugging steps.
--
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]