Support Questions

Find answers, ask questions, and share your expertise

Using math function methods in NiFi

avatar
Expert Contributor

Hello NiFi Community,

 

I want to convert decimal degree coordinates (e.g. -45.123658) to radians, and I want to use the built-in NiFi math function to do so.  However, simply following the simple example in the Expression Language documentation for math, the example fails.  I keep getting an "unexpected token" error whenever trying to use toDouble or the math function itself.  Anyone have any success with using the math function and any of the methods associated with it, particularly if they take a double as an argument?

 

Since the function is subjectless, I'm :

 

${math("toRadians", ${latitude:toDouble()})}

 

But I've also tried variations of:

 

${latitude:toDouble():math("toRadians", ${latitude})}
${latitude:math("toRadians", ${latitude:toDouble()})}

 

I appreciate any insight.  

2 ACCEPTED SOLUTIONS

avatar
Super Guru

Hi ,

 

Did you try the following:

${latitude:toDecimal():math("toRadians")}

Or

${latitude:math("toRadians")}

View solution in original post

avatar
Expert Contributor

Thank you @SAMSAL.  I can always count on you to respond with good ideas.  It didn't occur to me to include just a single parameter in the math function because the documentation shows using "scalb" and "pow" methods with the second parameter as the value to pass to the input method. But also, I was trying to use a Double because they documentation says "toRadians" only accepts a double, and the NiFi expression language docs shows using a "toDouble()", but "toDouble" doesn't seem to be supported.  Seems to be an inconsistency in the docs.

 

Your suggestions were pretty close.  Below is the final result which did the trick.

 

${latitude:toDecimal():math("toRadians")}

 

Thank you again!

 

 

 

 

 

View solution in original post

2 REPLIES 2

avatar
Super Guru

Hi ,

 

Did you try the following:

${latitude:toDecimal():math("toRadians")}

Or

${latitude:math("toRadians")}

avatar
Expert Contributor

Thank you @SAMSAL.  I can always count on you to respond with good ideas.  It didn't occur to me to include just a single parameter in the math function because the documentation shows using "scalb" and "pow" methods with the second parameter as the value to pass to the input method. But also, I was trying to use a Double because they documentation says "toRadians" only accepts a double, and the NiFi expression language docs shows using a "toDouble()", but "toDouble" doesn't seem to be supported.  Seems to be an inconsistency in the docs.

 

Your suggestions were pretty close.  Below is the final result which did the trick.

 

${latitude:toDecimal():math("toRadians")}

 

Thank you again!