apache / incubator-hugegraph

A graph database that supports more than 100+ billion data, high performance and scalability (Include OLTP Engine & REST-API & Backends)
https://hugegraph.apache.org
Apache License 2.0
2.62k stars 517 forks source link

[Question] Order vertex/edge without specified property #1579

Closed Yicheng-Wang closed 3 years ago

Yicheng-Wang commented 3 years ago

Problem Type (问题类型)

gremlin (结果不合预期)

Before submit

Environment (环境信息)

Your Question (问题描述)

Expected behavior

We expecte get the vertexes/edges ordered by their ID using gremlin order query without specified property like "g.V()/E().order().by(asc/desc)" in HugeGraph, as we can get the result by the same query in JanusGraph.

Actual behavior

An exception was thrown.

java.lang.ClassCastException: com.baidu.hugegraph.structure.HugeVertex cannot be cast to java.lang.Comparable
        at com.baidu.hugegraph.exception.ServerException.fromResponse(ServerException.java:47)
        at com.baidu.hugegraph.client.RestClient.checkStatus(RestClient.java:93)
        at com.baidu.hugegraph.rest.AbstractRestClient.post(AbstractRestClient.java:198)
        at com.baidu.hugegraph.rest.AbstractRestClient.post(AbstractRestClient.java:172)
        at com.baidu.hugegraph.api.gremlin.GremlinAPI.post(GremlinAPI.java:41)
        at com.baidu.hugegraph.driver.GremlinManager.execute(GremlinManager.java:51)
        at com.baidu.hugegraph.api.gremlin.GremlinRequest$Builder.execute(GremlinRequest.java:55)
        at org.gdbtesting.validation.ValidateHugeGraphOrder.main(ValidateHugeGraphOrder.java:41)
Caused by: [java.lang.ClassCastException]

Example to reproduce

        hugegraph.schema().propertyKey("name").asText().ifNotExist().create();
        hugegraph.schema().propertyKey("price").asDouble().ifNotExist().create();

// vertex
        hugegraph.schema().vertexLabel("product").useCustomizeNumberId().properties("name", "price").nullableKeys("name", "price").create();

        GraphManager graph = hugegraph.graph();

// create graph data
        Vertex product1 = new Vertex("product").property("name", "product1").property("price", 3.254615);
        product1.id(16);
        Vertex product2 = new Vertex("product").property("name", "product2").property("price", 4.5688);
        product2.id(18);
        Vertex product3 = new Vertex("product").property("name", "product3").property("price", 1.5688);
        product3.id(22);

        graph.addVertices(Arrays.asList(product1, product2,product3));

        GremlinManager gremlin = hugegraph.gremlin();
        String query = "g.V().order().by(asc)";
        try{
            ResultSet hugeResult = gremlin.gremlin(query).execute();
            Iterator<Result> huresult = hugeResult.iterator();
            huresult.forEachRemaining(result -> {
                Object object = result.getObject();
                System.out.println(object);
            });
        }catch(Exception e){
            e.printStackTrace();
        }

We could successfully run the order() step with specified property in Hugegraph, like using "g.V().id().order().by(asc)" to get vertexes ordered by vertex ID. We bring up the issue for we are wondering whether query without specified property, like "g.V()/E().order().by(asc/desc)", is grammatically correct or not, as we find it could be accepted in JanusGraph while get exception above in HugeGraph.

Vertex/Edge example (问题点 / 边数据举例)

No response

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

No response

imbajin commented 3 years ago

