Cole-Greer commented on code in PR #3458:
URL: https://github.com/apache/tinkerpop/pull/3458#discussion_r3437661737


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/P.java:
##########
@@ -453,6 +697,106 @@ public static <V> P<V> without(final Collection<V> value) 
{
         return new P(Contains.without, value);
     }
 
+    /**
+     * Determines if values are equal using a child traversal resolved at 
runtime.
+     *
+     * @since 4.0.0
+     */
+    public static <V> P<V> eq(final Traversal<?, ?> traversalValue) {
+        ChildTraversalValidator.validate(traversalValue.asAdmin());
+        return new P(Compare.eq, traversalValue.asAdmin());
+    }
+
+    /**
+     * Determines if values are not equal using a child traversal resolved at 
runtime.
+     *
+     * @since 4.0.0
+     */
+    public static <V> P<V> neq(final Traversal<?, ?> traversalValue) {
+        ChildTraversalValidator.validate(traversalValue.asAdmin());
+        return new P(Compare.neq, traversalValue.asAdmin());
+    }
+
+    /**
+     * Determines if a value is less than another using a child traversal 
resolved at runtime.
+     *
+     * @since 4.0.0
+     */
+    public static <V> P<V> lt(final Traversal<?, ?> traversalValue) {
+        ChildTraversalValidator.validate(traversalValue.asAdmin());
+        return new P(Compare.lt, traversalValue.asAdmin());
+    }
+
+    /**
+     * Determines if a value is less than or equal to another using a child 
traversal resolved at runtime.
+     *
+     * @since 4.0.0
+     */
+    public static <V> P<V> lte(final Traversal<?, ?> traversalValue) {
+        ChildTraversalValidator.validate(traversalValue.asAdmin());
+        return new P(Compare.lte, traversalValue.asAdmin());
+    }
+
+    /**
+     * Determines if a value is greater than another using a child traversal 
resolved at runtime.
+     *
+     * @since 4.0.0
+     */
+    public static <V> P<V> gt(final Traversal<?, ?> traversalValue) {
+        ChildTraversalValidator.validate(traversalValue.asAdmin());
+        return new P(Compare.gt, traversalValue.asAdmin());
+    }
+
+    /**
+     * Determines if a value is greater than or equal to another using a child 
traversal resolved at runtime.
+     *
+     * @since 4.0.0
+     */
+    public static <V> P<V> gte(final Traversal<?, ?> traversalValue) {
+        ChildTraversalValidator.validate(traversalValue.asAdmin());
+        return new P(Compare.gte, traversalValue.asAdmin());
+    }
+
+    /**
+     * Determines if a value is within the results of a child traversal 
resolved at runtime.
+     *
+     * @since 4.0.0
+     */
+    public static <V> P<V> within(final Traversal<?, ?> traversalValue) {
+        ChildTraversalValidator.validate(traversalValue.asAdmin());
+        return new P(Contains.within, traversalValue.asAdmin());
+    }
+
+    /**
+     * Determines if a value is within the union of results from multiple 
child traversals resolved at runtime.
+     * Each traversal is evaluated independently and results are combined into 
a single collection.
+     *
+     * @since 4.0.0
+     */
+    public static <V> P<V> within(final Traversal<?, ?> first, final 
Traversal<?, ?> second, final Traversal<?, ?>... more) {
+        return containsTraversals(Contains.within, first, second, more);
+    }
+
+    /**
+     * Determines if a value is not within the results of a child traversal 
resolved at runtime.
+     *
+     * @since 4.0.0
+     */
+    public static <V> P<V> without(final Traversal<?, ?> traversalValue) {
+        ChildTraversalValidator.validate(traversalValue.asAdmin());
+        return new P(Contains.without, traversalValue.asAdmin());
+    }
+
+    /**
+     * Determines if a value is not within the union of results from multiple 
child traversals resolved at runtime.
+     * Each traversal is evaluated independently and results are combined into 
a single collection.
+     *
+     * @since 4.0.0
+     */
+    public static <V> P<V> without(final Traversal<?, ?> first, final 
Traversal<?, ?> second, final Traversal<?, ?>... more) {

Review Comment:
   a minimum of a `first, more...` overload is necessary to disambiguate the 
zero arg calls to these methods.



##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/P.java:
##########
@@ -49,10 +56,23 @@ public class P<V> implements Predicate<V>, Serializable, 
Cloneable {
     protected Map<String, V> variables = new HashMap<>();
     protected Collection<V> literals = Collections.EMPTY_LIST;
     private boolean isCollection = false;
+    private boolean resolvedEmpty = false;
+    private Traversal.Admin<?, ?> traversalValue;
+    private List<Traversal.Admin<?, ?>> traversalValues;

Review Comment:
   I experimented with this a bit, and it really just moving problems around 
instead of solving them. The real issue is the pre-existing extent to which the 
generics are abused in P. I think a larger P refactor would be beneficial at 
some point, but definitely beyond the scope of this work.



##########
docs/src/upgrade/release-4.x.x.asciidoc:
##########
@@ -101,6 +70,51 @@ partial work is discarded if the user forgets to call 
`commit()`. In Java (both
 can still be overridden via `tx.onClose(Transaction.CLOSE_BEHAVIOR.COMMIT)`. 
The non-Java GLVs do not support
 configuring close behavior and always rollback.
 
+==== Expanding Dynamic Arguments to Additional Steps
+
+Prior to 4.0, comparing a traverser's value against a dynamically computed 
reference required verbose workarounds with
+`where()`, `select()`, and labeled steps. For example, finding all people 
older than "marko" previously required:
+
+[source,groovy]

Review Comment:
   The upgrade docs examples should remain static such that they remain as-is 
following future releases. I don't think the results are particularly 
interesting for these traversals, however I can add static emulated console 
output.



##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/AcceptsChildPredicateTraversal.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.step;
+
+/**
+ * Marker interface for steps that accept user-supplied child traversals 
embedded as predicate or lookup

Review Comment:
   I think this points to a larger branding/framing problem with this 
interface. I've renamed it `ReadOnlyTraversalParent` and updated the javadoc. 
See below thread for more details.



##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/AcceptsChildPredicateTraversal.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.step;
+
+/**
+ * Marker interface for steps that accept user-supplied child traversals 
embedded as predicate or lookup
+ * arguments (for example {@code has(key, traversal)}, {@code 
is(P.gt(traversal))},
+ * {@code V(traversal)}, or {@code property(traversal)}).
+ * <p>
+ * The {@link 
org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ChildTraversalVerificationStrategy}
+ * validates the local children of every step implementing this interface, 
rejecting child traversals that
+ * contain mutating steps. New steps that accept such traversals should 
implement this interface so they are
+ * validated automatically rather than relying on a hardcoded step list.
+ *
+ * @since 4.0.0
+ */
+public interface AcceptsChildPredicateTraversal {

Review Comment:
   I've opted to go in a different direction on this one, renaming it to 
`ReadOnlyTraversalParent extends TraversalParent`. I added the `extends 
TraversalParent` as I don't think this marker interface makes any sense for 
steps which are not already TraversalParents. I also think that this new 
framing is easier to understand, it is a `TraversalParent` with a `ReadOnly` 
restriction applied.



-- 
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]

Reply via email to