英文:
Perform parallel calculations on tables and concatenate the results into one table
问题
我想在DolphinDB中对多个内存表执行并行计算,然后将结果连接到一个表中。
例如,我想创建一个UDF来对表t0执行计算,其中涉及if-else语句:
- 条件为真:返回t0
- 条件为假:返回NULL值
最后,我希望将所有结果连接到一个表中。有人可以帮我编写一个脚本吗?提前感谢。
这里是一个伪代码示例:
def work(){
t0=table(1 2 3 as a, `x`y`z as b, 10.8 7.6 3.5 as c);
if(bad_cond){return NULL}
else{return t0}
}
ploop(work)
英文:
I want to perform parallel calculations on several in-memory tables in DolphinDB and concatenate the results into one table.
For example, I want to create a UDF to perform calculations on a table t0, which involves a if-else statement:
- the condition is true: return t0
- the condition is false: return NULL values
At last, I wish to concatenate all the results into one table. Can anyone help me to write a script? Thanks in advance.
Here is a pseudocode for you:
def work(){
t0=table(1 2 3 as a, `x`y`z as b, 10.8 7.6 3.5 as c);
if(bad_cond){return NULL}
else{return t0}
}
ploop(work)
答案1
得分: 1
参考以下脚本:
def work(p):
if p == 1:
return table(1 2 3 as id)
else:
return NULL
}
loop(work, 1 2 1).unionAll(false)
在这里,loop
返回一个包含子作业结果的元组,然后将输出表传递给 unionAll
进行连接。
英文:
Refer to the following script:
def work(p){
if(p==1) return table(1 2 3 as id)
else return NULL
}
loop(work, 1 2 1).unionAll(false)
Here, loop
returns a tuple containing the results of sub-jobs, and then the output tables are passed to unionAll
to be concatenated.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论