Gremlin query on Cosmos DB: Unable to cast object of type StringField to Compose1Field

0

We have the issue with Gremlin query on Azure Cosmos DB The query works in Gremlin Console on TinkerPop but Cosmos DB is complaining about it.

It seems to be an issue with the last group().by(...) step

Not sure if this is a bug or there is some workaround specific for Cosmos

The error is as follows:

Error

ExceptionType : InvalidCastException ExceptionMessage : Unable to cast object of type 'Microsoft.Azure.Cosmos.Gremlin.Core.Runtime.StringField' to type 'Microsoft.Azure.Cosmos.Gremlin.Core.Runtime.Compose1Field'. Source : Microsoft.Azure.Cosmos.Gremlin.Core HResult : 0x80004002

The query is as follows:

g.V().hasLabel('user').as('u').
           out('userGeneratedEvent').
           outE('eventRelatedTo').as('w').inV().
           out('itemVersionOf').as('i').
           select('u','i','w').
             by('userId').
             by('itemId').
             by('weight').
           unfold().
           group().
             by(keys).
             by(select(values).fold()).
           unfold()

It should produce the following result:

==>u=[1, 2, 2, 2, 2, 3, 3]
==>w=[5, 4, 1, 2, 3, 4, 1]
==>i=[1, 1, 2, 1, 3, 1, 2]

The graph example is as follows:

g.addV('user').property('userId', 1)
g.addV('user').property('userId', 2)
g.addV('user').property('userId', 3)
g.addV('event').property('eventId', 1)
g.addV('event').property('eventId', 2)
g.addV('event').property('eventId', 3)
g.addV('event').property('eventId', 4)
g.addV('event').property('eventId', 5)
g.addV('itemVersion').property('itemVersionId', 1)
g.addV('itemVersion').property('itemVersionId', 2)
g.addV('itemVersion').property('itemVersionId', 3)
g.addV('itemVersion').property('itemVersionId', 4)
g.addV('itemVersion').property('itemVersionId', 5)
g.addV('itemVersion').property('itemVersionId', 6)
g.addV('itemVersion').property('itemVersionId', 7)
g.addV('item').property('itemId', 1)
g.addV('item').property('itemId', 2)
g.addV('item').property('itemId', 3)
g.addV('item').property('itemId', 4)
g.V().hasLabel('user').has('userId',1).addE('userGeneratedEvent').to(g.V().hasLabel('event').has('eventId',1))
g.V().hasLabel('user').has('userId',2).addE('userGeneratedEvent').to(g.V().hasLabel('event').has('eventId',2))
g.V().hasLabel('user').has('userId',2).addE('userGeneratedEvent').to(g.V().hasLabel('event').has('eventId',3))
g.V().hasLabel('user').has('userId',3).addE('userGeneratedEvent').to(g.V().hasLabel('event').has('eventId',4))
g.V().hasLabel('user').has('userId',3).addE('userGeneratedEvent').to(g.V().hasLabel('event').has('eventId',5))
g.V().hasLabel('event').has('eventId',1).addE('eventRelatedTo').to(g.V().hasLabel('itemVersion').has('itemVersionId',1)).property('weight', 5)
g.V().hasLabel('event').has('eventId',2).addE('eventRelatedTo').to(g.V().hasLabel('itemVersion').has('itemVersionId',1)).property('weight', 4)
g.V().hasLabel('event').has('eventId',2).addE('eventRelatedTo').to(g.V().hasLabel('itemVersion').has('itemVersionId',2)).property('weight', 1)
g.V().hasLabel('event').has('eventId',3).addE('eventRelatedTo').to(g.V().hasLabel('itemVersion').has('itemVersionId',1)).property('weight', 2)
g.V().hasLabel('event').has('eventId',3).addE('eventRelatedTo').to(g.V().hasLabel('itemVersion').has('itemVersionId',3)).property('weight', 3)
g.V().hasLabel('event').has('eventId',4).addE('eventRelatedTo').to(g.V().hasLabel('itemVersion').has('itemVersionId',4)).property('weight', 4)
g.V().hasLabel('event').has('eventId',5).addE('eventRelatedTo').to(g.V().hasLabel('itemVersion').has('itemVersionId',5)).property('weight', 1)
g.V().hasLabel('itemVersion').has('itemVersionId',1).addE('itemVersionOf').to(g.V().hasLabel('item').has('itemId',1))
g.V().hasLabel('itemVersion').has('itemVersionId',2).addE('itemVersionOf').to(g.V().hasLabel('item').has('itemId',2))
g.V().hasLabel('itemVersion').has('itemVersionId',3).addE('itemVersionOf').to(g.V().hasLabel('item').has('itemId',3))
g.V().hasLabel('itemVersion').has('itemVersionId',4).addE('itemVersionOf').to(g.V().hasLabel('item').has('itemId',1))
g.V().hasLabel('itemVersion').has('itemVersionId',5).addE('itemVersionOf').to(g.V().hasLabel('item').has('itemId',2))
g.V().hasLabel('itemVersion').has('itemVersionId',6).addE('itemVersionOf').to(g.V().hasLabel('item').has('itemId',3))
g.V().hasLabel('itemVersion').has('itemVersionId',7).addE('itemVersionOf').to(g.V().hasLabel('item').has('itemId',4))
azure-cosmosdb
azure-cosmosdb-gremlinapi
asked on Stack Overflow May 17, 2019 by Sebastian Widz

1 Answer

0

Thanks for your feedback. Currently, the Data Explorer does not support all functionality as does the Gremlin Console on Tinkerpop, which supports all Groovy language expressions.

You can refer the MSDN Thread for more details.

Hope it helps.

answered on Stack Overflow May 30, 2019 by angoyal-msft

User contributions licensed under CC BY-SA 3.0