When running the following code directly with run_factor()
, it executes successfully. However, when I use the submitJob
function, an error occurs:
Syntax Error: [line #1] Cannot recognize the token factor0000.
The following is my script:
def factor0000(){
return table(1..100 as id);
}
def factor0001(){
return table(101..200 as id);
}
def run_factor(){
factor="";
for(i in 0..1){
sql0 = "select * from factor0000()"
sql1 = strReplace(sql0 , "factor0000" , "factor" + lpad(string(i) , 4 , "0"))
print(sql1);
res= parseExpr(sql1).eval();
factor+=string(res);
}
return factor;
}
submitJob("test000" , "test000" , run_factor)
getRecentJobs()
How to pass the function name run_factor
as a string and dynamically call it inside the submitted function?
You can use
makeCall
to call the function, generate SQL metacode, and useunionAll
to combine query results, as shown in the following script: