X

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

A Tip on Using Property Value as Vertex Label(s)

Alan Wu
Architect

Oracle's property graph database (Oracle Spatial and Graph Property Graph, and Oracle Big Data Spatial and Graph) has a feature that allows one to use the literal value of a designated property to define vertex label(s). The difference between a label and a property is not always clear. In general, a label denotes some kind of typing and/or categorization. 

One thing to watch out for is that in addition to using the following two setters, it is also important to add a setLoadVertexLabels(true) when constructing a graph config. Without it, your in-memory graph simply does not have the vertex labels.

setUseVertexPropertyValueAsLabel("<property_key>"),

and

setPropertyValueDelimiter(",")

A complete example is as follows. This Groovy-based code snippet assumes an Oracle NoSQL Database as the backend.

server = new ArrayList<String>();
server.add("bigdatalite:5000");


// -- use country as label
cfg = GraphConfigBuilder.forPropertyGraphNosql()
    .setName("connections").setStoreName("kvstore")
    .setHosts(server) .hasEdgeLabel(true)
    .setLoadEdgeLabel(true)                 

    .addEdgeProperty("weight", PropertyType.DOUBLE, "1000000")
    .setMaxNumConnections(2)
    .addVertexProperty("country", PropertyType.STRING, "null")
    .addVertexProperty("name", PropertyType.STRING, "empty name")
    .setLoadVertexLabels(true)
    .setUseVertexPropertyValueAsLabel("country")
    .setPropertyValueDelimiter(",")
    .build();
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());

opg-nosql> v=pgxGraph.getVertex(1l)
==>PgxVertex[ID=1]

opg-nosql> v.labels
==>United States

// add a vertex label constraint in a PGQL query
opg-nosql> pgxResultSet = pgxGraph.queryPgql("SELECT n,m WHERE (n:'United States') -> (m)")
==>PgqlResultSet[graph=connections,numResults=117]
opg-nosql> pgxResultSet.print(10);
---------------------------------------
| n                | m                |
=======================================
| PgxVertex[ID=38] | PgxVertex[ID=2]  |
| PgxVertex[ID=1]  | PgxVertex[ID=2]  |
...

 

Cheers,

Zhe

 

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