I have created a UDF and used it in a where clause, which is shown in the following figure.
def isZero(number,precision=4){
unit =1\pow(10,precision)
ngUnit =-unit
if(ngUnit < number && number < unit){
return true
}
return false
}
res= select * from diff where isZero(openDiff)
But an error is reported as follows:
Why is that happening? Is there anything I should be aware of when creating a UDF in such a clause?
DolphinDB supports vector operation. In the where clause, the parameter openDiff of your UDF is a column (ie, a vector), so you need to ensure that your function returns a vector of the same length. But the output you designed for your UDF is a Boolean scalar. To solve your problem, refer to the following methods:
(1) change your UDF to a vector function
(2) use each(isZero, openDiff)
(3) Use iif : where iif((openDiff<1.0/pow(10,4) && openDiff>-1.0/pow(10,4)),true,false) == true
(4) use eqFloat(precision=4)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.