I have a query that sent as a string works and returns the result
var query = $"g.V('{brandEntityCode}')" +
$".has('{Affinity}', '{partition}')" +
$".optional(" +
$"outE('{relationshipType}')" +
$".has('{HierarchyCollection}', '{hierarchyCollection}')" +
$".has('{IsDeleted}', {IsDeletedValue})" +
$".inV()" +
$".has('{IsDeleted}', {IsDeletedValue})" +
$".optional(" +
$"outE('{relationshipType}')" +
$".has('{HierarchyCollection}', '{hierarchyCollection}')" +
$".has('{IsDeleted}', {IsDeletedValue})" +
$".inV()" +
$".has('{IsDeleted}', {IsDeletedValue})" +
$")" +
$")" +
$".values('{EntityCode}')";
Since I have Gremlin package I want to use their package to write the query, which looks like this
var query = Graph.V($"'{brandEntityCode}'")
.Has(Affinity, $"'{partition}'")
.Optional<GraphTraversal<object, Vertex>>(OutE($"'{relationshipType}'")
.Has(HierarchyCollection, $"'{hierarchyCollection}'")
//.Has(IsDeleted, $"{IsDeletedValue}")
.InV()
.Has(IsDeleted, $"{IsDeletedValue}")
.Optional<GraphTraversal<object, Vertex>>(OutE($"{relationshipType}")
.Has(HierarchyCollection, $"'{hierarchyCollection}'")
//.Has(IsDeleted, IsDeletedValue)
.InV()
//.Has(IsDeleted, IsDeletedValue)
))
.Values<string>($"{EntityCode}")
.ToGremlinQuery();
But this throw a runtime exception, that An item with the same key has already been added. Key: isDeleted_1
And if I remove the isDeleted key, then the query at runtime looks like this
{g.V(9e591e9f-de07-427c-8b9e-762caf9c86a6).has('_affinity', _affinity).optional(outE('isOwnedBy').has('hierarchyCollection', hierarchyCollection_1).has('isDeleted', isDeleted_1).inV().optional(outE('isOwnedBy').has('hierarchyCollection', hierarchyCollection_2).inV())).values('entityCode')}
Now the execution throws the exception
ServerEvaluationError:
ActivityId : aa76ea5f-a514-479c-b799-349ae4ca3b5c
ExceptionType : GraphCompileException
ExceptionMessage :
Gremlin Query Compilation Error: Unable to resolve symbol '_affinity' in the current context. @ line 1, column 62.
Unable to resolve symbol 'hierarchyCollection_1' in the current context. @ line 1, column 127.
Unable to resolve symbol 'isDeleted_1' in the current context. @ line 1, column 173.
Unable to resolve symbol 'hierarchyCollection_2' in the current context. @ line 1, column 240.
4 Error(s)
GremlinRequestId : bae1692c-2b04-4b09-8521-88a0a78a9c0a
Context : graphcompute
Scope : graphparse-translate-validatesymbolresolution
GraphInterOpStatusCode : QuerySyntaxError
HResult : 0x80131500
Is there a solution for this issue?