X

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

  • January 22, 2018

Kicking off Relational to Property Graph Conversion from BDSG

Alan Wu
Architect

Today, I got a question on converting relational to PG (flat files). I actually wrote about PG data generation in the past. What makes this one different is the relational data is accessible from within an Oracle Database but the property graph database is on Big Data platform.

Here is an example flow with Python & JPype. The BDSG version is 2.1.

Assume we have a relational table with three columns, employee ID (EMPID), manager ID (MGRID), and a random property X. Say, we want to generate a set of edges based on this manager-employee relationship and treat that X column as an edge property.

SQL> desc reports
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 EMPID                                              NUMBER
 MGRID                                              NUMBER
 X                                                  NUMBER
 

We can use the following Python code, Java wrapped in JPype,  to convert this table into a .ope file:

ora=JClass('oracle.pg.rdbms.Oracle')
conn = ora("jdbc:oracle:thin:@<host>:1521:<sid>", "<user>",                                   "<password>").getConnection()
ctamCls=JClass("oracle.pg.common.ColumnToAttrMapping")
c1=ctamCls.getInstance("X", "X", JClass("java.lang.Long"))

util=JClass("oracle.pg.common.OraclePropertyGraphUtilsBase")
os=JClass("java.io.FileOutputStream")("/tmp/test.ope")

try:
        util.convertRDBMSTable2OPE(conn, "reports", None, 0l, "EMPID","MGRID",

          0l, False, "reportsTo", [c1], 1, os, None)
except jpype.JException(java.lang.RuntimeException), ex :
        print ex.message()
        print ex.stacktrace()

An example output is as follows:

$ cat /tmp/test.ope
1,1,2,reportsTo,X,7,,100,
2,3,2,reportsTo,X,7,,100,
[oracle@bigdatalite ~]$

Cheers,

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