简体   繁体   中英

Tree query using SimpleGraphStatement in CassandraCSharpDriver.Graph throws “cannot cast to org.apache.tinkerpop.gremlin.structure.Element”

I'm able to run this query in the Datastax Studio console and get a tree result back (although it is in malformed json, with all the data returned in the keys instead of values).

g.V().has("mything","key", "mykey")
.emit()
.repeat(outE("contains").inV())
.dedup()

.tree()
.by(
    group()
    .by(label)
    .by(
            valueMap()
            .unfold()
            .group()
            .by(select(keys))
            .by(select(values).unfold())
        )
    .unfold()
    .unfold()
)

The console result looks like this (notice the strange json format, with the data in the json keys?):

{
  "mystuff={dynamicproperties={stuff}, key=mykey}": {
    "contains={}": {
      "astuff={dynamicproperties=stuff, key=mykey}": {},
      "bstuff={dynamicproperties={stuff}, key=mykey}": {},
      "container={key=mykey}": {
        "contains={}": {
          "thing={key=mykey}": {
            "contains={}": {
              "cstuff={dynamicproperties={stuff}, key=mykey}": {}
            }
          }
        }
      }
    }
  }
}

However when I run it as a SimpleGraphStatement in Gremlin.NET using the CassandraCSharpGraph, it throws this exception: "java.util.HashMap$Node cannot be cast to org.apache.tinkerpop.gremlin.structure.Element"

This is the C# code I run the query:

var graphResultSet = cassandraGraphProvider.Session.ExecuteGraph(new SimpleGraphStatement(query));

I am able to run the statement all the way down to the.dedup() line and get vertices in the graphResultSet, but adding the tree code below that is when it starts throwing the error.

I'm using CassandraCSharpDriver.Graph 2.1, CassandraCSharpDriver 3.14, Gremlin.Net 3.2.9. The server is running dse cassandra 5.1.14 and gremlin 3.2.11.

What is the trick to running a tree query in CassandraCSharpDriver? Any ideas on what I could try next?

The real issue with Tree right now is denoted here in TINKERPOP-2063 - Gremlin Language Variants like C# do not currently support the deserialization of that object so you get that ugly "java.util.HashMap$Node cannot be cast to org.apache.tinkerpop.gremlin.structure.Element". You're only workaround at this point is to submit a script with the driver (the way Studio does) but then you're left to process that rought looking JSON. That representation relates to the problem of JSON not supporting non-string keys (ie can't use object the way Java does). So, I believe all the data is there but it's just not easy to work with sadly. As the JIRA issue also notes, there are similar issues with subgraph() step.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM