X

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

How Many Ways to Run Property Graph Query Language (PGQL) in BDSG? (I)

Alan Wu
Architect

As many of you know it already, Property Graph Query Language (PGQL) is a very powerful feature offered in Oracle Big Data Spatial and Graph (BDSG)*. PGQL provides a clean, intuitive, SQL-like syntax for one to write expressive query patterns. By design, PGQL combines strengths of SQL syntax, Cypher syntax, and a bit of SPARQL (a query language for RDF). Details on PGQL can be found here.

One thing you may not know is there are actually quite a few different ways one can execute PGQL: from Cytoscape UI, Groovy, Python, Zeppelin, to name a few. In a few installments, I am going to illustrate how to execute PGQL in different environments.

Approach #1: Execute PGQL from Groovy/Java

The following script can be executed with the groovy shell: ./gremlin-opg-hbase.sh

 ...

 // Get a graph config that has graph name "connections" and
// Zookeeper host, port, and some other parameters
cfg = GraphConfigBuilder.forPropertyGraphHbase()            \
 .setName("connections")                                    \
 .setZkQuorum("bigdatalite").setZkClientPort(2181)          \
 .setZkSessionTimeout(120000).setInitialEdgeNumRegions(3)   \
 .setInitialVertexNumRegions(3).setSplitsPerRegion(1)       \
 .addVertexProperty("name", PropertyType.STRING, "empty name") \
 .build();

// Get an instance of OraclePropertyGraph which is a key Java
// class to manage property graph data
opg = OraclePropertyGraph.getInstance(cfg);
opg.clearRepository();

// OraclePropertyGraphDataLoader is a key Java class
// to bulk load property graph data into the backend databases.
opgdl=OraclePropertyGraphDataLoader.getInstance();
vfile="../../data/connections.opv"
efile="../../data/connections.ope"
opgdl.loadData(opg, vfile, efile, 2);

// Create an in memory analytics session and analyst
session=Pgx.createSession("session_ID_1");
analyst=session.createAnalyst();

// Read graph data from database into memory
pgxGraph = session.readGraphWithProperties(opg.getConfig());

pgxResultSet = pgxGraph.queryPgql("SELECT n,n.name, m WHERE (n) -> (m)")
pgxResultSet.print(10);
pgxResultSet.getNumResults()
---------------------------------------------------------------
| n                    | n.name        | m                    |
===============================================================
| PgxVertex with ID 78 | Hosain Rahman | PgxVertex with ID 77 |
| PgxVertex with ID 71 | Pony Ma       | PgxVertex with ID 69 |
| PgxVertex with ID 44 | Seth Meyers   | PgxVertex with ID 42 |
| PgxVertex with ID 5  | Pope Francis  | PgxVertex with ID 59 |
| PgxVertex with ID 5  | Pope Francis  | PgxVertex with ID 56 |
| PgxVertex with ID 5  | Pope Francis  | PgxVertex with ID 58 |
| PgxVertex with ID 5  | Pope Francis  | PgxVertex with ID 57 |
| PgxVertex with ID 77 | Tony Fadell   | PgxVertex with ID 78 |
| PgxVertex with ID 77 | Tony Fadell   | PgxVertex with ID 73 |
| PgxVertex with ID 75 | Bobby Murphy  | PgxVertex with ID 74 |
---------------------------------------------------------------

pgxResultSet = pgxGraph.queryPgql("SELECT n,e, m WHERE (n) -[e:'collaborates']-> (m)")
pgxResultSet.print(10);
pgxResultSet.getNumResults()

...

Cheers,

Zhe


* Note that PGQL is part of BDSG on big data platform. It is also available with Oracle Spatial and Graph option in Oracle Database (12.2.0.1) via a patch.

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.Captcha
Oracle

Integrated Cloud Applications & Platform Services