[ https://issues.apache.org/jira/browse/TINKERPOP-3164?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17956465#comment-17956465 ]
Yang Xia edited comment on TINKERPOP-3164 at 6/5/25 10:54 PM: -------------------------------------------------------------- Hi, I'm trying to replicate this in TinkerGraph with the Gremlin Console, however, it looks like everything is as expected. As I see that you are using JanusGraph, I wonder if this is an issue on the JanusGraph side? For TinkerGraph (via Gremlin Console 3.7.2), by default the step by() filters out unproductive traversers ([https://tinkerpop.apache.org/docs/3.7.3/reference/#by-step|https://tinkerpop.apache.org/docs/3.7.3/reference/#by-step)]), it is actually expected that both queries omit the "Honda" vertex: {code:java} gremlin> g.V().hasLabel("Car").order().by("brand").by("weight").elementMap() ==>[id:18,label:Car,weight:4900,model:Q8,type:CROSSOVER,brand:Audi] ==>[id:0,label:Car,weight:5000,model:F-150,type:TRUCK,brand:Ford] ==>[id:13,label:Car,weight:4500,model:Frontier,type:TRUCK,brand:Nissan] gremlin> g.V().hasLabel("Car").choose(__.values("type")).option("TRUCK", __.has("weight", P.lte(4500))).option("CROSSOVER", __.identity()).order().by("brand").by("weight").elementMap() ==>[id:18,label:Car,weight:4900,model:Q8,type:CROSSOVER,brand:Audi] ==>[id:13,label:Car,weight:4500,model:Frontier,type:TRUCK,brand:Nissan] {code} Now for TinkerGraph, you can allow unproductive by()'s to be passed through using the "ProductiveByStrategy", for which you'll see that the "Honda" vertex appears in the result of both queries: {code:java} gremlin> g.withStrategies(ProductiveByStrategy).V().hasLabel("Car").order().by("brand").by("weight").elementMap() ==>[id:18,label:Car,weight:4900,model:Q8,type:CROSSOVER,brand:Audi] ==>[id:0,label:Car,weight:5000,model:F-150,type:TRUCK,brand:Ford] ==>[id:23,label:Car,model:CR-V,type:CROSSOVER,brand:Honda] ==>[id:13,label:Car,weight:4500,model:Frontier,type:TRUCK,brand:Nissan] gremlin> g.withStrategies(ProductiveByStrategy).V().hasLabel("Car").choose(__.values("type")).option("TRUCK", __.has("weight", P.lte(4500))).option("CROSSOVER", __.identity()).order().by("brand").by("weight").elementMap() ==>[id:18,label:Car,weight:4900,model:Q8,type:CROSSOVER,brand:Audi] ==>[id:23,label:Car,model:CR-V,type:CROSSOVER,brand:Honda] ==>[id:13,label:Car,weight:4500,model:Frontier,type:TRUCK,brand:Nissan] {code} Looking at your results with JanusGraph, it looks as if the `ProductiveByStrategy` was enabled for the first query but disabled in the second one, so I'm wondering if it has to do with some configuration in JanusGraph that's worth a check. was (Author: xiazcy): Hi, I'm trying to replicate this in TinkerGraph with the Gremlin Console, however, it looks like everything is as expected. As I see that you are using JanusGraph, I wonder if this is an issue on the JanusGraph side? For TinkerGraph (via Gremlin Console 3.7.2), by default the step by() filters out unproductive traversers ([https://tinkerpop.apache.org/docs/3.7.3/reference/#by-step|https://tinkerpop.apache.org/docs/3.7.3/reference/#by-step)]), it is actually expected that both queries omit the "Honda" vertex: {code:java} gremlin> g.V().hasLabel("Car").order().by("brand").by("weight").elementMap() ==>[id:18,label:Car,weight:4900,model:Q8,type:CROSSOVER,brand:Audi] ==>[id:0,label:Car,weight:5000,model:F-150,type:TRUCK,brand:Ford] ==>[id:13,label:Car,weight:4500,model:Frontier,type:TRUCK,brand:Nissan] gremlin> g.V().hasLabel("Car").choose(__.values("type")).option("TRUCK", __.has("weight", P.lte(4500))).option("CROSSOVER", __.identity()).order().by("brand").by("weight").elementMap() ==>[id:18,label:Car,weight:4900,model:Q8,type:CROSSOVER,brand:Audi] ==>[id:13,label:Car,weight:4500,model:Frontier,type:TRUCK,brand:Nissan] {code} Now for TinkerGraph, you can allow unproductive by()'s to be passed through using the "ProductiveByStrategy", for which you'll see that the "Honda" vertex appears in the result of both queries: {code:java} gremlin> g.withStrategies(ProductiveByStrategy).V().hasLabel("Car").order().by("brand").by("weight").elementMap() ==>[id:18,label:Car,weight:4900,model:Q8,type:CROSSOVER,brand:Audi] ==>[id:0,label:Car,weight:5000,model:F-150,type:TRUCK,brand:Ford] ==>[id:23,label:Car,model:CR-V,type:CROSSOVER,brand:Honda] ==>[id:13,label:Car,weight:4500,model:Frontier,type:TRUCK,brand:Nissan] gremlin> g.withStrategies(ProductiveByStrategy).V().hasLabel("Car").choose(__.values("type")).option("TRUCK", __.has("weight", P.lte(4500))).option("CROSSOVER", __.identity()).order().by("brand").by("weight").elementMap() ==>[id:18,label:Car,weight:4900,model:Q8,type:CROSSOVER,brand:Audi] ==>[id:23,label:Car,model:CR-V,type:CROSSOVER,brand:Honda] ==>[id:13,label:Car,weight:4500,model:Frontier,type:TRUCK,brand:Nissan] {code} Looking at your results with JanusGraph, it looks as if the `ProductiveByStrategy` was enabled for the first query but disabled in the second one, so I'm wondering if it has to do with some configuration in JanusGraph that's worth a check. > Sorting doesn't work after the 'choose' step (if the property doesn't exist) > ---------------------------------------------------------------------------- > > Key: TINKERPOP-3164 > URL: https://issues.apache.org/jira/browse/TINKERPOP-3164 > Project: TinkerPop > Issue Type: Bug > Components: process > Affects Versions: 3.7.2 > Reporter: Vladislav > Priority: Major > > Elements are lost when sorting by property (after choose step) if the > property is missing in a vertex > Example graph: > {code:java} > gremlin> graph.traversal().addV("Car").property("brand", > "Ford").property("model", "F-150").property("type", > "TRUCK").property("weight", 5000).iterate() > gremlin> graph.traversal().addV("Car").property("brand", > "Nissan").property("model", "Frontier").property("type", > "TRUCK").property("weight", 4500).iterate() > gremlin> graph.traversal().addV("Car").property("brand", > "Audi").property("model", "Q8").property("type", > "CROSSOVER").property("weight", 4900).iterate() > gremlin> graph.traversal().addV("Car").property("brand", > "Honda").property("model", "CR-V").property("type", "CROSSOVER").iterate() > {code} > Base sort (without choose step) > {code:java} > gremlin> > graph.traversal().V().hasLabel("Car").order().by("brand").by("weight").elementMap() > 15:42:10 WARN > org.janusgraph.graphdb.transaction.StandardJanusGraphTx$3.execute - Query > requires iterating over all vertices [[~label = Car]]. For better > performance, use indexes > ==>[weight:4900,model:Q8,type:CROSSOVER,brand:Audi,id:8408,label:Car] > ==>[weight:5000,model:F-150,type:TRUCK,brand:Ford,id:4136,label:Car] > ==>[model:CR-V,type:CROSSOVER,brand:Honda,id:4328,label:Car] > ==>[weight:4500,model:Frontier,type:TRUCK,brand:Nissan,id:4312,label:Car] > {code} > Sort with choose step (Honda CR-V is missing): > {code:java} > gremlin> > graph.traversal().V().hasLabel("Car").choose(__.values("type")).option("TRUCK", > __.has("weight", P.lte(4500))).option("CROSSOVER", > __.identity()).order().by("brand").by("weight").elementMap() > 15:43:53 WARN > org.janusgraph.graphdb.transaction.StandardJanusGraphTx$3.execute - Query > requires iterating over all vertices [[~label = Car]]. For better > performance, use indexes > ==>[weight:4900,model:Q8,type:CROSSOVER,brand:Audi,id:8408,label:Car] > ==>[weight:4500,model:Frontier,type:TRUCK,brand:Nissan,id:4312,label:Car] > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)