submitJob提交的函数中用parseExpr不能解析函数

运行以下代码,直接run_factor()可以,但submitJob报错:Syntax Error: [line #1] Cannot recognize the token factor0000

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()

请问怎么将运行的函数名称使用字符串传进去,在里面动态调用呢?

请先 登录 后评论

1 个回答

wale

submitJob+parseExpr问题,可以参考以下例子:

def factor0000(){
	return table(1..100 as id);
}
def factor0001(){
	return table(101..200 as id);
}
funlist=dict(STRING,ANY)
f=exec name from defs() where name like "factor%"
for (i in f){
        funlist[i]=funcByName(i)
        }
 
def run_factor(dd){
        factor=0
        for(i in 0..1){
//                sql0="select * from factor0000()"
//                sql1=strReplace(sql0,"factor0000","factor"+lpad(string(i),4,"0"))
//                factor=parseExpr(sql1,dd).eval()
                fname="factor"+lpad(string(i),4,"0")
                factor=factor+makeCall(dd[fname]).eval()
        }
        return factor 
}
jodid=submitJob("test000" , "test000" , run_factor{funlist})
getJobReturn(jodid,1)
请先 登录 后评论