8.1.1 Retrieving Metadata for PG Views

You can retrieve the metadata of property graph views (PG Views) created in the database using the built-in PROPERTY_GRAPH_METADATA graph in your PGQL queries.

The PROPERTY_GRAPH_METADATA graph structure including properties is as shown:

Figure 8-1 PROPERTY_GRAPH_METADATA Graph Design

Description of Figure 8-1 follows
Description of "Figure 8-1 PROPERTY_GRAPH_METADATA Graph Design"

The following describes the preceding design of the metadata graph:

PROPERTY_GRAPH -[:HAS_VERTEX_TABLE]-> VERTEX_TABLE
               -[:HAS_EDGE_TABLE]-> EDGE_TABLE
 
VERTEX_TABLE -[:HAS_KEY_COLUMN]-> KEY_COLUMN
             -[:HAS_LABEL]-> LABEL
 
EDGE_TABLE -[:HAS_KEY_COLUMN]-> KEY_COLUMN
           -[:HAS_LABEL]-> LABEL
           -[:HAS_SOURCE_TABLE]-> VERTEX_TABLE
           -[:HAS_DESTINATION_TABLE]-> VERTEX_TABLE
 
LABEL -[:HAS_PROPERTY]-> PROPERTY

It is important to note the following when using PROPERTY_GRAPH_METADATA in PGQL queries:

  • The PROPERTY_GRAPH_METADATA graph is automatically created and updated the first time you attempt to access it in a PGQL query.
  • The PROPERTY_GRAPH_METADATA graph is similar to a PG View and has its own set of metadata tables that describe its structure. In addition to the metadata tables for PG Views that are described in Table 8-1, the graph data for PROPERTY_GRAPH_METADATA is also stored in database objects that are listed in the following table:

    Table 8-2 Additional Metadata Tables and Views

    Table or View Name Description
    TEMP_PROPERY_GRAPHS Metadata table describing the list of PG Views in the database schema
    TEMP_EDGE_KEY_COLUMNS Metadata view describing the edge key columns
    TEMP_EDGE_LABELS Metadata view describing the edge labels
    TEMP_EDGE_TABLES Metadata view describing the edge tables
    TEMP_LABEL_PROPERTIES Metadata view describing the vertex and edge label properties
    TEMP_LABELS Metadata view describing the vertex and edge labels
    TEMP_VERTEX_KEY_COLUMNS Metadata view describing the vertex key columns
    TEMP_VERTEX_LABELS Metadata view describing the vertex labels
    TEMP_VERTEX_TABLES Metadata view describing the vertex tables

    Note:

    It is important that you do not alter or remove the any of the metadata tables or views for the PROPERTY_GRAPH_METADATA graph.
  • When running PGQL queries using the Java API, you must disable autocommit on the JDBC connection (conn.setAutoCommit(false)). This ensures that PROPERTY_GRAPH_METADATA graph gets created automatically.

The following examples show using PROPERTY_GRAPH_METADATA in PGQL queries to retrieve the required metadata.

You can retrieve the list of graphs to which you have access as shown:

opg4j> String pgql =
...> "SELECT g.graph_name "
...> +"FROM MATCH (g:property_graph) ON property_graph_metadata "
...> +"ORDER BY g.graph_name"
pgql ==> "SELECT g.graph_name FROM MATCH (g:property_graph) ON property_graph_metadata ORDER BY g.graph_name"
opg4j> pgqlStmt.executeQuery(pgql).print()
String pgql = "SELECT g.graph_name "+
"FROM MATCH (g:property_graph) ON property_graph_metadata "+
"ORDER BY g.graph_name";
PgqlResultSet rs = pgqlStmt.executeQuery(pgql);
rs.print();
>>> pgql = '''
... SELECT g.graph_name
... FROM MATCH (g:property_graph) ON property_graph_metadata
... ORDER BY g.graph_name
... '''
>>> pgql_statement.execute_query(pgql).print()

On execution, the preceding query produces the following result:

+------------------------+
| GRAPH_NAME             |
+------------------------+
| BANK_GRAPH_VIEW        |
| FINANCIAL_TRANSACTIONS |
| FRIENDS                |
+------------------------+

You can retrieve the vertex properties of a graph as shown:

opg4j> String pgql =
...> "SELECT p.property_name "
...> +"FROM MATCH(g:property_graph)-[:has_vertex_table]->(v)-[:has_label]->(l:label)-[:has_property]->(p:property) "
...> +"ON property_graph_metadata "
...> +"WHERE g.graph_name = 'FRIENDS' "
pgql ==> "SELECT p.property_name FROM MATCH(g:property_graph)-[:has_vertex_table]->(v)-[:has_label]->(l:label)-[:has_property]->(p:property) ON property_graph_metadata WHERE g.graph_name = 'FRIENDS' "
opg4j> pgqlStmt.executeQuery(pgql).print()
String pgql = "SELECT p.property_name "+
"FROM MATCH(g:property_graph)-[:has_vertex_table]->(v)-[:has_label]->(l:label)-[:has_property]->(p:property) "+
"ON property_graph_metadata "+
"WHERE g.graph_name = 'FRIENDS' ";
PgqlResultSet rs = pgqlStmt.executeQuery(pgql);
rs.print();
>>> pgql = '''
... SELECT p.property_name
... FROM MATCH(g:property_graph)-[:has_vertex_table]->(v)-[:has_label]->(l:label)-[:has_property]->(p:property)
... ON property_graph_metadata
... WHERE g.graph_name = 'FRIENDS'
... '''
>>> pgql_statement.execute_query(pgql).print()

On execution, the preceding query produces the following result:

+---------------+
| PROPERTY_NAME |
+---------------+
| BIRTHDATE     |
| HEIGHT        |
| NAME          |
+---------------+