PGX 1.2.0
Documentation

Running Graph Pattern Matching

Submitting a Query and Getting a Result Set

PgxGraph provides methods to submit a graph pattern matching query written in PGQL:

PgxFuture<PgqlResultSet> queryPgqlAsync(String pgqlString)

and its blocking equivalent:

PgqlResultSet queryPgql(String pgqlString)

Getting Result Element Information from a Result Set

A graph pattern matching result consists of a list of result elements. We allow the following types for an result element.

  • Vertex
  • Edge
  • Integer
  • Long
  • Float
  • Double
  • Boolean

Since a result element can have any of the above types, we provide a way to get information on each result element. PgqlResultSet has the following method to get a list of result element information.

List<PgqlResultElement> getPgqlResultElements()

ith PgqlResultElemet instance in the list contains type and variable name information on the ith result element in a graph pattern matching result. They are accessible via the following PgqlResultElement methods:

PgqlResultElement.Type getElementType() IdType getVertexEdgeIdType()
String getVarName()

Iterating over Results

Once you get an PgqlResultSet object, you can get an Iterable<PgqlResult> instance by calling the following method:

Iterable<PgqlResult> getResults()

Then, you can iterate over the graph pattern matching results using the for-each style loop.

Each PgqlResult instance contains a specific pattern matching result. You can get a java object for each result element by its index or variable name.

Object get(int elementIdx)
Object get(int variableName)

Alternatively, if you are aware of a type of a result element from your knowlege on a query or a PgqlResultElement instance. We provide the following type-specific getter methods:

PgxVertex<ID> getVertex(int elementIdx)
PgxVertex<ID> getVertex(String variableName)
PgxEdge getEdge(int elementIdx)
PgxEdge getEdge(String variableName)
Integer getInteger(int elementIdx)
Integer getInteger(String variableName)
Long getLong(int elementIdx)
Long getLong(String variableName)
Float getFloat(int elementIdx)
Float getFloat(String variableName)
Double getDouble(int elementIdx)
Double getDouble(String variableName)
Double getBoolean(int elementIdx)
Double getBoolean(String variableName)

We also provide a print method for PqglResultSet to print out the result set without iterating over each result.

void print(PrintStream stream, int from, long numResults)
void print(int from, long numResults)
void print(long numResults)
void print()

The print methods prints numResults results to stream after skipping from - 1 results. Without stream, the method prints the results to System.out. Without from, the method does not skip any results. Without numResults, the method print all results.

Advanced - Select Graph Pattern Matching Semantics

PGX provides two graph pattern matching semantics -- graph isomorphism and graph homomorphism which are briefly described in the PQGL specification. The default graph pattern matching semantics can be configured in the engine, session, and query submission level. The engine level configuration is done via the engine configuration field pattern_matching_semantic. The session level configuration is done via the following PgxSession method:

void setDefaultPatternMatchingSemantic(PatternMatchingSemantic semantic)

With this method, you can choose the graph pattern matching semantic between the graph isomorphism (PatternMatchingSemantic.ISOMORPHISM) and the graph homomorphism (PatternMatchingSemantic.HOMOMORPHISM).

Lastly, in the query submission level, you can specify the pattern matching semantic using the following PgxGraph method:

PgxFuture<PgqlResultSet> queryPgqlAsync(String pgqlString, PatternMatchingSemantic semantic)

and its Blocking equivalent is:

PgqlResultSet queryPgql(String pgqlString, PatternMatchingSemantic semantic)