如果一个函数算出来一个数组,有多个变量返回,比如100个变量,但是要分列命名,这里有好的写法吗?

如,函数ff返回多个变量

def ff(x){
          return x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x
          }
 select ff(s) `a1`a2`a3`a4`a5`a6`... from table(rand(1.0,10) as s)
请先 登录 后评论

1 个回答

mhxiang

可以通过元编程sqlColAlias实现

sql(sqlColAlias(makeCall(ff,sqlCol(`s)),`a+string(1..60)),table(rand(1.0,10) as s)).eval()
a1                a2                a3                a4                a5                a6                ...
----------------- ----------------- ----------------- ----------------- ----------------- ----------------- ---
0.675343952374533 0.675343952374533 0.675343952374533 0.675343952374533 0.675343952374533 0.675343952374533 ...
0.939932537497953 0.939932537497953 0.939932537497953 0.939932537497953 0.939932537497953 0.939932537497953 ...
0.187748047057539 0.187748047057539 0.187748047057539 0.187748047057539 0.187748047057539 0.187748047057539 ...
0.082222495693713 0.082222495693713 0.082222495693713 0.082222495693713 0.082222495693713 0.082222495693713 ...
0.153666474157944 0.153666474157944 0.153666474157944 0.153666474157944 0.153666474157944 0.153666474157944 ...
0.626400190871209 0.626400190871209 0.626400190871209 0.626400190871209 0.626400190871209 0.626400190871209 ...
0.976464069681242 0.976464069681242 0.976464069681242 0.976464069681242 0.976464069681242 0.976464069681242 ...
0.596477479441092 0.596477479441092 0.596477479441092 0.596477479441092 0.596477479441092 0.596477479441092 ...
0.428009673720226 0.428009673720226 0.428009673720226 0.428009673720226 0.428009673720226 0.428009673720226 ...
0.261356600327417 0.261356600327417 0.261356600327417 0.261356600327417 0.261356600327417 0.261356600327417 ...
请先 登录 后评论