Oracle Big Data Spatial and Graph - technical tips, best practices, and news from the product team

A Tip to Help You Quickly Identify Object Types When Using Graph APIs

Alan Wu

Oracle Big Data Spatial and Graph (BDSG) and Oracle Spatial and Graph offer a rich set of Java APIs to process property graph data. Sometimes, the return value (object) of an API can be a bit tricky to deal with.

Here is a real question I recently got: "If I run PGQL selecting an id(), is there a way to convert this to a long to use when looking for a corresponding partition derived from an SCC call?"

To find an answer, one can either check the product Javadocs, or use a Groovy script. To get the exact type (class) of an object, simply run .getClass().getName()

As an illustration, the following Groovy script runs a PGQL query, iterates through the result set, gets an ID and finds its type.

opg-nosql> pgxResultSet = pgxGraph.queryPgql("SELECT n,m WHERE (n) -> (m)")

opg-nosql> r=pgxResultSet.getResults()
==>n(VERTEX)=1 m(VERTEX)=10
==>n(VERTEX)=11 m(VERTEX)=10
==>n(VERTEX)=1 m(VERTEX)=20

opg-nosql> r=pgxResultSet.getResults(); i=1
opg-nosql> r.getClass().getName()
opg-nosql> a=r.iterator().next()
==>n(VERTEX)=1 m(VERTEX)=10

opg-nosql> a.getVertex(1)

opg-nosql> a.getVertex(1).getId()

opg-nosql> a.getVertex(1).getId().getClass().getName()

Hope this small tip can make your graph exploring journey a bit easier!


Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.