1

I define a function by the following code:

def func(Open,High,Low,Close,20)
xxxxxxxxxxxxxxxxxxxxxxxx
return x,y 

There are two return results in the function “func()”, and I want to select these two results in one select clause. I write a statement as follows:

t=select TimeStamp,funcA(Open,High,Low,Close,20) as factorA,funcB(Open,High,Low,Close,20) as factorB, from xxx

The function is called twice in a select clause which will waste more time. Is there a method to get these two results by calling the function only once?

damie
  • 412
  • 2
  • 7

1 Answers1

0

You should modify the select clause like this: select ...as factor1factor2

t=table(take(now(),3) as TimeStamp, 1..3 as Open, 1..3 as High, 1..3 as Close, 1..3 as Low)
def func(Open, High, Low, Close, num) {
    x=avg(Open)
    y=max(High)
    return x, y
}
select TimeStamp, func(Open, High, Low, Close, 20) as `factor1`factor2 from t
TimeStamp factor1 factor2
2021.09.18T17:10:04.969 2 3
2021.09.18T17:10:04.969 2 3
2021.09.18T17:10:04.969 2 3
dontyousee
  • 458
  • 2
  • 9