You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by "xiazcy (via GitHub)" <gi...@apache.org> on 2025/10/17 03:03:55 UTC

[PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

xiazcy opened a new pull request, #3244:
URL: https://github.com/apache/tinkerpop/pull/3244

   As discussed in [devlist](https://lists.apache.org/thread/mtfy1jshb8rwqglp7ooxswwwwj70qy33), disallowing `choose().option(Traversal, v)` with an `IllegalArgumentException` in 3.8.0, with the intention of enabling an improved implementation in future versions.
   
   VOTE +1


-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3244:
URL: https://github.com/apache/tinkerpop/pull/3244#discussion_r2446217391


##########
docs/src/upgrade/release-3.8.x.asciidoc:
##########
@@ -623,6 +623,43 @@ gremlin> g.V().choose(__.values("age")).
 ==>peter
 ----
 
+*Removal of choose().option(Traversal, v)*
+
+The `choose().option(Traversal, v)` was relatively unused in comparison to the other overloads with constants, predicates
+and Pick tokens. The previous implementation often led to confusion as it only evaluated if the traversal was productive,
+rather than performing comparisons based on the traversal's output value. To eliminate this confusion, `Traversal` is no
+longer permitted as an option token for `choose()`. Any usages which are dependent on the Traversal for dynamic case
+matching can be rewritten using `union()`, with filters prepended to each child traversal.
+
+[source,text]
+----
+// 3.7.x
+gremlin> g.V().hasLabel("person").choose(identity()).
+......1>         option(outE().count().is(P.gt(2)), values("age")).
+......2>         option(none, values("name"))
+==>29
+==>vadas
+==>josh
+==>peter

Review Comment:
   Can you explain what is confusing about this example?



-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

Posted by "spmallette (via GitHub)" <gi...@apache.org>.
spmallette commented on code in PR #3244:
URL: https://github.com/apache/tinkerpop/pull/3244#discussion_r2441260314


##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/branch/Choose.feature:
##########
@@ -666,4 +666,15 @@ Feature: Step - choose()
       | matched |
       | d[27].i |
       | d[32].i |
-      | d[35].i |
\ No newline at end of file
+      | d[35].i |
+
+  Scenario: g_V_hasLabelXpersonX_chooseX_valuesXnameX_option1X_isXmarkoX_valuesXageXX_option2Xnone_valuesXnameXX

Review Comment:
   interesting that we didn't even really have a test for this anywhere...



-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy commented on code in PR #3244:
URL: https://github.com/apache/tinkerpop/pull/3244#discussion_r2446229906


##########
docs/src/upgrade/release-3.8.x.asciidoc:
##########
@@ -623,6 +623,43 @@ gremlin> g.V().choose(__.values("age")).
 ==>peter
 ----
 
+*Removal of choose().option(Traversal, v)*
+
+The `choose().option(Traversal, v)` was relatively unused in comparison to the other overloads with constants, predicates
+and Pick tokens. The previous implementation often led to confusion as it only evaluated if the traversal was productive,
+rather than performing comparisons based on the traversal's output value. To eliminate this confusion, `Traversal` is no
+longer permitted as an option token for `choose()`. Any usages which are dependent on the Traversal for dynamic case
+matching can be rewritten using `union()`, with filters prepended to each child traversal.
+
+[source,text]
+----
+// 3.7.x
+gremlin> g.V().hasLabel("person").choose(identity()).
+......1>         option(outE().count().is(P.gt(2)), values("age")).
+......2>         option(none, values("name"))
+==>29
+==>vadas
+==>josh
+==>peter

Review Comment:
   Technically this isn't the confusing one, given `is(P())` is a filter it will only produce based on the desired filtering. The example is meant to show what people can do as an alternative, i.e. this particular one can be replaced with a union() with where(). 
   
   An actual meaningless query would be something like:
   ```
   gremlin> g.V().hasLabel("person").choose(identity()).
                             option(outE().count(), values("age")).
                             option(none, values("name"))
   ==>29
   ==>27
   ==>32
   ==>35
   ```
   But I don't think it needs to be shown here per se. 



-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy commented on code in PR #3244:
URL: https://github.com/apache/tinkerpop/pull/3244#discussion_r2441360245


##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/branch/Choose.feature:
##########
@@ -666,4 +666,15 @@ Feature: Step - choose()
       | matched |
       | d[27].i |
       | d[32].i |
-      | d[35].i |
\ No newline at end of file
+      | d[35].i |
+
+  Scenario: g_V_hasLabelXpersonX_chooseX_valuesXnameX_option1X_isXmarkoX_valuesXageXX_option2Xnone_valuesXnameXX

Review Comment:
   It's indeed a rare use case.



-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer commented on code in PR #3244:
URL: https://github.com/apache/tinkerpop/pull/3244#discussion_r2441211868


##########
docs/src/upgrade/release-3.8.x.asciidoc:
##########
@@ -623,8 +623,45 @@ gremlin> g.V().choose(__.values("age")).
 ==>peter
 ----
 
+*Removal of choose().option(Traversal, v)*
+
+The `choose().option(Traversal, v)` is rarely used in comparison to the other overloads with constants, predicates and Pick
+tokens. It is also not the recommended approach for performance reasons. In addition, the current implementation leads to
+confusion as it only evaluates if the traversal is productive, rather than performing comparison on based on the traversal's
+output value. Fixing this behavior would require extensive changes, as such we are removing this functionality from
+`choose()` in 3.8.0, with plans to reintroduce a properly implemented version in the next major release.

Review Comment:
   I think this would be better restructured to keep the focus on the confusing nature of the old implementation. Something such as this:
   
   ```
   The `choose().option(Traversal, v)` was relatively unused in comparison to the other overloads with
   constants, predicates and Pick tokens. The previous implementation often led to confusion as it only
   evaluated if the traversal was productive, rather than performing comparisons based on the traversal's
   output value. To eliminate this confusion, `Traversal`'s are no longer permitted as an option token for
   `choose()`. Any usages which are dependent on the Traversal for dynamic case matching can be
   rewritten using `union()`, with filters prepended to each child traversal.
   ```



##########
docs/src/upgrade/release-3.8.x.asciidoc:
##########
@@ -623,8 +623,45 @@ gremlin> g.V().choose(__.values("age")).
 ==>peter
 ----
 
+*Removal of choose().option(Traversal, v)*
+
+The `choose().option(Traversal, v)` is rarely used in comparison to the other overloads with constants, predicates and Pick
+tokens. It is also not the recommended approach for performance reasons. In addition, the current implementation leads to
+confusion as it only evaluates if the traversal is productive, rather than performing comparison on based on the traversal's
+output value. Fixing this behavior would require extensive changes, as such we are removing this functionality from
+`choose()` in 3.8.0, with plans to reintroduce a properly implemented version in the next major release.
+
+[source,text]
+----
+// 3.7.x
+gremlin> g.V().hasLabel("person").choose(values("name")).
+......1>         option(is("marko"), values("age")).
+......2>         option(none, values("name"))
+==>29
+==>vadas
+==>josh
+==>peter
+
+// 3.8.0 - an IllegalArgumentException will be thrown
+gremlin> g.V().hasLabel("person").choose(values("name")).
+......1>         option(is("marko"), values("age")).
+......2>         option(none, values("name"))
+Traversal is not allowed as a Pick token for choose().option()
+Type ':help' or ':h' for help.
+Display stack trace? [yN]n
+// use predicates in these cases
+gremlin> g.V().hasLabel("person").choose(values("name")).
+......1>         option(P.eq("marko"), values("age")).
+......2>         option(none, values("name"))
+==>29
+==>vadas
+==>josh
+==>peter
+----

Review Comment:
   I'm not sure these are the best examples as I think that the simpler `option("marko", values("age"))` case is generally preferable to either `is()` or `P.eq()`. I think the most important case to cover is when the traversal is used for a more dynamic filter which cannot be easily adapted to the simpler predicate options. In that case, we should show users how they can use something like union() to achieve a similar result to the old `choose().option(Traversal, v)`
   
   ```
   [source,text]
   ----
   // 3.7.x
   gremlin> g.V().hasLabel("person").choose(identity()).
   ......1>         option(outE().count().is(P.gt(2)), values("age")).
   ......2>         option(none, values("name"))
   ==>29
   ==>vadas
   ==>josh
   ==>peter
   
   // 3.8.0 - an IllegalArgumentException will be thrown
   gremlin> g.V().hasLabel("person").choose(identity()).
   ......1>         option(outE().count().is(P.gt(2)), values("age")).
   ......2>         option(none, values("name"))
   Traversal is not allowed as a Pick token for choose().option()
   Type ':help' or ':h' for help.
   Display stack trace? [yN]n
   
   // use union() in these cases
   gremlin> g.V().hasLabel("person").union(
   ......1>         where(outE().count().is(P.gt(2))).values("age"),
   ......2>         __.not(where(outE().count().is(P.gt(2)))).values("name"))
   ==>29
   ==>vadas
   ==>josh
   ==>peter
   ----
   ```



-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

Posted by "spmallette (via GitHub)" <gi...@apache.org>.
spmallette commented on code in PR #3244:
URL: https://github.com/apache/tinkerpop/pull/3244#discussion_r2441254950


##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -1138,9 +1138,8 @@ link:https://tinkerpop.apache.org/docs/x.y.z/reference/#call-step[reference]
 *Modulation:*
 
 * `option(pickToken, traversalOption)` - Adds a traversal option to the `choose` step. The `pickToken` is matched
-against the result of the choice traversal. The `pickToken` may be a literal value, a predicate `P`, a `Traversal`
-(whose first returned value is used for matching) or a `Pick` enum value. If a match is found, the traverser is routed
-to the corresponding `traversalOption`.
+against the result of the choice traversal. The `pickToken` may be a literal value, a predicate `P` or a `Pick` enum
+value. `Traversal` is not allowed as a `pickToken` here and will lead to `IllegalArgumentException`. If a match is found, the traverser is routed to the corresponding `traversalOption`.

Review Comment:
   nit: line feed



-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

Posted by "kenhuuu (via GitHub)" <gi...@apache.org>.
kenhuuu commented on PR #3244:
URL: https://github.com/apache/tinkerpop/pull/3244#issuecomment-3423594375

   VOTE +1


-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy merged PR #3244:
URL: https://github.com/apache/tinkerpop/pull/3244


-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

Posted by "spmallette (via GitHub)" <gi...@apache.org>.
spmallette commented on code in PR #3244:
URL: https://github.com/apache/tinkerpop/pull/3244#discussion_r2441258893


##########
docs/src/upgrade/release-3.8.x.asciidoc:
##########
@@ -623,8 +623,45 @@ gremlin> g.V().choose(__.values("age")).
 ==>peter
 ----
 
+*Removal of choose().option(Traversal, v)*
+
+The `choose().option(Traversal, v)` is rarely used in comparison to the other overloads with constants, predicates and Pick
+tokens. It is also not the recommended approach for performance reasons. In addition, the current implementation leads to
+confusion as it only evaluates if the traversal is productive, rather than performing comparison on based on the traversal's
+output value. Fixing this behavior would require extensive changes, as such we are removing this functionality from
+`choose()` in 3.8.0, with plans to reintroduce a properly implemented version in the next major release.
+
+[source,text]
+----
+// 3.7.x
+gremlin> g.V().hasLabel("person").choose(values("name")).
+......1>         option(is("marko"), values("age")).
+......2>         option(none, values("name"))
+==>29
+==>vadas
+==>josh
+==>peter
+
+// 3.8.0 - an IllegalArgumentException will be thrown
+gremlin> g.V().hasLabel("person").choose(values("name")).
+......1>         option(is("marko"), values("age")).
+......2>         option(none, values("name"))
+Traversal is not allowed as a Pick token for choose().option()
+Type ':help' or ':h' for help.
+Display stack trace? [yN]n
+// use predicates in these cases
+gremlin> g.V().hasLabel("person").choose(values("name")).
+......1>         option(P.eq("marko"), values("age")).
+......2>         option(none, values("name"))
+==>29
+==>vadas
+==>josh
+==>peter
+----
+
 See: link:https://issues.apache.org/jira/browse/TINKERPOP-3178[TINKERPOP-3178],
-link:https://tinkerpop.apache.org/docs/3.8.0/reference/#choose-step[Reference Documentation - choose()]
+link:https://tinkerpop.apache.org/docs/3.8.0/reference/#choose-step[Reference Documentation - choose()],
+linke:https://lists.apache.org/thread/mtfy1jshb8rwqglp7ooxswwwwj70qy33[DISCUSS]

Review Comment:
   nit: i'd not include dev list posts as references here. make sure they are on the JIRA  and be sure the JIRA description is user consumable.



-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy commented on code in PR #3244:
URL: https://github.com/apache/tinkerpop/pull/3244#discussion_r2446239991


##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/branch/Choose.feature:
##########
@@ -666,4 +666,15 @@ Feature: Step - choose()
       | matched |
       | d[27].i |
       | d[32].i |
-      | d[35].i |
\ No newline at end of file
+      | d[35].i |
+
+  Scenario: g_V_hasLabelXpersonX_chooseX_valuesXnameX_option1X_isXmarkoX_valuesXageXX_option2Xnone_valuesXnameXX
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().hasLabel("person").choose(values("name")).

Review Comment:
   Technically this particular simple example can be replaced with predicate, but I can add the example query from the docs into feature tests (union() will be under Union.feature).



-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

Posted by "spmallette (via GitHub)" <gi...@apache.org>.
spmallette commented on code in PR #3244:
URL: https://github.com/apache/tinkerpop/pull/3244#discussion_r2441257456


##########
docs/src/upgrade/release-3.8.x.asciidoc:
##########
@@ -623,8 +623,45 @@ gremlin> g.V().choose(__.values("age")).
 ==>peter
 ----
 
+*Removal of choose().option(Traversal, v)*
+
+The `choose().option(Traversal, v)` is rarely used in comparison to the other overloads with constants, predicates and Pick
+tokens. It is also not the recommended approach for performance reasons. In addition, the current implementation leads to
+confusion as it only evaluates if the traversal is productive, rather than performing comparison on based on the traversal's
+output value. Fixing this behavior would require extensive changes, as such we are removing this functionality from
+`choose()` in 3.8.0, with plans to reintroduce a properly implemented version in the next major release.

Review Comment:
   I think a `union` example would be relevant here.



-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3244:
URL: https://github.com/apache/tinkerpop/pull/3244#discussion_r2446224042


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/ChooseStep.java:
##########
@@ -120,6 +120,8 @@ public void addChildOption(final M pickToken, final Traversal.Admin<S, E> traver
             } else if (pickToken == Pick.none && !this.traversalPickOptions.containsKey(Pick.none)) {
                 super.addChildOption(pickToken, traversalOption);
             }
+        } else if (pickToken instanceof Traversal) {
+            throw new IllegalArgumentException("Traversal is not allowed as a Pick token for choose().option()");

Review Comment:
   Nit: would be cleaner to consolidate all validation logic into the beginning of this method instead of spread out throughout the method.



-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Disallow the use of `choose().option(Traversal, v)` [tinkerpop]

Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3244:
URL: https://github.com/apache/tinkerpop/pull/3244#discussion_r2446227767


##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/branch/Choose.feature:
##########
@@ -666,4 +666,15 @@ Feature: Step - choose()
       | matched |
       | d[27].i |
       | d[32].i |
-      | d[35].i |
\ No newline at end of file
+      | d[35].i |
+
+  Scenario: g_V_hasLabelXpersonX_chooseX_valuesXnameX_option1X_isXmarkoX_valuesXageXX_option2Xnone_valuesXnameXX
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().hasLabel("person").choose(values("name")).

Review Comment:
   Can you add a feature test for the suggested traversal to use instead (using union) to achieve the desired result?



-- 
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: commits-unsubscribe@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org