How to query using vertexId if vertex is made using composite key in scala gremline

179 Views Asked by At

We are using this lib to query dse graph. https://github.com/mpollmeier/gremlin-scala

  1. we can query and get vertex using vertexId if vertex primary key just single key like UUID. for ex. g.V("veretxId=UUID,~label=vertexLabel")

  2. But if vertex primary key is made composite keys for
    ex.

        addressTD : UUId
        postCode: Int
        sName: String
        lName: String.
    

now vertex primary key is composite key of these four values.

  1. Now if query in Datastax Studio and get vertex using this query

    g.V("{sName=\"TREVALLYN\",lName=\"TREVALLYN\",~label=tasLabel,postCode=7250,addressID=ad71d33c-0aaa-4014-a381-c189c30d45c5}")
    

it will return vertex in datastax studio.

  1. While using https://github.com/mpollmeier/gremlin-scala this lib. Its seems it is not working. I am sending vertexId in a prescribed format like this

    "{sName=\"TREVALLYN\",lName=\"TREVALLYN\",~label=tasLabel,postCode=7250,addressID=ad71d33c-0aaa-4014-a381-c189c30d45c5}"
    
1

There are 1 best solutions below

0
On BEST ANSWER

Well, I found a solution for that. Use java linked hash map in scala to generate vertexId and pass it to the scala gremlin query.

val javaLinkedHashMapVertexId = new java.util.LinkedHashMap[String, Any]()


//Putting values in hashmap
val vLabel =
  javaLinkedHashMapVertexId.put("~label", "vertexLabelName")
val pKeyLocaName =
  javaLinkedHashMapVertexId.put("localityName", "lName")
val pKeyPostCode =
  javaLinkedHashMapVertexId.put("postCode", postCode)
val pKeyStreetName =
  javaLinkedHashMapVertexId.put("streetName", "sname")
val pKeyAddId =
  javaLinkedHashMapVertexId.put("addressID","addressID")

val vertex = graph 
  .V(javaLinkedHashMapVertexId)
  .head()

Vertex variable will fetch vertex from dse graph using linked hashmap