0

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?

Robert Corvus
  • 2,054
  • 23
  • 30

1 Answers1

0

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 (i.e. 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.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • how would I submit a script with the driver, I thought SimpleGraphStatement was the way to do that and I'm getting the error above? Is there another way besides SimpleGraphStatement to send the studio query and get back a json string? – Robert Corvus Apr 13 '20 at 16:23
  • oh, you're already submitting a `String`, then what happens if you remove the `by()` modulator on `tree()`? does it work then? (i wonder if there are more caveats to consider with GraphSON than I'm aware of) – stephen mallette Apr 13 '20 at 16:33
  • thanks, i'll give that a try. we're on a very old version of datastax, and we started the upgrade now, so i'll reply back once that's complete later this week. maybe the newer version helps with this issue – Robert Corvus Apr 14 '20 at 20:39