I have a csv file with 2 columns (StateCode & State) and a State vertex (see below). Every time I run the load job to add more states, I would like to load the current datetime into the updateTS attribute. Is there a function or a way to define a parameter for datetime? I can achieve this in a query using now.
USE GRAPH entityMgmtDEV
SET sys.data_root = “@sys_dataroot@”
SET dt = “2019-10-16 10:30:00”
USE GRAPH entityMgmtDEV
CREATE LOADING JOB EEM_Dev_LJ_State FOR GRAPH entityMgmtDEV {
DEFINE FILENAME f = "$sys.data_root/State.csv";
DEFINE HEADER h = "StateCode", "State";
LOAD f
TO VERTEX State VALUES ($"StateCode", $"StateCode", $"State", "$sys.file_name", **"$dt"** )
USING USER_DEFINED_HEADER="h", SEPARATOR=",", HEADER="true", EOL="\n";
}
Vertex - State
(
id STRING,
stateCD STRING,
state STRING,
source STRING COMPRESS,
updateTS DATETIME
)
Thanks,
Nick
Hi Nicholas,
Token function gsql_current_time_epoch(0) will return the current time in Unix epoch seconds. It can be used directly in the loading job for DATETIME attribute.
For more information, please check: https://docs.tigergraph.com/dev/gsql-ref/ddl-and-loading/creating-a-loading-job#built-in-loader-token-functions
Thanks,
Chengbiao
Are there any extra steps needed to convert it the UINT output of the function to DATETIME? You can’t map gsql_current_time_epoch(0) in GraphStudio and if you used that function as a value in the load job it returns a similar error.
Nick
Yes, it’s necessary to convert the output to type STRING for loading job. It has to be done via a user-defined token function.
However, it sounds like it’ll be simpler to get the current time in the user-defined token function directly. For example, put the following code into <tigergraph_root>/dev/gdk/gsql/src/TokenBank/TokenBank.cpp
#include <time.h>
extern “C” void CurrentTime(const char* const iToken[], uint32_t iTokenLen[], uint32_t iTokenNum,
char *const oToken, uint32_t& oTokenLen) {
sprintf(oToken, “%d”, time(NULL));
oTokenLen = 10;
}
And use “CurrentTime(0)” directly in loading job.
Regards,
Chengbiao