DolphinDB:无法解析submitJob提交的函数定义

问题描述 投票:0回答:1

直接用

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

如何将函数名

run_factor
作为字符串传递并在提交的函数内部动态调用它?

sql parallel-processing metaprogramming jobs dolphindb
1个回答
0
投票

您可以使用

makeCall
调用函数,生成SQL元代码,并使用
unionAll
组合查询结果,如以下脚本所示:

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 = table(1:0, [`id], [INT])
        for(i in 0..1){
                fname="factor"+lpad(string(i),4,"0")
                factor=unionAll(factor, sql(select=sqlCol("*"), from=makeCall(dd[fname])).eval())
        }
        return factor 
}
submitJob("test000" , "test000" , run_factor{funlist})
© www.soinside.com 2019 - 2024. All rights reserved.