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/07/08 21:25:02 UTC
[PR] Implement asBool() step [tinkerpop]
xiazcy opened a new pull request, #3154:
URL: https://github.com/apache/tinkerpop/pull/3154
Implementation of the boolean parsing step `asBool()` as outlined in the [proposal](https://github.com/apache/tinkerpop/blob/3.8-dev/docs/src/dev/future/proposal-asbool-step-7.asciidoc).
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] Implement asBool() step [tinkerpop]
Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2200836344
##########
docs/src/upgrade/release-3.8.x.asciidoc:
##########
@@ -30,6 +30,35 @@ complete list of all the modifications that are part of this release.
=== Upgrading for Users
+==== Boolean Conversion Step
+
+We have introduced a boolean conversion step, `asBool()`, which converts the incoming traverser to a boolean value.
+Numbers evaluate to `true` when non-zero (and not `NaN`), `null` evaluates to `null`. Strings are only accepted when
+equal to `"true"` or `"false"` (case-insensitive), otherwise `null` will be returned.
+All other types will throw an `IllegalArgumentException`.
+
+[source,text]
+----
+gremlin> g.inject(5).asBool()
+==> true
+gremlin> g.inject(5.0).asBool()
+==> true
+gremlin> g.inject(0).asBool()
+==> false
+gremlin> g.inject(0.0).asBool()
+==> false
+gremlin> g.inject("true").asBool()
+==> true
+gremlin> g.inject("123hello").asBool()
+==> null
+gremlin> g.inject(null).asBool()
+==> null
+gremlin> g.inject([1, 2, 3, 4]).asBool()
+==> IllegalArgumentException
+----
+
+See: link:https://tinkerpop.apache.org/docs/3.8.0/reference/#asBool-step[asBool()-step]
Review Comment:
Just added https://issues.apache.org/jira/browse/TINKERPOP-3175
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2193625471
##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/AsBool.feature:
##########
Review Comment:
Can you add tests for boolean types for example: `g.inject(true).asBool()` and `g.inject(false).asBool()`?
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2193626113
##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/AsBool.feature:
##########
@@ -0,0 +1,114 @@
+# 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.
+
+@StepClassMap @StepAsBool
+Feature: Step - asBool()
+
+ @GraphComputerVerificationInjectionNotSupported
+ Scenario: g_injectX1X_asBool
+ Given the empty graph
+ And the traversal of
+ """
+ g.inject(1).asBool()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | true |
+
+ @GraphComputerVerificationInjectionNotSupported
+ Scenario: g_injectXneg_1X_asBool
+ Given the empty graph
+ And the traversal of
+ """
+ g.inject(-1).asBool()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | true |
+
+ @GraphComputerVerificationInjectionNotSupported
+ Scenario: g_injectX0X_asBool
+ Given the empty graph
+ And the traversal of
+ """
+ g.inject(0).asBool()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | false |
+
+ @GraphComputerVerificationInjectionNotSupported
+ Scenario: g_injectXneg_0X_asBool
+ Given the empty graph
+ And the traversal of
+ """
+ g.inject(-0.0).asBool()
Review Comment:
Can you add a test for non-zero with decimal ie. `3.14`?
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2193546289
##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -776,6 +776,32 @@ None
See: link:https://github.com/apache/tinkerpop/tree/x.y.z/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java[source],
link:https://tinkerpop.apache.org/docs/x.y.z/reference/#as-step[reference]
+[[asBool-step]]
+=== asBool()
+
+*Description:* Parse the value of the incoming traverser as boolean.
+
+*Syntax:* `asBool()`
+
+[width="100%",options="header"]
+|=========================================================
+|Start Step |Mid Step |Modulated |Domain |Range
+|N |Y |N |`Number`/`String`/`null` |`boolean`
+|=========================================================
+
+*Arguments:*
+
+None
+
+`null` values return `null`, numbers evaluate to `true` if non-zero. Strings only accept "true" or "false", any other strings will return `null`.
+
+*Exceptions*
+
+If the incoming traverser type is unsupported or a string other than "true" or "false" then an `IllegalArgumentException` is thrown.
+
+See: link:https://github.com/apache/tinkerpop/tree/x.y.z/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsBoolStep.java[source],
Review Comment:
This seems to be a broken link and similar links that reference `tree/x.y.z` in other areas of this doc do not even work in `master` or `-dev` branches.
--
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] Implement asBool() step [tinkerpop]
Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2198534736
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java:
##########
@@ -1852,6 +1853,17 @@ public default GraphTraversal<S, String> format(final String format) {
return this.asAdmin().addStep(new FormatStep<>(this.asAdmin(), format));
}
+ /**
+ * Parse the incoming traverser as a boolean value.
+ *
+ * @return the traversal with an appended {@link AsBoolStep}.
+ * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#asBool-step" target="_blank">Reference Documentation - asBool Step</a>
Review Comment:
```suggestion
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#asBool-step" target="_blank">Reference Documentation - asBool Step</a>
* @since 3.8.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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2193546289
##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -776,6 +776,32 @@ None
See: link:https://github.com/apache/tinkerpop/tree/x.y.z/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java[source],
link:https://tinkerpop.apache.org/docs/x.y.z/reference/#as-step[reference]
+[[asBool-step]]
+=== asBool()
+
+*Description:* Parse the value of the incoming traverser as boolean.
+
+*Syntax:* `asBool()`
+
+[width="100%",options="header"]
+|=========================================================
+|Start Step |Mid Step |Modulated |Domain |Range
+|N |Y |N |`Number`/`String`/`null` |`boolean`
+|=========================================================
+
+*Arguments:*
+
+None
+
+`null` values return `null`, numbers evaluate to `true` if non-zero. Strings only accept "true" or "false", any other strings will return `null`.
+
+*Exceptions*
+
+If the incoming traverser type is unsupported or a string other than "true" or "false" then an `IllegalArgumentException` is thrown.
+
+See: link:https://github.com/apache/tinkerpop/tree/x.y.z/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsBoolStep.java[source],
Review Comment:
This seems to be a broken link and similar links that reference `tree/x.y.z` in other areas of this doc do not even work in `master` or `-dev` branches.
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2193624250
##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/AsBool.feature:
##########
@@ -0,0 +1,114 @@
+# 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.
+
+@StepClassMap @StepAsBool
+Feature: Step - asBool()
+
+ @GraphComputerVerificationInjectionNotSupported
+ Scenario: g_injectX1X_asBool
+ Given the empty graph
+ And the traversal of
+ """
+ g.inject(1).asBool()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | true |
+
+ @GraphComputerVerificationInjectionNotSupported
+ Scenario: g_injectXneg_1X_asBool
+ Given the empty graph
+ And the traversal of
+ """
+ g.inject(-1).asBool()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | true |
+
+ @GraphComputerVerificationInjectionNotSupported
+ Scenario: g_injectX0X_asBool
+ Given the empty graph
+ And the traversal of
+ """
+ g.inject(0).asBool()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | false |
+
+ @GraphComputerVerificationInjectionNotSupported
+ Scenario: g_injectXneg_0X_asBool
+ Given the empty graph
+ And the traversal of
+ """
+ g.inject(-0.0).asBool()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | false |
+
+ @GraphComputerVerificationInjectionNotSupported
+ Scenario: g_injectXtrueX_asBool
+ Given the empty graph
+ And the traversal of
+ """
+ g.inject('true').asBool()
Review Comment:
Can you add a test to check for case insensitivity?
--
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] Implement asBool() step [tinkerpop]
Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2226726434
##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -776,6 +776,32 @@ None
See: link:https://github.com/apache/tinkerpop/tree/x.y.z/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java[source],
link:https://tinkerpop.apache.org/docs/x.y.z/reference/#as-step[reference]
+[[asBool-step]]
+=== asBool()
+
+*Description:* Parse the value of the incoming traverser as boolean.
+
+*Syntax:* `asBool()`
+
+[width="100%",options="header"]
+|=========================================================
+|Start Step |Mid Step |Modulated |Domain |Range
+|N |Y |N |`Number`/`String`/`null` |`Boolean`
+|=========================================================
+
+*Arguments:*
+
+None
+
+`null` values return `null`, numbers evaluate to `true` if non-zero. Strings only accept "true" or "false" (case-insensitive).
+
+*Exceptions*
+
+If the incoming traverser type is unsupported or a string other than "true" or "false" then an `IllegalArgumentException` is thrown.
Review Comment:
```suggestion
If the incoming traverser type is unsupported, a string other than "true" or "false", or a `null` then an `IllegalArgumentException` is thrown.
```
--
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] Implement asBool() step [tinkerpop]
Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2236900753
##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/translator/GremlinTranslatorTest.java:
##########
@@ -731,6 +731,15 @@ public static Collection<Object[]> data() {
"Java does not support range literals",
"Javascript does not support range literals",
"Python does not support range literals"},
+ {"g.inject(1).asBool()",
+ null,
+ "g.inject(number0).asBool()",
+ "g.Inject<object>(1).AsBool()",
+ "g.Inject(1).AsBool()",
+ null,
+ null,
+ null,
Review Comment:
I believe it's b/c they don't differ from the expected one, but I've added them anyways.
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2195338920
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsBoolStep.java:
##########
Review Comment:
Should override both `hashCode` and `equals` methods.
--
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] Implement asBool() step [tinkerpop]
Posted by "spmallette (via GitHub)" <gi...@apache.org>.
spmallette commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2195535069
##########
docs/src/upgrade/release-3.8.x.asciidoc:
##########
@@ -30,6 +30,35 @@ complete list of all the modifications that are part of this release.
=== Upgrading for Users
+==== Boolean Conversion Step
Review Comment:
Please revise the content here a bit to read a bit more like an announcement rather than the documentation itself. and rather than present all the possible ways it works, maybe just have a good example where it might be helpful and you'd be stuck beforehand.
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2193547614
##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -776,6 +776,32 @@ None
See: link:https://github.com/apache/tinkerpop/tree/x.y.z/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java[source],
link:https://tinkerpop.apache.org/docs/x.y.z/reference/#as-step[reference]
+[[asBool-step]]
+=== asBool()
+
+*Description:* Parse the value of the incoming traverser as boolean.
+
+*Syntax:* `asBool()`
+
+[width="100%",options="header"]
+|=========================================================
+|Start Step |Mid Step |Modulated |Domain |Range
+|N |Y |N |`Number`/`String`/`null` |`boolean`
+|=========================================================
+
+*Arguments:*
+
+None
+
+`null` values return `null`, numbers evaluate to `true` if non-zero. Strings only accept "true" or "false", any other strings will return `null`.
Review Comment:
Should mention if the strings are case sensitive or not.
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2193619739
##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsBoolStepTest.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
+import org.junit.Test;
+
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class AsBoolStepTest extends StepTest {
+
+ @Override
+ protected List<Traversal> getTraversals() {
+ return Collections.singletonList(__.asBool());
+ }
+
+ @Test
+ public void shouldParseBoolean() {
+ assertEquals(true, __.__(-1).asBool().next());
+ assertEquals(false, __.__(0).asBool().next());
+ assertEquals(true, __.__(1).asBool().next());
+ assertEquals(true, __.__(3.14).asBool().next());
+ assertEquals(true, __.__(new BigInteger("1000000000000000000000")).asBool().next());
+ assertEquals(true, __.__("TRUE").asBool().next());
+ assertEquals(false, __.__("false").asBool().next());
+ assertNull(__.__(Double.NaN).asBool().next());
Review Comment:
Suggest also adding the following tests:
```
assertEquals(false, __.__(0.0).asBool().next());
assertNull(__.__(Float.NaN).asBool().next());
assertNull(__.__("").asBool().next());
```
--
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] Implement asBool() step [tinkerpop]
Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2195097682
##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/translator/GremlinTranslatorTest.java:
##########
@@ -731,6 +731,15 @@ public static Collection<Object[]> data() {
"Java does not support range literals",
"Javascript does not support range literals",
"Python does not support range literals"},
+ {"g.inject(1).asBool()",
+ null,
+ "g.inject(number0).asBool()",
+ "g.Inject<object>(1).AsBool()",
+ "g.Inject(1).AsBool()",
+ null,
+ null,
+ null,
Review Comment:
Oh yes good catch, I'll populate that.
--
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] Implement asBool() step [tinkerpop]
Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2200836847
##########
docs/src/reference/the-traversal.asciidoc:
##########
@@ -804,6 +804,27 @@ g.V().hasLabel('person').values('age').fold().asString(local) <3>
link:++https://tinkerpop.apache.org/javadocs/x.y.z/core/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.html#asString()++[`asString()`]
link:++https://tinkerpop.apache.org/javadocs/x.y.z/core/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.html#asString(org.apache.tinkerpop.gremlin.process.traversal.Scope)++[`asString(Scope)`]
+[[asBool-step]]
+=== AsBool Step
+
+The `asBool()`-step (*map*) converts the incoming traverser to a boolean value. Numbers evaluate to
+`true` when non-zero (and not `NaN`), `null` evaluates to `null`. Strings are only accepted when
+equal to `"true"` or `"false"` (case-insensitive), otherwise `null` will be returned.
Review Comment:
Ah yes, semantics docs was a miss.
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2193555258
##########
docs/src/reference/the-traversal.asciidoc:
##########
@@ -804,6 +804,27 @@ g.V().hasLabel('person').values('age').fold().asString(local) <3>
link:++https://tinkerpop.apache.org/javadocs/x.y.z/core/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.html#asString()++[`asString()`]
link:++https://tinkerpop.apache.org/javadocs/x.y.z/core/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.html#asString(org.apache.tinkerpop.gremlin.process.traversal.Scope)++[`asString(Scope)`]
+[[asBool-step]]
+=== AsBool Step
+
+The `asBool()`-step (*map*) converts the incoming traverser to a boolean value. Numbers evaluate to
+`true` when non-zero (and not `NaN`), `null` evaluates to `null`. Strings are only accepted when
+equal to `"true"` or `"false"` (case-insensitive), otherwise `null` will be returned.
Review Comment:
Does this mean `g.inject("foo").asBool()` will return null? Should provide an example of such. Since users will be referencing this documentation more than docs/src/upgrade/release-3.8.x.asciidoc it would be helpful to copy more of the examples from the upgrade doc to this one.
--
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] Implement asBool() step [tinkerpop]
Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2198769847
##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsBoolStepTest.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
+import org.junit.Test;
+
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class AsBoolStepTest extends StepTest {
+
+ @Override
+ protected List<Traversal> getTraversals() {
+ return Collections.singletonList(__.asBool());
+ }
+
+ @Test
+ public void shouldParseBoolean() {
+ assertEquals(true, __.__(-1).asBool().next());
+ assertEquals(false, __.__(0).asBool().next());
+ assertEquals(true, __.__(1).asBool().next());
+ assertEquals(true, __.__(3.14).asBool().next());
+ assertEquals(true, __.__(new BigInteger("1000000000000000000000")).asBool().next());
+ assertEquals(true, __.__("TRUE").asBool().next());
+ assertEquals(false, __.__("false").asBool().next());
+ assertNull(__.__(Double.NaN).asBool().next());
+ assertNull(__.__((Object) null).asBool().next());
+ assertNull(__.__("hello world").asBool().next());
+ assertNull(__.__("1").asBool().next());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void shouldThrowOnInvalidString() {
Review Comment:
```suggestion
public void shouldThrowOnInvalidInput) {
```
Where did we land regarding strings such as `"not a bool"`, if that throws an error that should be included here as well.
--
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] Implement asBool() step [tinkerpop]
Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2200841794
##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsBoolStepTest.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
+import org.junit.Test;
+
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class AsBoolStepTest extends StepTest {
+
+ @Override
+ protected List<Traversal> getTraversals() {
+ return Collections.singletonList(__.asBool());
+ }
+
+ @Test
+ public void shouldParseBoolean() {
+ assertEquals(true, __.__(-1).asBool().next());
+ assertEquals(false, __.__(0).asBool().next());
+ assertEquals(true, __.__(1).asBool().next());
+ assertEquals(true, __.__(3.14).asBool().next());
+ assertEquals(true, __.__(new BigInteger("1000000000000000000000")).asBool().next());
+ assertEquals(true, __.__("TRUE").asBool().next());
+ assertEquals(false, __.__("false").asBool().next());
+ assertNull(__.__(Double.NaN).asBool().next());
Review Comment:
Some of these are covered by feature tests so I didn't add here (and vice versa), but I'll duplicate them for better coverage.
--
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] Implement asBool() step [tinkerpop]
Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer commented on PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#issuecomment-3130134992
For reference: [TINKERPOP-3175](https://issues.apache.org/jira/browse/TINKERPOP-3175)
--
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] Implement asBool() step [tinkerpop]
Posted by "spmallette (via GitHub)" <gi...@apache.org>.
spmallette commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2195532446
##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -776,6 +776,32 @@ None
See: link:https://github.com/apache/tinkerpop/tree/x.y.z/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java[source],
link:https://tinkerpop.apache.org/docs/x.y.z/reference/#as-step[reference]
+[[asBool-step]]
+=== asBool()
+
+*Description:* Parse the value of the incoming traverser as boolean.
+
+*Syntax:* `asBool()`
+
+[width="100%",options="header"]
+|=========================================================
+|Start Step |Mid Step |Modulated |Domain |Range
+|N |Y |N |`Number`/`String`/`null` |`boolean`
+|=========================================================
+
+*Arguments:*
+
+None
+
+`null` values return `null`, numbers evaluate to `true` if non-zero. Strings only accept "true" or "false", any other strings will return `null`.
+
+*Exceptions*
+
+If the incoming traverser type is unsupported or a string other than "true" or "false" then an `IllegalArgumentException` is thrown.
Review Comment:
For future thoughts - should the semantics doc be Java centric? not sure what it should be for "Exceptions" but might want to do that differently going forward, particularly for 4.x
--
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] Implement asBool() step [tinkerpop]
Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2195097682
##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/translator/GremlinTranslatorTest.java:
##########
@@ -731,6 +731,15 @@ public static Collection<Object[]> data() {
"Java does not support range literals",
"Javascript does not support range literals",
"Python does not support range literals"},
+ {"g.inject(1).asBool()",
+ null,
+ "g.inject(number0).asBool()",
+ "g.Inject<object>(1).AsBool()",
+ "g.Inject(1).AsBool()",
+ null,
+ null,
+ null,
Review Comment:
Oh yes good catch, I'll populate that.
--
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] Implement asBool() step [tinkerpop]
Posted by "spmallette (via GitHub)" <gi...@apache.org>.
spmallette commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2195536183
##########
docs/src/upgrade/release-3.8.x.asciidoc:
##########
@@ -30,6 +30,35 @@ complete list of all the modifications that are part of this release.
=== Upgrading for Users
+==== Boolean Conversion Step
+
+We have introduced a boolean conversion step, `asBool()`, which converts the incoming traverser to a boolean value.
+Numbers evaluate to `true` when non-zero (and not `NaN`), `null` evaluates to `null`. Strings are only accepted when
+equal to `"true"` or `"false"` (case-insensitive), otherwise `null` will be returned.
+All other types will throw an `IllegalArgumentException`.
+
+[source,text]
+----
+gremlin> g.inject(5).asBool()
+==> true
+gremlin> g.inject(5.0).asBool()
+==> true
+gremlin> g.inject(0).asBool()
+==> false
+gremlin> g.inject(0.0).asBool()
+==> false
+gremlin> g.inject("true").asBool()
+==> true
+gremlin> g.inject("123hello").asBool()
+==> null
+gremlin> g.inject(null).asBool()
+==> null
+gremlin> g.inject([1, 2, 3, 4]).asBool()
+==> IllegalArgumentException
+----
+
+See: link:https://tinkerpop.apache.org/docs/3.8.0/reference/#asBool-step[asBool()-step]
Review Comment:
is there a JIRA for this?
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#issuecomment-3130087230
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2193615744
##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/translator/GremlinTranslatorTest.java:
##########
@@ -731,6 +731,15 @@ public static Collection<Object[]> data() {
"Java does not support range literals",
"Javascript does not support range literals",
"Python does not support range literals"},
+ {"g.inject(1).asBool()",
+ null,
+ "g.inject(number0).asBool()",
+ "g.Inject<object>(1).AsBool()",
+ "g.Inject(1).AsBool()",
+ null,
+ null,
+ null,
Review Comment:
Why are the Java, groovy, javascript translations null?
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2193555258
##########
docs/src/reference/the-traversal.asciidoc:
##########
@@ -804,6 +804,27 @@ g.V().hasLabel('person').values('age').fold().asString(local) <3>
link:++https://tinkerpop.apache.org/javadocs/x.y.z/core/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.html#asString()++[`asString()`]
link:++https://tinkerpop.apache.org/javadocs/x.y.z/core/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.html#asString(org.apache.tinkerpop.gremlin.process.traversal.Scope)++[`asString(Scope)`]
+[[asBool-step]]
+=== AsBool Step
+
+The `asBool()`-step (*map*) converts the incoming traverser to a boolean value. Numbers evaluate to
+`true` when non-zero (and not `NaN`), `null` evaluates to `null`. Strings are only accepted when
+equal to `"true"` or `"false"` (case-insensitive), otherwise `null` will be returned.
Review Comment:
Does this mean `g.inject("foo").asBool()` will return null? Should provide an example of such.
--
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] Implement asBool() step [tinkerpop]
Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2200833238
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsBoolStep.java:
##########
Review Comment:
The `hashCode` function would be identical though? There are no additional variables for the step.
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2230138316
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsBoolStep.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Reference implementation for boolean parsing step.
+ */
+public final class AsBoolStep<S> extends ScalarMapStep<S, Boolean> {
+
+ public AsBoolStep(final Traversal.Admin traversal) {
+ super(traversal);
+ }
+
+ @Override
+ protected Boolean map(final Traverser.Admin<S> traverser) {
+ final Object object = traverser.get();
+ if (object == null) throw new IllegalArgumentException("Can't parse null as Boolean.");
+ if (object instanceof Boolean) return (Boolean) object;
+ if (object instanceof Number) {
+ final double d = ((Number) object).doubleValue();
+ if (Double.isNaN(d)) return null;
+ return d != 0d;
+ }
+ if (object instanceof String) {
+ final String str = (String) object;
Review Comment:
Nit: should also call `str.trim()`
--
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] Implement asBool() step [tinkerpop]
Posted by "xiazcy (via GitHub)" <gi...@apache.org>.
xiazcy merged PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154
--
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] Implement asBool() step [tinkerpop]
Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2226728991
##########
docs/src/reference/the-traversal.asciidoc:
##########
@@ -804,6 +804,27 @@ g.V().hasLabel('person').values('age').fold().asString(local) <3>
link:++https://tinkerpop.apache.org/javadocs/x.y.z/core/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.html#asString()++[`asString()`]
link:++https://tinkerpop.apache.org/javadocs/x.y.z/core/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.html#asString(org.apache.tinkerpop.gremlin.process.traversal.Scope)++[`asString(Scope)`]
+[[asBool-step]]
+=== AsBool Step
+
+The `asBool()`-step (*map*) converts the incoming traverser to a boolean value. Numbers evaluate to
+`true` when non-zero (and not `NaN`). Strings are only accepted when
+equal to `"true"` or `"false"` (case-insensitive), otherwise an `IllegalArgumentException` is thrown.
+All other types (including `null`) will throw an `IllegalArgumentException`.
Review Comment:
```suggestion
The `asBool()`-step (*map*) converts the incoming traverser to a boolean value. If the traverser is
already a boolean value, it is passed as-is. Numbers evaluate to
`true` when non-zero (and not `NaN`). Strings are only accepted when
equal to `"true"` or `"false"` (case-insensitive), otherwise an `IllegalArgumentException` is thrown.
All other types (including `null`) will throw an `IllegalArgumentException`.
```
--
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] Implement asBool() step [tinkerpop]
Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2226726434
##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -776,6 +776,32 @@ None
See: link:https://github.com/apache/tinkerpop/tree/x.y.z/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java[source],
link:https://tinkerpop.apache.org/docs/x.y.z/reference/#as-step[reference]
+[[asBool-step]]
+=== asBool()
+
+*Description:* Parse the value of the incoming traverser as boolean.
+
+*Syntax:* `asBool()`
+
+[width="100%",options="header"]
+|=========================================================
+|Start Step |Mid Step |Modulated |Domain |Range
+|N |Y |N |`Number`/`String`/`null` |`Boolean`
+|=========================================================
+
+*Arguments:*
+
+None
+
+`null` values return `null`, numbers evaluate to `true` if non-zero. Strings only accept "true" or "false" (case-insensitive).
+
+*Exceptions*
+
+If the incoming traverser type is unsupported or a string other than "true" or "false" then an `IllegalArgumentException` is thrown.
Review Comment:
```suggestion
If the incoming traverser type is unsupported, a string other than "true" or "false", or `null`, then an `IllegalArgumentException` is thrown.
```
--
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] Implement asBool() step [tinkerpop]
Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer commented on PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#issuecomment-3110231761
VOTE +1 (pending resolution of above comments)
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2230138316
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsBoolStep.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Reference implementation for boolean parsing step.
+ */
+public final class AsBoolStep<S> extends ScalarMapStep<S, Boolean> {
+
+ public AsBoolStep(final Traversal.Admin traversal) {
+ super(traversal);
+ }
+
+ @Override
+ protected Boolean map(final Traverser.Admin<S> traverser) {
+ final Object object = traverser.get();
+ if (object == null) throw new IllegalArgumentException("Can't parse null as Boolean.");
+ if (object instanceof Boolean) return (Boolean) object;
+ if (object instanceof Number) {
+ final double d = ((Number) object).doubleValue();
+ if (Double.isNaN(d)) return null;
+ return d != 0d;
+ }
+ if (object instanceof String) {
+ final String str = (String) object;
Review Comment:
Nit: should also call `str.trim()`
Or maybe not since other steps that parse string (like asDate) do not trim...
--
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] Implement asBool() step [tinkerpop]
Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2198541273
##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsBoolStepTest.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
+import org.junit.Test;
+
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class AsBoolStepTest extends StepTest {
+
+ @Override
+ protected List<Traversal> getTraversals() {
+ return Collections.singletonList(__.asBool());
+ }
+
+ @Test
+ public void shouldParseBoolean() {
+ assertEquals(true, __.__(-1).asBool().next());
+ assertEquals(false, __.__(0).asBool().next());
+ assertEquals(true, __.__(1).asBool().next());
+ assertEquals(true, __.__(3.14).asBool().next());
+ assertEquals(true, __.__(new BigInteger("1000000000000000000000")).asBool().next());
+ assertEquals(true, __.__("TRUE").asBool().next());
+ assertEquals(false, __.__("false").asBool().next());
+ assertNull(__.__(Double.NaN).asBool().next());
Review Comment:
`assertEquals(false, __.__(-0.0).asBool().next());` would be a good case as well
--
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] Implement asBool() step [tinkerpop]
Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2198532171
##########
docs/src/reference/the-traversal.asciidoc:
##########
@@ -804,6 +804,27 @@ g.V().hasLabel('person').values('age').fold().asString(local) <3>
link:++https://tinkerpop.apache.org/javadocs/x.y.z/core/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.html#asString()++[`asString()`]
link:++https://tinkerpop.apache.org/javadocs/x.y.z/core/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.html#asString(org.apache.tinkerpop.gremlin.process.traversal.Scope)++[`asString(Scope)`]
+[[asBool-step]]
+=== AsBool Step
+
+The `asBool()`-step (*map*) converts the incoming traverser to a boolean value. Numbers evaluate to
+`true` when non-zero (and not `NaN`), `null` evaluates to `null`. Strings are only accepted when
+equal to `"true"` or `"false"` (case-insensitive), otherwise `null` will be returned.
Review Comment:
This contradicts the `Exceptions` section in the 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
Re: [PR] Implement asBool() step [tinkerpop]
Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2226725411
##########
docs/src/dev/provider/gremlin-semantics.asciidoc:
##########
@@ -776,6 +776,32 @@ None
See: link:https://github.com/apache/tinkerpop/tree/x.y.z/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java[source],
link:https://tinkerpop.apache.org/docs/x.y.z/reference/#as-step[reference]
+[[asBool-step]]
+=== asBool()
+
+*Description:* Parse the value of the incoming traverser as boolean.
+
+*Syntax:* `asBool()`
+
+[width="100%",options="header"]
+|=========================================================
+|Start Step |Mid Step |Modulated |Domain |Range
+|N |Y |N |`Number`/`String`/`null` |`Boolean`
+|=========================================================
+
+*Arguments:*
+
+None
+
+`null` values return `null`, numbers evaluate to `true` if non-zero. Strings only accept "true" or "false" (case-insensitive).
Review Comment:
```suggestion
|N |Y |N |`Number`/`String`/`Boolean` |`Boolean`
|=========================================================
*Arguments:*
None
Booleans are passed as is, numbers evaluate to `true` if non-zero. Strings only accept "true" or "false" (case-insensitive).
```
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2230137142
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsBoolStep.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Reference implementation for boolean parsing step.
+ */
+public final class AsBoolStep<S> extends ScalarMapStep<S, Boolean> {
+
+ public AsBoolStep(final Traversal.Admin traversal) {
+ super(traversal);
+ }
+
+ @Override
+ protected Boolean map(final Traverser.Admin<S> traverser) {
+ final Object object = traverser.get();
+ if (object == null) throw new IllegalArgumentException("Can't parse null as Boolean.");
+ if (object instanceof Boolean) return (Boolean) object;
+ if (object instanceof Number) {
+ final double d = ((Number) object).doubleValue();
+ if (Double.isNaN(d)) return null;
Review Comment:
Should this return false instead?
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2193615744
##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/translator/GremlinTranslatorTest.java:
##########
@@ -731,6 +731,15 @@ public static Collection<Object[]> data() {
"Java does not support range literals",
"Javascript does not support range literals",
"Python does not support range literals"},
+ {"g.inject(1).asBool()",
+ null,
+ "g.inject(number0).asBool()",
+ "g.Inject<object>(1).AsBool()",
+ "g.Inject(1).AsBool()",
+ null,
+ null,
+ null,
Review Comment:
Why is the javascript translation null?
--
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] Implement asBool() step [tinkerpop]
Posted by "Cole-Greer (via GitHub)" <gi...@apache.org>.
Cole-Greer commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2198769847
##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsBoolStepTest.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
+import org.junit.Test;
+
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class AsBoolStepTest extends StepTest {
+
+ @Override
+ protected List<Traversal> getTraversals() {
+ return Collections.singletonList(__.asBool());
+ }
+
+ @Test
+ public void shouldParseBoolean() {
+ assertEquals(true, __.__(-1).asBool().next());
+ assertEquals(false, __.__(0).asBool().next());
+ assertEquals(true, __.__(1).asBool().next());
+ assertEquals(true, __.__(3.14).asBool().next());
+ assertEquals(true, __.__(new BigInteger("1000000000000000000000")).asBool().next());
+ assertEquals(true, __.__("TRUE").asBool().next());
+ assertEquals(false, __.__("false").asBool().next());
+ assertNull(__.__(Double.NaN).asBool().next());
+ assertNull(__.__((Object) null).asBool().next());
+ assertNull(__.__("hello world").asBool().next());
+ assertNull(__.__("1").asBool().next());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void shouldThrowOnInvalidString() {
Review Comment:
```suggestion
public void shouldThrowOnInvalidType() {
```
--
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] Implement asBool() step [tinkerpop]
Posted by "spmallette (via GitHub)" <gi...@apache.org>.
spmallette commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2195538857
##########
gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/map/AsBool.feature:
##########
@@ -0,0 +1,114 @@
+# 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.
+
+@StepClassMap @StepAsBool
Review Comment:
please consider some more practical tests beyond just `inject`.
--
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] Implement asBool() step [tinkerpop]
Posted by "andreachild (via GitHub)" <gi...@apache.org>.
andreachild commented on code in PR #3154:
URL: https://github.com/apache/tinkerpop/pull/3154#discussion_r2195338920
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AsBoolStep.java:
##########
Review Comment:
Should override both `hashCode` and `equals` methods as the parent default ones should not be used.
--
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