Skip to content

TINKERPOP-3023 Expand type syntax in grammar in 3.8 - Remove Vertex#3133

Merged
Cole-Greer merged 17 commits into
apache:3.8-devfrom
EchoNullify:grammar_vertexv2
Jul 7, 2025
Merged

TINKERPOP-3023 Expand type syntax in grammar in 3.8 - Remove Vertex#3133
Cole-Greer merged 17 commits into
apache:3.8-devfrom
EchoNullify:grammar_vertexv2

Conversation

@EchoNullify

@EchoNullify EchoNullify commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

Feat: Remove Vertex support from grammar, and for places where a vertex is required, pass in the vertex id instead at traversal construction.

  • The grammar currently includes inconsistencies, particularly around "type constructors" like ReferenceVertex(), which are being re-evaluated.

  • ReferenceVertex should be renamed simply to Vertex, as the distinction (e.g., between ReferenceVertex and DetachedVertex) is no longer meaningful or guaranteed.

  • The keyword new should be removed from the grammar rule for structureVertex, as it's syntactically unnecessary.

  • The Vertex constructor should only require an id, not a label. Labels are not utilized in practice (e.g., in g.V(Vertex)), and can default to an empty string.

Resolves: 3023,

For reference...

https://lists.apache.org/thread/ptq81160z4y4vddg4lxz2nv244x2yzhq

@EchoNullify EchoNullify marked this pull request as ready for review June 11, 2025 16:17
@codecov-commenter

codecov-commenter commented Jun 11, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.59184% with 10 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (3.8-dev@9c7a54c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...remlin/process/traversal/step/map/AddEdgeStep.java 64.70% 4 Missing and 2 partials ⚠️
...in/language/grammar/DefaultGremlinBaseVisitor.java 0.00% 2 Missing ⚠️
...n/process/traversal/step/map/AddEdgeStartStep.java 87.50% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             3.8-dev    #3133   +/-   ##
==========================================
  Coverage           ?   76.52%           
  Complexity         ?    13829           
==========================================
  Files              ?     1109           
  Lines              ?    69787           
  Branches           ?     7545           
==========================================
  Hits               ?    53404           
  Misses             ?    13617           
  Partials           ?     2766           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@EchoNullify EchoNullify changed the title [TP Grammar] Remove Vertex from Grammar [TINKERPOP-3023] Expand type syntax in grammar in 3.8 - Remove Vertex Jun 11, 2025
@EchoNullify EchoNullify changed the title [TINKERPOP-3023] Expand type syntax in grammar in 3.8 - Remove Vertex TINKERPOP-3023 Expand type syntax in grammar in 3.8 - Remove Vertex Jun 11, 2025
@EchoNullify EchoNullify marked this pull request as draft June 11, 2025 17:16
@EchoNullify EchoNullify marked this pull request as ready for review June 12, 2025 22:04
g.mergeE(["weight": 0.5, Direction.out: 1])
g.mergeE(["weight": 0.5, Direction.in: 1])
g.addE('knows').from(g.V(1))
g.addE('knows').from(g.V(1).next())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this now a valid traversal?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously was invalid but now works

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting. from() in the grammar previously only allowed a nestedTraversal, but not a terminatedTraversal. By putting genericArgument in there to accept any arbitrary ID type, we've now allowed terminatedTraversal to leak in. I don't think this is a big concern.
@spmallette any thoughts on this?

Comment thread docs/src/recipes/between-vertices.asciidoc Outdated
Comment thread docs/src/upgrade/release-3.8.x.asciidoc Outdated
Comment thread docs/src/upgrade/release-3.8.x.asciidoc Outdated
Comment thread docs/src/upgrade/release-3.8.x.asciidoc Outdated
Comment thread docs/src/upgrade/release-3.8.x.asciidoc Outdated
Comment thread gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs Outdated
Comment thread gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
g.mergeE(["weight": 0.5, Direction.out: 1])
g.mergeE(["weight": 0.5, Direction.in: 1])
g.addE('knows').from(g.V(1))
g.addE('knows').from(g.V(1).next())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting. from() in the grammar previously only allowed a nestedTraversal, but not a terminatedTraversal. By putting genericArgument in there to accept any arbitrary ID type, we've now allowed terminatedTraversal to leak in. I don't think this is a big concern.
@spmallette any thoughts on this?

@Cole-Greer

Copy link
Copy Markdown
Contributor

I've pushed some changes into the branch which updates the docs a bit and strips out the vertex -> id sugar in GraphTraversal as it's not required for bytecode. (to be added to master in a separate PR)

My vote is VOTE +1

@Cole-Greer

Copy link
Copy Markdown
Contributor

Note: Followup PR for master: #3138

@Cole-Greer Cole-Greer merged commit f8dd8c1 into apache:3.8-dev Jul 7, 2025
18 checks passed
Cole-Greer added a commit that referenced this pull request Jul 22, 2025
…3138)

This is a followup to #3133 with changes exclusively for TP4. The primary difference in TP4 is that bytecode has been replaced with GremlinLang, which means that the use of Vertex in V(), from(), and to() is now sugar added by GraphTraversal. These vertices must be converted to their ids when passed into GremlinLang.

---------

Co-authored-by: Peter Tribe <peter.tribe@improving.com>
Cole-Greer added a commit that referenced this pull request Oct 29, 2025
from() and to() will now only accept Strings (alias for __.select()) and Traversals. If users wish to pass a vertex id, they may embed it in __.V() or __.constant().

The primary motivation here is to ensure consistent behaviour accross providers regardless of if their id types are numerics, strings, or other.

This change is a followup to an unintended consequence stemming from #3133. The issue with directly allowing ID's to be passed into from/to, it creates a weird asymmetry for graphs which use Strings as their ids. For example g.addE().from(1).to(2) would work fine and create an edge from V[1] to V[2], however if the graph used String ids, the equivalent traversal (g.addE().from("a").to("b")) does not work, as the Strings are interpreted as path labels (converted to __.select("a")) instead of vertex ids. There are some ugly workarounds which can partially mitigate this issue, but overall there is no generalized fix which allows all traversals to behave the same regardless of the vertex id type.

---------

Co-authored-by: andreachild <andrea.child@improving.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants