Using math.js in Functions

52 views
Skip to first unread message

Tore

unread,
Jul 11, 2016, 3:09:30 PM7/11/16
to OrientDB
Trying to utilize math....() in a function (javascript).
If this can be done, is there a way to use a function in a query? 
e.g. select math.asinh(XXX) as yyy from ...

Luca Garulli

unread,
Jul 11, 2016, 10:03:09 PM7/11/16
to OrientDB
You can use the Java math for sure: https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html

Example:

var value = java.lang.Math.abs( v );



Best Regards,

Luca Garulli
Founder & CEO


--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tore

unread,
Jul 12, 2016, 7:24:55 AM7/12/16
to OrientDB
Thanks Luca.
Still, the question is really about using a function written in Studio/Functions. Lets assume I write a javascript
function in Studio called snug(p), with one parameter. Can I use this in a select statement, e.g. select snug(Sfactor) from Foo...
Saw some discussion about that somewhere. Can this be done?

Luca Garulli

unread,
Jul 12, 2016, 9:03:09 AM7/12/16
to OrientDB
Hi Tore,

Sure you can call any function from SQL.

Best Regards,

Luca Garulli
Founder & CEO


Tore

unread,
Jul 12, 2016, 1:50:26 PM7/12/16
to OrientDB
Indeed. I misread another thread. May be an explicit example should be included in the docs?
Thanks again.

Luca Garulli

unread,
Jul 12, 2016, 2:05:51 PM7/12/16
to OrientDB
You're right, just added this example:


It will go to the official documentation in the next hours.

Best Regards,

Luca Garulli
Founder & CEO


Tore Austrått

unread,
Jul 12, 2016, 3:09:45 PM7/12/16
to orient-...@googlegroups.com
Excellent Luca.
How do I use math.js (which I installed) in Javascript functions?
It obviously works in node. What does it take to reference it in a "Functions-function"?
 

--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/38Oema7nruU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Tore Austrått
phone +47 90657231

Tore

unread,
Jul 19, 2016, 9:06:08 AM7/19/16
to OrientDB
It worked just fine after correcting a mistyping and adding, actually guessing, the phrase: parseFloat(arg). Can someone please
add a few words about this parse-stuff in Functions -  in the doc?


// The Math.log() function returns the natural logarithm (base e) of a number.
return Math.log(parseFloat(arg) + Math.sqrt(parseFloat(arg) * parseFloat(arg) + 1));

select arcsinh(foo) from bigFoo group by, etc delivers what's expected.

Cheers,
Tore
To unsubscribe from this group and stop receiving emails from it, send an email to orient-database+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/38Oema7nruU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-database+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages