You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by "Cole-Greer (via GitHub)" <gi...@apache.org> on 2025/08/29 20:31:23 UTC

[PR] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

Cole-Greer opened a new pull request, #3195:
URL: https://github.com/apache/tinkerpop/pull/3195

   https://issues.apache.org/jira/browse/TINKERPOP-3173
   
   Replaces the old system of ternary boolean semantics with simple binary semantics. The triggers for "ERROR" states from illegal comparisons are unchanged (typically comparisons with NaN or between incomparable types such as String and int). The difference now is that instead of the ERROR being propagated according to ternary logic semantics until a reduction point is reached, the error now immediately returns a value of FALSE.
   
   This will be most visible in expressions which include negations. Prior to this change, `g.inject(NaN).not(is(1))` would produce no results as !(NaN == 1) -> !(ERROR) -> ERROR -> traverser is filtered out. After this change, the same traversal will return NaN as the same expression now evaluates as !(NaN == 1) -> !(FALSE) -> TRUE -> traverser is not filtered.
   
   This commit also introduces NotP to model a negated P, as the old method of getting the complement of the PBiPredicate may handle edge cases incorrectly:
   
   !(1 < NaN) != (1 >= NaN) -> !(FALSE) != (FALSE)


-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/GremlinValueComparator.java:
##########
@@ -331,17 +307,70 @@ private static boolean naturallyComparable(final Object f, final Object s) {
     /**
      * Return true if the two objects are of the same comparison type (although they may not be the exact same Class)
      */
-    private static boolean comparable(final Object f, final Object s) {
+    public static boolean comparable(final Object f, final Object s) {
         if (f == null || s == null)
             return f == s; // true iff both in the null space
 
+        if (eitherAreNaN(f, s))
+            return false;
+
         final Type ft = Type.type(f);
         final Type st = Type.type(s);
 
+        // if objects are collections or composites, their contents must be mutually comparable
+        if (ft == Type.List && st == Type.List) {

Review Comment:
   Great catch. Under the original TBL semantics arrays and Lists were mutually comparable. That was missing here. I've updated Type.List to now encompass arrays, and updated the associated comparator to handle iterators from either List or Arrays.



-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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

   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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/GremlinValueComparator.java:
##########
@@ -331,17 +307,74 @@ private static boolean naturallyComparable(final Object f, final Object s) {
     /**
      * Return true if the two objects are of the same comparison type (although they may not be the exact same Class)
      */
-    private static boolean comparable(final Object f, final Object s) {
+    public static boolean comparable(final Object f, final Object s) {
         if (f == null || s == null)
             return f == s; // true iff both in the null space
 
+        if (eitherAreNaN(f, s))
+            return false;
+
         final Type ft = Type.type(f);
         final Type st = Type.type(s);
 
+        // if objects are collections or composites, their contents must be mutually comparable
+        if (ft == Type.List && st == Type.List) {
+            return contentsComparable(((List) f).iterator(), ((List) s).iterator());
+        }
+        else if (ft == Type.Path && st == Type.Path) {
+            return contentsComparable(((Path) f).iterator(), ((Path) s).iterator());
+        }
+        else if (ft == Type.Set && st == Type.Set) {
+            final List l1 = new ArrayList((Set) f);
+            final List l2 = new ArrayList((Set) s);
+            Collections.sort(l1, ORDERABILITY);
+            Collections.sort(l2, ORDERABILITY);
+
+            return contentsComparable(l1.iterator(), l2.iterator());
+        }
+        else if (ft == Type.Map && st == Type.Map) {
+            final List l1 = new ArrayList(((Map) f).entrySet());
+            final List l2 = new ArrayList(((Map) s).entrySet());
+            Collections.sort(l1, ORDERABILITY);
+            Collections.sort(l2, ORDERABILITY);
+
+            return contentsComparable(l1.iterator(), l2.iterator());
+        }
+        else if (ft == Type.MapEntry && st == Type.MapEntry) {
+            return comparable(((Map.Entry) f).getKey(), ((Map.Entry) s).getKey()) &&
+                    comparable(((Map.Entry) f).getValue(), ((Map.Entry) s).getValue());
+        }
+        else if (ft == Type.MapEntry && st == Type.MapEntry) {
+            return comparable(((Map.Entry) f).getKey(), ((Map.Entry) s).getKey()) &&
+                    comparable(((Map.Entry) f).getValue(), ((Map.Entry) s).getValue());
+        }

Review Comment:
   ```suggestion
   ```
   Looks like a duplicated case of `MapEntry`. Or did you mean to compare a different type?



-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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

   is this change for 3.8 or 4.0?


-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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

   > is this change for 3.8 or 4.0?
   
   3.8-dev 🤦 


-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/TraversalPredicateVisitorTest.java:
##########
@@ -42,26 +42,26 @@ public class TraversalPredicateVisitorTest {
     @Parameterized.Parameters(name = "{0}")
     public static Iterable<Object[]> generateTestParameters() {
         return Arrays.asList(new Object[][]{
-                {"eq(10)", P.eq(10)},
-                {"neq(1.0f)", P.neq(1.0f)},
-                {"lt(0x11)", P.lt(0x11)},
-                {"lte('abc')", P.lte("abc")},
-                {"gt(1.0D)", P.gt(1d)},
-                {"gte(1L)", P.gte(1L)},
-                {"inside(100, 200)", P.inside(100, 200)},
-                {"outside(1E11, 2e-11)", P.outside(new Double("1E11"), new Double("2e-11"))},
-                {"between(\"a\", \"e\")", P.between("a", "e")},
-                {"within([\"a\", \"e\"])", P.within(Arrays.asList("a", "e"))},
-                {"within()", P.within()},
-                {"without([1, 2])", P.without(Arrays.asList(1, 2))},
-                {"without([1, 2])", P.without(1, 2)},
-                {"without(1, 2)", P.without(1, 2)},
-                {"without(1)", P.without(1)},
-                {"without([1])", P.without(1)},
-                {"without()", P.without()},
-                {"without(1, [1, 2])", P.without(1, Arrays.asList(1, 2))},
-                {"within([1, 2, 3], 1, [1, 2])", P.within(Arrays.asList(1, 2, 3), 1, Arrays.asList(1, 2))},
-                {"not(without(1, 2))", P.not(P.without(1, 2))},
+//                {"eq(10)", P.eq(10)},

Review Comment:
   Note to uncomment these tests given they should be passing.



-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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

   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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/NotP.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+public class NotP<V> extends P<V> {
+    private P<V> originalP;

Review Comment:
   Something feels a bit off about this class. It both wraps P and extends P but it doesn't feel like either is completely needed in this case. It would probably be easier to understand if some changes were made to P itself. Other things that are confusing is that it leads to situations where negate() returns originalP which isn't immediately clear why that would be the case. If this isn't something that you want to address for this PR then just make a short javadoc for this class that has a quick explanation about its design and make a Jira for future refactoring.



-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java:
##########
@@ -395,6 +397,7 @@ public static class SetValueTest {
         private static final String NEQ_FORMAT = "neq(%d)";

Review Comment:
   nit: `NEQ_FORMAT` is now unused. 



-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/binary/types/PSerializer.java:
##########
@@ -153,7 +154,14 @@ protected void writeValue(final T value, final Buffer buffer, final GraphBinaryW
         // the predicate name is either a static method of P or an instance method when a type ConnectiveP
         final boolean isConnectedP = value instanceof ConnectiveP;
         final String predicateName = value.getPredicateName();
-        final Object args = isConnectedP ? ((ConnectiveP<?>) value).getPredicates() : value.getValue();
+        final Object args;
+        if (value instanceof ConnectiveP) {

Review Comment:
   nit: variable `isConnectedP` can be used here or removed



-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java:
##########
@@ -22,6 +22,7 @@
 import org.apache.tinkerpop.gremlin.process.traversal.step.GValue;
 import org.apache.tinkerpop.gremlin.process.traversal.util.AndP;
 import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
+import org.apache.tinkerpop.gremlin.util.GremlinValueComparator;

Review Comment:
   nit: unused



-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/NotP.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+public class NotP<V> extends P<V> {
+    private P<V> originalP;

Review Comment:
   New JIRA for this: https://issues.apache.org/jira/browse/TINKERPOP-3190



-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/binary/types/PSerializer.java:
##########
@@ -153,7 +154,14 @@ protected void writeValue(final T value, final Buffer buffer, final GraphBinaryW
         // the predicate name is either a static method of P or an instance method when a type ConnectiveP
         final boolean isConnectedP = value instanceof ConnectiveP;
         final String predicateName = value.getPredicateName();
-        final Object args = isConnectedP ? ((ConnectiveP<?>) value).getPredicates() : value.getValue();
+        final Object args;
+        if (value instanceof ConnectiveP) {

Review Comment:
   I've dropped the variable



-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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

   Feels like tests with nested operations like NOT (A OR B) might be missing. Essentially tests that show why the ternary logic didn't quite work in the first place.


-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/GremlinValueComparator.java:
##########
@@ -331,17 +307,70 @@ private static boolean naturallyComparable(final Object f, final Object s) {
     /**
      * Return true if the two objects are of the same comparison type (although they may not be the exact same Class)
      */
-    private static boolean comparable(final Object f, final Object s) {
+    public static boolean comparable(final Object f, final Object s) {
         if (f == null || s == null)
             return f == s; // true iff both in the null space
 
+        if (eitherAreNaN(f, s))
+            return false;
+
         final Type ft = Type.type(f);
         final Type st = Type.type(s);
 
+        // if objects are collections or composites, their contents must be mutually comparable
+        if (ft == Type.List && st == Type.List) {

Review Comment:
   is same for arrays?



-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/NotP.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+public class NotP<V> extends P<V> {
+    private P<V> originalP;
+    public NotP(final P<V> p) {
+        super(null, (V) null);
+
+        if (null == p) {
+            throw new IllegalArgumentException("Cannot negate a null P");
+        }
+        this.originalP = p;
+        this.biPredicate = new NotPBiPredicate<>(p.getBiPredicate());
+    }
+
+    /**
+     * Gets the current value to be passed to the predicate for testing.
+     */
+    @Override
+    public V getValue() {
+        return originalP.getValue();
+    }
+
+    @Override
+    public void setValue(final V value) {
+        super.setValue(value);
+        if (originalP != null) {
+            originalP.setValue(value);
+        }
+    }
+
+    @Override
+    public String toString() {
+        return null == this.getValue() ? this.biPredicate.toString() : String.format("not(%s(%s))", this.originalP.biPredicate.toString(), this.getValue());
+    }
+
+    @Override
+    public P<V> negate() {
+        return originalP;
+    }
+
+    public P<V> clone() {
+        return new NotP<>(this.originalP.clone());
+    }
+
+    public static class NotPBiPredicate<T, U> implements PBiPredicate<T, U>, Serializable {
+        PBiPredicate<T, U> original;

Review Comment:
   Nit: final



-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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

   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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/NotP.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+public class NotP<V> extends P<V> {
+    private P<V> originalP;

Review Comment:
   Both wrapping and extending P is a bit weird. This was primarily modeled after ConnectiveP which has a similar structure, although perhaps less odd there given it wraps a collection of P's. P should arguably be refactored as an interface, with ConnectiveP (AndP and OrP), NotP, TextP, and DefaultP as implementations. I will open up a JIRA for such a change.



-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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

   > Feels like tests with nested operations like NOT (A OR B) might be missing. Essentially tests that show why the ternary logic didn't quite work in the first place.
   
   The updated tests in the renamed ComparabilitySemanticsTests provided all of the coverage I wanted to see for this change. I have not looked at special test cases for AndStep, OrStep, P.and, or P,or as none of these have any special handling regarding the new comparability semantics, and are not able to demonstrate the changes.
   
   There were a few existing steps using the NotStep which demonstrate the new semantics, and have been updated accordingly. It's occurred to me however that we don't have a dedicated `Not.feature` file at the moment. I'm not sure why that is, but I can add such a file with basic scenarios as part of this PR.


-- 
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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -144,67 +144,10 @@ Key differences include handling of numeric types and NaN.
 Both Equality and Equivalence can be understood as complete, i.e. the result of equality and equivalence checks is
 always either `TRUE` or `FALSE` (in particular, it never returns `nulltype` or throws an exception). Similarly,
 Orderability can be also understood as complete - any two values can be compared without error for ordering purposes.
-Comparability semantics are not complete with respect to binary boolean semantics, and as such, Gremlin introduces a
-ternary boolean semantics for Comparability that includes a third boolean state - `ERROR`, with its own well-defined
-semantics.
-
-=== Ternary Boolean Logics
-
-When evaluating boolean value expressions, we sometimes encounter situations that cannot be proved as either `TRUE` or
-`FALSE`. Common `ERROR` cases are Comparability against `NaN`, cross-type Comparability (e.g. `String` vs `Numeric`), or
-other invalid arguments to other boolean value expressions.
-
-Rather than throwing an exception and halting the traversal, we extend normal binary boolean logics and introduce a
-third boolean option - `ERROR`. How this `ERROR` result is handled is Graph provider dependent. For the reference
-implementation, `ERROR` is an internal representation only and will not be propagated back to the client as an
-exception - it will eventually hit a binary reduction operation and be reduced to `FALSE` (thus quietly filters the
-solution that produced the `ERROR`). Before that happens though, it will be treated as its own boolean value with its
-own semantics that can be used in other boolean value expressions, such as Connective predicates (`P.and/or`) and
-negation (`P.not`).
-
-==== Ternary Boolean Semantics for `AND`
-
-|===
-|A|B|AND|Intuition
-
-| `TRUE` | `TRUE` | `TRUE` |
-| `TRUE` | `FALSE` | `FALSE` |
-| `TRUE` | `ERROR` | `ERROR` | `TRUE && X == X`
-| `FALSE` | `TRUE` | `FALSE` |
-| `FALSE` | `FALSE` | `FALSE` |
-| `FALSE` | `ERROR` | `FALSE` | `FALSE && X == FALSE`
-| `ERROR` | `TRUE` | `ERROR` | `X && TRUE == X`
-| `ERROR` | `FALSE` | `FALSE` | `X && FALSE == FALSE`
-| `ERROR` | `ERROR` | `ERROR` | `X && X == X`
-|===
-
-==== Ternary Boolean Semantics for `OR`
-
-|===
-|A|B|OR|Intuition
-
-| `TRUE` | `TRUE` | `TRUE` |
-| `TRUE` | `FALSE` | `TRUE` |
-| `TRUE` | `ERROR` | `TRUE` | `TRUE \|\| X == TRUE`
-| `FALSE` | `TRUE` | `TRUE` |
-| `FALSE` | `FALSE` | `FALSE` |
-| `FALSE` | `ERROR` | `ERROR` | `FALSE \|\| X == X`
-| `ERROR` | `TRUE` | `TRUE` | `X \|\| TRUE == TRUE`
-| `ERROR` | `FALSE` | `ERROR` | `X \|\| FALSE == X`
-| `ERROR` | `ERROR` | `ERROR` | `X \|\| X == X`
-|===
-
-==== Ternary Boolean Semantics for `NOT`
-
-The `NOT` predicate inverts `TRUE` and `FALSE`, respectively, but maintains `ERROR` values. The key idea is that, for an
-`ERROR` value, we can neither prove nor disprove the expression, and hence stick with `ERROR`.
-|===
-|Argument | Result
-
-|`TRUE` | `FALSE`
-|`FALSE` | `TRUE`
-|`ERROR` | `ERROR`
-|===
+Comparability semantics are not complete with respect to traditional binary boolean semantics, as certain comparisons
+cannot be proved as either `TRUE` or `FALSE`. Common examples of such cases are Comparability against `NaN`, cross-type
+Comparability (e.g. `String` vs `Numeric`). For the purposes of Comparability within Gremlin, any such incomputable

Review Comment:
   Probably it's worth adding a section on special cases when typecasting (not number type promotion) is performed for comparison, like for element id's 
   `g.V("1")` vs `g.V().id().is("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] [TINKERPOP-3173] Simplify comparability semantics [tinkerpop]

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


##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -144,67 +144,10 @@ Key differences include handling of numeric types and NaN.
 Both Equality and Equivalence can be understood as complete, i.e. the result of equality and equivalence checks is
 always either `TRUE` or `FALSE` (in particular, it never returns `nulltype` or throws an exception). Similarly,
 Orderability can be also understood as complete - any two values can be compared without error for ordering purposes.
-Comparability semantics are not complete with respect to binary boolean semantics, and as such, Gremlin introduces a
-ternary boolean semantics for Comparability that includes a third boolean state - `ERROR`, with its own well-defined
-semantics.
-
-=== Ternary Boolean Logics
-
-When evaluating boolean value expressions, we sometimes encounter situations that cannot be proved as either `TRUE` or
-`FALSE`. Common `ERROR` cases are Comparability against `NaN`, cross-type Comparability (e.g. `String` vs `Numeric`), or
-other invalid arguments to other boolean value expressions.
-
-Rather than throwing an exception and halting the traversal, we extend normal binary boolean logics and introduce a
-third boolean option - `ERROR`. How this `ERROR` result is handled is Graph provider dependent. For the reference
-implementation, `ERROR` is an internal representation only and will not be propagated back to the client as an
-exception - it will eventually hit a binary reduction operation and be reduced to `FALSE` (thus quietly filters the
-solution that produced the `ERROR`). Before that happens though, it will be treated as its own boolean value with its
-own semantics that can be used in other boolean value expressions, such as Connective predicates (`P.and/or`) and
-negation (`P.not`).
-
-==== Ternary Boolean Semantics for `AND`
-
-|===
-|A|B|AND|Intuition
-
-| `TRUE` | `TRUE` | `TRUE` |
-| `TRUE` | `FALSE` | `FALSE` |
-| `TRUE` | `ERROR` | `ERROR` | `TRUE && X == X`
-| `FALSE` | `TRUE` | `FALSE` |
-| `FALSE` | `FALSE` | `FALSE` |
-| `FALSE` | `ERROR` | `FALSE` | `FALSE && X == FALSE`
-| `ERROR` | `TRUE` | `ERROR` | `X && TRUE == X`
-| `ERROR` | `FALSE` | `FALSE` | `X && FALSE == FALSE`
-| `ERROR` | `ERROR` | `ERROR` | `X && X == X`
-|===
-
-==== Ternary Boolean Semantics for `OR`
-
-|===
-|A|B|OR|Intuition
-
-| `TRUE` | `TRUE` | `TRUE` |
-| `TRUE` | `FALSE` | `TRUE` |
-| `TRUE` | `ERROR` | `TRUE` | `TRUE \|\| X == TRUE`
-| `FALSE` | `TRUE` | `TRUE` |
-| `FALSE` | `FALSE` | `FALSE` |
-| `FALSE` | `ERROR` | `ERROR` | `FALSE \|\| X == X`
-| `ERROR` | `TRUE` | `TRUE` | `X \|\| TRUE == TRUE`
-| `ERROR` | `FALSE` | `ERROR` | `X \|\| FALSE == X`
-| `ERROR` | `ERROR` | `ERROR` | `X \|\| X == X`
-|===
-
-==== Ternary Boolean Semantics for `NOT`
-
-The `NOT` predicate inverts `TRUE` and `FALSE`, respectively, but maintains `ERROR` values. The key idea is that, for an
-`ERROR` value, we can neither prove nor disprove the expression, and hence stick with `ERROR`.
-|===
-|Argument | Result
-
-|`TRUE` | `FALSE`
-|`FALSE` | `TRUE`
-|`ERROR` | `ERROR`
-|===
+Comparability semantics are not complete with respect to traditional binary boolean semantics, as certain comparisons
+cannot be proved as either `TRUE` or `FALSE`. Common examples of such cases are Comparability against `NaN`, cross-type
+Comparability (e.g. `String` vs `Numeric`). For the purposes of Comparability within Gremlin, any such incomputable

Review Comment:
   I'd prefer to leave this out of this section of the docs. The parsing of Strings is really a special implementation detail of the Integer IdManager in TinkerGraph. As far as gremlin itself is concerned, `g.V("1")` is looking for a vertex with a String id `"1"`. If this needs documentation I would rather it be listed as some special sugar in TinkerGraph, rather than an exception outlined here in the comparability semantics docs.



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