This is an automated email from the ASF dual-hosted git repository. xiazcy pushed a commit to branch type-enum-poc in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 20827f80c3bb4211d3c8c5ff4bd32100e776ad55 Merge: 01c2d78ec1 f8dd8c1ba0 Author: Yang Xia <55853655+xia...@users.noreply.github.com> AuthorDate: Tue Jul 8 17:08:33 2025 -0400 Merge branch '3.8-dev' into TINKERPOP-3166_asNumber CHANGELOG.asciidoc | 2 + docs/src/upgrade/release-3.8.x.asciidoc | 33 +++++++++++- gremlin-annotations/pom.xml | 30 ++--------- .../src/main/resources/archetype-resources/pom.xml | 31 ++--------- .../src/main/resources/archetype-resources/pom.xml | 31 ++--------- .../src/main/resources/archetype-resources/pom.xml | 31 ++--------- .../gremlin/language/grammar/ArgumentVisitor.java | 16 ------ .../grammar/DefaultGremlinBaseVisitor.java | 12 +---- .../language/grammar/GenericLiteralVisitor.java | 5 -- .../language/grammar/GremlinAntlrToJava.java | 6 --- .../language/grammar/StructureElementVisitor.java | 38 ------------- .../language/grammar/TraversalMethodVisitor.java | 8 +-- .../language/translator/GoTranslateVisitor.java | 10 ---- .../translator/GroovyTranslateVisitor.java | 12 ----- .../language/translator/JavaTranslateVisitor.java | 12 ----- .../translator/JavascriptTranslateVisitor.java | 10 ---- .../translator/PythonTranslateVisitor.java | 10 ---- .../traversal/dsl/graph/GraphTraversal.java | 20 +++++-- .../traversal/step/map/AddEdgeStartStep.java | 47 +++++++++++----- .../process/traversal/step/map/AddEdgeStep.java | 47 +++++++++++----- .../language/grammar/ArgumentVisitorTest.java | 8 --- .../grammar/StructureElementVisitorTest.java | 48 ----------------- .../language/translator/GremlinTranslatorTest.java | 9 ---- .../Process/Traversal/GraphTraversal.cs | 18 +++++++ .../Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs | 34 ++++++------ gremlin-go/driver/cucumber/gremlin.go | 34 ++++++------ gremlin-groovy/pom.xml | 16 ++---- .../gremlin-javascript/test/cucumber/gremlin.js | 34 ++++++------ gremlin-language/src/main/antlr4/Gremlin.g4 | 22 +------- .../language/corpus/DocumentationReader.java | 4 +- .../src/test/resources/gremlin-values.txt | 5 -- .../src/test/resources/incorrect-traversals.txt | 1 - gremlin-python/src/main/python/radish/gremlin.py | 34 ++++++------ gremlin-shaded/pom.xml | 31 ++++++++++- .../gremlin/test/features/branch/Union.feature | 10 ++-- .../gremlin/test/features/filter/Has.feature | 12 ++--- .../gremlin/test/features/filter/Where.feature | 4 +- .../gremlin/test/features/map/AddEdge.feature | 62 +++++++++++----------- .../gremlin/test/features/map/Element.feature | 12 ++--- .../gremlin/test/features/map/Math.feature | 4 +- .../gremlin/test/features/map/MergeEdge.feature | 60 ++++++++++----------- .../gremlin/test/features/map/Vertex.feature | 8 +-- .../test/features/sideEffect/Inject.feature | 35 ------------ pom.xml | 24 ++------- .../tinkergraph/structure/TinkerGraphTest.java | 12 ++--- 45 files changed, 352 insertions(+), 600 deletions(-) diff --cc docs/src/upgrade/release-3.8.x.asciidoc index 50dea6654b,e8ed68dee1..2c49bd6410 --- a/docs/src/upgrade/release-3.8.x.asciidoc +++ b/docs/src/upgrade/release-3.8.x.asciidoc @@@ -30,53 -30,38 +30,85 @@@ complete list of all the modifications === Upgrading for Users +==== Number Conversion Step + +We have introduced a number conversion step, `asNumber()`, which converts the incoming traverser to the nearest parsable type if no argument is provided, or to the desired numerical type, based on the number token (`N`) provided. + +Numerical input will pass through unless a type is specified by the number token, with the exception that any float number will be converted into double. `ArithmeticException` will be thrown for any overflow during narrowing of types: + +[source,text] +---- +gremlin> g.inject(5).asNumber() +==> 5 // parses to int +gremlin> g.inject(5.0).asNumber() +==> 5 // parses to double +gremlin> g.inject(5.123f).asNumber() +==> 5.123 // will cast float to double +// Narrowing of types may result in ArithmeticException due to overflow +gremlin> g.inject(12).asNumber(N.byte) +==> 12 +gremlin> g.inject(128).asNumber(N.byte) +==> ArithmeticException +gremlin> g.inject(300).asNumber(N.byte) +==> ArithmeticException +---- + +String input will be parsed. By default, the smalled unit of number to be parsed into is `int` if no number token is provided. `NumberFormatException` will be thrown for any unparsable strings: + +[source,text] +---- +gremlin> g.inject("5").asNumber() +==> 5 +gremlin> g.inject("5.7").asNumber(N.int) +==> 5 +gremlin> g.inject("1,000").asNumber(N.nint) +==> NumberFormatException +gremlin> g.inject("128").asNumber(N.nbyte) +==> ArithmeticException +---- + +All other input types will result in `IllegalArgumentException`: +[source,text] +---- +gremlin> g.inject([1, 2, 3, 4]).asNumber() +==> IllegalArgumentException +---- + +See: link:https://tinkerpop.apache.org/docs/3.8.0/reference/#asNumber-step[asNumber()-step] +See: link:https://issues.apache.org/jira/browse/TINKERPOP-3166[TINKERPOP-3166] + + ==== Removal of Vertex/ReferenceVertex from grammar + + `StructureVertex`, previously used to construct new vertices in the grammar, now been removed. The `V()` step, as well + as the `from()` and `to()` modulators used with `addE()`, previously accepted `StructureVertex` as arguments in the + grammar. In its place, the `from()` and `to()` modulators can now directly accept a vertex id in place of a `Vertex` + when used with `addE()` (`V()` has always accepted ids in addition to vertices). When using these steps in `gremlin-lang` + scripts, the vertex id must be used directly. This change has no effect on the `GraphTraversal` API, nor on + `gremlin-groovy` scripts. Vertices can continue to be used directly such places. + + [source,groovy] + ---- + // 3.7.3 + gremlin> v1 = g.V(1).next() + ==>v[1] + gremlin> v2 = g.V(2).next() + ==>v[2] + gremlin> script = String.format("g.V(new Vertex(%s)).outE().where(inV().is(new Vertex(%s)))", v1.id(), v2.id()) + ==>g.V(new Vertex(1)).outE().where(inV().is(new Vertex(2))) + gremlin> client.submit(script).all().get().get(0).getEdge() + ==>e[7][1-knows->2] + + // 3.8.0 + gremlin> v1 = g.V(1).next() + ==>v[1] + gremlin> v2 = g.V(2).next() + ==>v[2] + gremlin> script = String.format("g.V(%s).outE().where(inV().id().is(%s))", v1.id(), v2.id()) + ==>g.V(1).outE().where(inV().id().is(2)) + gremlin> client.submit(script).all().get().get(0).getEdge() + ==>e[7][1-knows->2] + ---- + ==== Auto promotion of number types Previously, operations like sum or sack that involved mathematical calculations did not automatically promote the result diff --cc gremlin-language/src/main/antlr4/Gremlin.g4 index 4f089e9cfd,a2ae6fea14..d7037a4fff --- a/gremlin-language/src/main/antlr4/Gremlin.g4 +++ b/gremlin-language/src/main/antlr4/Gremlin.g4 @@@ -1586,8 -1556,6 +1573,7 @@@ genericLitera | traversalMerge | traversalPick | traversalDT + | traversalN - | structureVertexLiteral | genericSetLiteral | genericCollectionLiteral | genericRangeLiteral