0

Suppose I have the following code in gremlin.net:


 var graphQuery = graph.V(source.ToString());

            var graphOutCondition = __.OutE().HasLabel("Transport");
            foreach (var filter in filters)
            {
                if (filter.Key.StartsWith("C"))
                {

                    graphOutCondition = graphOutCondition.Has("C", P.Within(Clist));
                }
               
                if (filter.Key.StartsWith("CT"))
                {

                    graphOutCondition = graphOutCondition.Has(filter.Key,filter.Value);
                }
                
                if (filter.Key.StartsWith("TU"))
                {
             
                    graphOutCondition = graphOutCondition.Where(__.Properties<string>().HasKey("EP_" + filter.Value.Clean()));
                }
            }
            graphQuery.Repeat(graphOutCondition.InV().SimplePath())
            .Until(__.HasId(destination.ToString()));

            graphQuery.Path()
            .By(__.Id()).By(__.Id());

As the code implies, I have multiple values in CT list (which is a List<string>).

But when running the code, it throws an exception:

Error: System.AggregateException: One or more errors occurred. (One or more errors occurred. (ScriptEvaluationError:

ActivityId : 29d7649d-0694-4089-9567-26506c67a010
ExceptionType : GraphSyntaxException
ExceptionMessage : Gremlin query syntax error: Unexpected token: '`'

The array is translated to System.Collections.Generic.List which I don't see why.

I have tried to pass the list itself, using the .ToArray() method or casting like in the code shown above. All results are the same.

I am using gremlin.net version 3.4.13 as it is the latest version supported by Azure CosmosDb.

I do have an executor which sends the query as string.

var result = gremlinClient.SubmitAsync<dynamic>(query.ToString()).Result

Any suggestions?

  • CosmosDB does [not support submitting queries as Gremlin Bytecode](https://learn.microsoft.com/en-us/azure/cosmos-db/gremlin/support#unsupported-features). How are you submitting the query? What does the full query look like - what you have shown above looks like a part of the query. The error message seems to imply it is the whole query that is causing the issue and the example appears to show you are trying to use Gremlin Bytecode. – Kelvin Lawrence Jul 10 '23 at 14:27
  • the problem is the P.Within method does not translate items inside the list. it simply translates it to its type name. – arian shahesmaeili Jul 11 '23 at 15:26
  • But that is still using ByteCode right? When you try sending that to CosmosDB, per their documentation, it is not supported. Their documentation says : `Use GremlinClient.SubmitAsync() and pass traversal as a text string.` – Kelvin Lawrence Jul 11 '23 at 18:15
  • I do it. yes. i have an executor which sends the query to gremlin like this: var result = gremlinClient.SubmitAsync(query.ToString()).Result; it works on other queries. the only problem I have is the within method. it is not translating the ICollection inside it. actually gremlin takes an array inside within, but gremlin.net it takes param[] then convert it using ToGenericList(). which I think is a bug. – arian shahesmaeili Jul 11 '23 at 19:40
  • OK thanks - that's a very important point that perhaps you could add to the question. – Kelvin Lawrence Jul 11 '23 at 22:41
  • sure, I will. thank you for participating – arian shahesmaeili Jul 12 '23 at 11:52
  • Generally when ToString is used on a Traversal what gets printed out is the ByteCode form of the query and not the actual query in a form that is consumable as Gremlin. This is the other reason why I have been a bit confused by this question. Can you please show an example of what the ToString is producing? I do not see anywhere in the Gremlin-DotNet code where it calls the translator as part of a ToString - which it would need to do for this to work. I'm looking at the latest code though so it is possible it used to work differently. – Kelvin Lawrence Jul 12 '23 at 16:56
  • Yes. this is the generated. note that every parameter is translated but in Within method: g.V('1').repeat(outE().hasLabel('T').has('CT_0', 'ct1').where(properties().hasKey('EP_20')).has('C', within(System.Collections.Generic.List`1[System.Object])).inV().simplePath()).until(hasId('10')).path().by(id()).by(id()) – arian shahesmaeili Jul 13 '23 at 11:08
  • It's still not clear to me from your question and the comments here how this string was created. Can you please edit your question and show the C# code that leads to this string? Would also be great if you could make that as simple as possible, e.g., with a very simple traversal and the `foreach` should not be necessary, as well as using variables that are defined outside of the shown code. – Florian Hockmann Jul 27 '23 at 15:24
  • The C# code is like the code block I have mentioned in the question. variables are "source" and "destination" which are valid ids of the graph's nodes. "filters" is a dictionary which is provided by other layers of code. here is an example of what is in it. ["C","bicycle "] ["CT1","Pizza"] ["CT2","letter"] ["TU1123"."1KG"] ["TU25432","1PKG"] Higher layers provide these. in this query I want to check if the edge has C=bicycle and it hasone either one of the CT1 = pizza or CT2 = letter and if it has any property that its name begins with TU1 – arian shahesmaeili Jul 29 '23 at 10:39
  • The error comes from the server when you execute: `gremlinClient.SubmitAsync(query.ToString()).Result`, right? Can you please just add the output of `query.ToString()` to your question? That should be the only part relevant to understand the problem. – Florian Hockmann Aug 08 '23 at 11:41
  • g.V('1').repeat(outE().hasLabel('T').has('CT_0', CT_0_1).where(properties().hasKey('EP_20')).has('C', within(System.Collections.Generic.List`1[System.Object])).inV().simplePath()).until(hasId('2')).path().by(id()).by(id()) note the array inside within method is not translated. i have gone through gremlin libraries. it seems there is a bug. it first opens it up to a make it an array then in another call makes it a list again. which seems to be the problem. – arian shahesmaeili Aug 12 '23 at 21:43

0 Answers0