You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Art Majtenyi <am...@us.ibm.com> on 2008/03/13 21:37:01 UTC

STDDEV for Derby

Reference manual says, "You can also create your own aggregates to perform 
other set functions such as calculating the standard deviation."
Has anyone done this?...Is there any docs to help with this?...It's not as 
easy as a scalar function.

Art Majtenyi, amajteny@us.ibm.com
WebSphere Business Monitor Development
IBM Corporation, RTP, NC
O: 919/254-4443, M: 919/302-8827


Re: STDDEV for Derby

Posted by Narayanan <V....@Sun.COM>.
Art Majtenyi wrote:
>
> Reference manual says, "You can also create your own aggregates to 
> perform other set functions such as calculating the standard deviation."
> Has anyone done this?...Is there any docs to help with this?...It's 
> not as easy as a scalar function.
>
> Art Majtenyi, amajteny@us.ibm.com
> WebSphere Business Monitor Development
> IBM Corporation, RTP, NC
> O: 919/254-4443, M: 919/302-8827
>
Hi,

My apologies if my reply was a click too quick.

Would it be please possible to give more details on the specific nature 
of the problem you are facing
while implementing the stored function to calculate the Standard deviation?

Here are my guesses from what I think is the problem you could be facing,

The algorithm for implementing the stored function should not be a 
problem because once
you have the data values you just have to write the computational 
algorithm for calculating the SD
from the set  of values (The ability to write functions and procedures 
in Java brings the complete
set of Java apis into your SQL environment as server side logic.  A 
function or procedure may call
any of the standard Java libraries, any of the standard Java  
extensions, or other third party libraries).

The return type from the function should not be a problem because I 
believe the return type would
be a floating point datatype.

I guess you are worried about the input data that you need to give to 
the function and how
to pass such a large number of input values.

A simple solution I can think of if the input values is very large and 
is very dynamic is to store
the values in a database table. Query this table from the Java program 
associated with this
java stored function and pass this set of values to the SD calculating 
logic.

This way each time you want to modify any data on the input data set you 
would perform the
modifications in the database table and call this function again. This 
would help you modify
the large volume of data, modify it as many times as you want easily 
using simple SQL queries
and just call the function everytime you want to calculate the SD for 
this large dataset.

If you think a table is not required (your dataset is small) you could 
just pass the parameters while
calling the function each time.

Hope the above helps in your application. If you need more 
clarifications pls feel free to ask more
questions. It would be a pleasure to answer.

cheers,
Narayanan

Re: STDDEV for Derby

Posted by Kim Haase <Ca...@Sun.COM>.
It's actually the topic "Aggregates (set functions)" 
(http://db.apache.org/derby/docs/dev/ref/rrefsqlj33923.html). If the 
statement is incorrect, we should fix it.

Kim

Rick Hillegas wrote:
> Hi Art,
> 
> Can you tell us what section of the Reference Guide makes this claim? 
> The old Cloudscape engine offered syntax for creating user-defined 
> aggregates but that machinery does not work in Derby. There is a JIRA 
> for this feature: DERBY-672. You may be able to do what you need by 
> using Derby functions. If you search the codeline for 
> "getMedianTestScore", you will find an example of how to code an 
> aggregating function which compute a median value over a set of rows.
> 
> Hope this helps,
> -Rick
> 
> Art Majtenyi wrote:
>>
>> Reference manual says, "You can also create your own aggregates to 
>> perform other set functions such as calculating the standard deviation."
>> Has anyone done this?...Is there any docs to help with this?...It's 
>> not as easy as a scalar function.
>>
>> Art Majtenyi, amajteny@us.ibm.com
>> WebSphere Business Monitor Development
>> IBM Corporation, RTP, NC
>> O: 919/254-4443, M: 919/302-8827
>>
> 

Re: STDDEV for Derby

Posted by Rick Hillegas <Ri...@Sun.COM>.
Hi Art,

Can you tell us what section of the Reference Guide makes this claim? 
The old Cloudscape engine offered syntax for creating user-defined 
aggregates but that machinery does not work in Derby. There is a JIRA 
for this feature: DERBY-672. You may be able to do what you need by 
using Derby functions. If you search the codeline for 
"getMedianTestScore", you will find an example of how to code an 
aggregating function which compute a median value over a set of rows.

Hope this helps,
-Rick

Art Majtenyi wrote:
>
> Reference manual says, "You can also create your own aggregates to 
> perform other set functions such as calculating the standard deviation."
> Has anyone done this?...Is there any docs to help with this?...It's 
> not as easy as a scalar function.
>
> Art Majtenyi, amajteny@us.ibm.com
> WebSphere Business Monitor Development
> IBM Corporation, RTP, NC
> O: 919/254-4443, M: 919/302-8827
>


Re: STDDEV for Derby

Posted by Narayanan <V....@Sun.COM>.
Art Majtenyi wrote:
>
> Reference manual says, "You can also create your own aggregates to 
> perform other set functions such as calculating the standard deviation."
> Has anyone done this?...Is there any docs to help with this?...It's 
> not as easy as a scalar function.
>
> Art Majtenyi, amajteny@us.ibm.com
> WebSphere Business Monitor Development
> IBM Corporation, RTP, NC
> O: 919/254-4443, M: 919/302-8827
>
Hi,

Derby supports Java Stored procedures which can be used to create any 
function of your choice. You can find more
information about this here

http://wiki.apache.org/db-derby/DerbySQLroutines

Narayanan