Hi Andrea.

> The reason I am asking is that if we allow the customized classes to be
used as arguments for any gremlin step, we also need a mechanism to specify
how the customized classes can be evaluated by the steps. For example, how
can the customized class be evaluated by a has step which is checking for
equality or an order step which needs to compare > > instances of the
customized class with each other?

Yes, you are right.
We already use such mechanics for the first step right now.
You see, we support polymorphism, so labels in our graph are just classes.
As a result, we overwrite the standard step by optimization strategies
https://github.com/JetBrains/youtrackdb/blob/develop/core/src/main/java/com/jetbrains/youtrackdb/internal/core/gremlin/traversal/step/filter/YTDBHasLabelStep.java
and
https://github.com/JetBrains/youtrackdb/blob/develop/core/src/main/java/com/jetbrains/youtrackdb/internal/core/gremlin/traversal/strategy/optimization/YTDBGraphStepStrategy.java#L122
.

So in such a case, steps should be redefined by the provider.
I think if we create nice documentation about this approach, I mean whole
stack:

1.  Unknown methods as services.
2.  Class constructors and factory methods.
3.  Optimization strategies.

Extending Gremlin will not be a walk in the park (and I think that is a
good thing, actually), but completely doable for any provider with serious
intentions to enhance this ecosystem.



On Mon, Nov 10, 2025 at 7:25 PM Andrea Child
<[email protected]> wrote:

> Hi Andrii,
>
> Is your proposal for allowing instantiation of custom classes in the
> grammar intended to be utilized only in addition to the proposal to allow
> registered custom services as method calls in the grammar? Or are you
> envisioning the custom classes can be used as arguments for any gremlin
> step? The example you provided with the has step indicates you would like
> to enable it for any step.
>
> The reason I am asking is that if we allow the customized classes to be
> used as arguments for any gremlin step, we also need a mechanism to specify
> how the customized classes can be evaluated by the steps. For example, how
> can the customized class be evaluated by a has step which is checking for
> equality or an order step which needs to compare instances of the
> customized class with each other?
>
> Andrea
>
> From: Andrii Lomakin <[email protected]>
> Date: Monday, November 10, 2025 at 12:42 AM
> To: [email protected] <[email protected]>
> Subject: Proposal: Instantiation and caching of classes instances in
> Gremlin Scrip
>
> Good day.
>
> This proposal is an extension of my previous proposal of implicit
> conversion of a service call to a method call according to its registered
> name.
>
> Currently, Gremlin Script supports the creation of instances of certain
> classes.
> So I propose to extend it to allow to creation of instances of classes that
> are provided by AbstractGremlinPlugin implementation.
>
> During the application start, the public constructors plus all static
> public methods that are annotated with the annotation `@FactoryMethod` are
> registered in the ANTLR-based script engine.
>
> Names of extension classes should start with an upper case, and they are
> allowed only as args of the steps. Instances of extension classes or calls
> to factory methods can contain instances of other extension classes in a
> recursive manner.
>
> This will allow queries like `g.V().hasLabel("PGVector").has("embedding",
> PGVectorPredicate.l1Distance(PGVector(,,,), 5))`.
>
> I believe that these mechanics, alongside the mechanics of exposing
> services as method calls, will provide all the means necessary for
> extending Gremlin by providers, though they will be bound to change some of
> their DSL to follow a unified approach.
>
> WDYT?
>

Reply via email to