Do u mean:

  1. g.V().order().by(property, desc) or V.id().xxis OK in HugeGraph, but g.V().order().by(desc) is not supported? (if yes, could u check if the server's log print any stack of exception? or open debug mode)
  2. Does JanusGraph can support both of them? refer to the TinkerPop order() step, seems search with property/value is the official case?

Will find the reason soon

Yicheng-Wang commented 3 years ago

Do u means:

  1. g.V().order().by(property, desc) or V.id().xxis OK in HugeGraph, but g.V().order().by(desc) is not supported? (if yes, could u check if the server's log print any stack of exception? or open debug mode)
  2. Does JanusGraph can support both of them? refer to the TinkerPop order() step, seems search with property/value is the official case?

Will find the reason soon

  1. Yes, the stack of exception in server's log is as follows:
    2021-08-19 10:01:48 20643 [gremlin-server-exec-2] [WARN ] org.apache.tinkerpop.gremlin.server.handler.HttpGremlinEndpointHandler [] - Invalid request - responding with 500 Internal Server Error and com.baidu.hugegraph.structure.HugeVertex cannot be cast to java.lang.Comparable
    java.lang.ClassCastException: com.baidu.hugegraph.structure.HugeVertex cannot be cast to java.lang.Comparable
    at org.apache.tinkerpop.gremlin.process.traversal.Order$4.compare(Order.java:103) ~[gremlin-core-3.4.3.jar:3.4.3]
    at org.apache.tinkerpop.gremlin.util.function.MultiComparator.compare(MultiComparator.java:57) ~[gremlin-core-3.4.3.jar:3.4.3]
    at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355) ~[?:1.8.0_292]
    at java.util.TimSort.sort(TimSort.java:220) ~[?:1.8.0_292]
    at java.util.Arrays.sort(Arrays.java:1512) ~[?:1.8.0_292]
    at java.util.ArrayList.sort(ArrayList.java:1464) ~[?:1.8.0_292]
    at java.util.Collections.sort(Collections.java:177) ~[?:1.8.0_292]
    at org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet.sort(TraverserSet.java:151) ~[gremlin-core-3.4.3.jar:3.4.3]
    at org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep.barrierConsumer(OrderGlobalStep.java:68) ~[gremlin-core-3.4.3.jar:3.4.3]
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.CollectingBarrierStep.processNextStart(CollectingBarrierStep.java:113) ~[gremlin-core-3.4.3.jar:3.4.3]
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143) ~[gremlin-core-3.4.3.jar:3.4.3]
    at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.hasNext(DefaultTraversal.java:197) ~[gremlin-core-3.4.3.jar:3.4.3]
    at org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils.fill(IteratorUtils.java:62) ~[gremlin-core-3.4.3.jar:3.4.3]
    at org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils.list(IteratorUtils.java:85) ~[gremlin-core-3.4.3.jar:3.4.3]
    at org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils.asList(IteratorUtils.java:382) ~[gremlin-core-3.4.3.jar:3.4.3]
    at org.apache.tinkerpop.gremlin.server.handler.HttpGremlinEndpointHandler.lambda$channelRead$1(HttpGremlinEndpointHandler.java:245) ~[gremlin-server-3.4.3.jar:3.4.3]
    at org.apache.tinkerpop.gremlin.util.function.FunctionUtils.lambda$wrapFunction$0(FunctionUtils.java:36) ~[gremlin-core-3.4.3.jar:3.4.3]
    at org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$0(GremlinExecutor.java:272) ~[gremlin-groovy-3.4.3.jar:3.4.3]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_292]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_292]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_292]
    at com.baidu.hugegraph.auth.HugeGraphAuthProxy$ContextTask.run(HugeGraphAuthProxy.java:1537) [hugegraph-api-0.11.2.jar:0.58.0.0]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_292]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_292]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_292]
  2. Yes, JanusGraph can support both of them, and normally with property/value should be the official case, thus this is not a big deal, ask just for curious.
imbajin commented 3 years ago

The reason for supporting the g.V().order().by(desc), we need implement a general comparator for it (lack it now)

U can use g.V().id().order().by() or g.V().order().by(T.id, desc) now

Yicheng-Wang commented 3 years ago

The reason for supporting the g.V().order().by(desc), we need implement a general comparator for it (lack it now)

U can use g.V().id().order().by() or g.V().order().by(T.id, desc) now

Fair enough, thank you for the response~