You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by "Cole Greer (Jira)" <ji...@apache.org> on 2023/04/11 22:38:00 UTC
[jira] [Commented] (TINKERPOP-2904) Forget to throw GremlinTypeErrorException when using is(predicate) to compare NaN
[ https://issues.apache.org/jira/browse/TINKERPOP-2904?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17711135#comment-17711135 ]
Cole Greer commented on TINKERPOP-2904:
---------------------------------------
I took a quick look here and I believe this is the expected behaviour. `GremlinTypeErrorException` is part of the new ternary boolean logic introduced in 3.6 which is detailed [here|[https://tinkerpop.apache.org/docs/current/dev/provider/#_ternary_boolean_logics].] `GremlinTypeErrorException` represents the error state of the ternary boolean.
Pulling a quote from the docs:
{panel}
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{}}}).
{panel}
In the reference implementation the `GremlinTypeErrorException` is only intended to be used internally and should be swallowed before results are returned. The expected result of `g.inject(Double.NaN).is(gt(3))` is null. `NaN>3` evaluates to `Error` which reduces to `False`.
> Forget to throw GremlinTypeErrorException when using is(predicate) to compare NaN
> ----------------------------------------------------------------------------------
>
> Key: TINKERPOP-2904
> URL: https://issues.apache.org/jira/browse/TINKERPOP-2904
> Project: TinkerPop
> Issue Type: Bug
> Components: process
> Affects Versions: 3.5.5
> Reporter: Miracy Cavendish
> Priority: Critical
>
> By the design of Gremlin, an exception should be thrown when compared with NaN.
> However, I found that when using ```is(predicate)``` to compare, the exception is always swallowed, and this issue occurs on all GDBs support Gremlin, such as "g.inject(Double.NaN).is(gt(3))"
> {code:java}
> public static final GremlinValueComparator COMPARABILITY = new GremlinValueComparator() {
> /**
> * Compare two Gremlin value objects per the Comparability semantics. Throws type errors for NaN comparison
> * and for cross-type comparison (including nulltype).
> *
> * Use this method for P.lt/lte/gt/gte.
> */
> @Override
> public int compare(final Object f, final Object s) {
> // For Compare, NaN always produces ERROR
> if (eitherAreNaN(f, s))
> throwTypeError();
> // For Compare we do not cross type boundaries, including null
> if (!comparable(f, s))
> throwTypeError();
> // comparable(f, s) assures that type(f) == type(s)
> final Type type = Type.type(f);
> return comparator(type).compare(f, s);
> }
> ... {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)