Can anyone help me figure out how we can load data into a Tuple created inside TigerGraph DB? I have created the following Tuple and I am trying to load data from a file using Spark.
Graph Name: MyGraph Tuple Name: MyTuple
Attributes of MyTuple: ID String(50),Datee Datetime
The tuple MyTuple is being referred into an edge (ed_newEdge) of MyGraph as an edge attribute. Seeking help to figure out how we can load data into the tuple present in MyGraph using Spark.
You can insert data to the tuple using tigergraph jdbc driver. You can find an example here https://github.com/tigergraph/ecosys/blob/master/tools/etl/tg-jdbc-driver/tg-jdbc-examples/src/main/java/com/tigergraph/jdbc/UpsertQuery.java
After following above code for creating connection , you can use below code snippet
try (java.sql.Statement stmt = con.createStatement()) {
query = "INSERT INTO edge ed_newEdge(Vertex1, Vertex2) VALUES(MyTuple("1d123","2011-02-03 01:02:03"))";
stmt.addBatch(query);}
Alternatively you can process your data on SPARK and serialize your data on a Parquet or csv file. And then you can create a GSQL loading job to read that file and insert the value to your tuple. https://docs.tigergraph.com/dev/gsql-ref/ddl-and-loading/creating-a-loading-job#loading-a-user-defined-type-udt-attribute
TYPEDEF TUPLE <f1 INT (1), f2 UINT, f3 STRING (10), f4 DOUBLE > myTuple # define a UDT
CREATE VERTEX v_udt (id STRING PRIMARY KEY, att_udt myTuple)
CREATE GRAPH test_graph (v_udt)
CREATE LOADING JOB load_udt FOR GRAPH test_graph {
DEFINE FILENAME f;
LOAD f TO VERTEX v_udt VALUES ($0, myTuple($1, $2, $3, $4) );
# $1 is loaded as f1, $2 is loaded as f2, and so on
}
RUN LOADING JOB load_udt USING f="./udt.csv"
Now you can invoke above created loading job using rest request https://docs.tigergraph.com/dev/gsql-ref/ddl-and-loading/running-a-loading-job