db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pavel Bortnovskiy <pbortnovs...@jefferies.com>
Subject RE: number of parameters
Date Fri, 28 Dec 2012 17:31:26 GMT
Thank you, Sekhar, et al.

I've done so: created a proper User Defined Java class (implementing Externalizable), created
the type in Derby, mapped the function, but it still doesn't seem to work.

Here is what I'm trying to achieve (names such as JAVA_FUNCTION and USER_DEFINED_TYPE are
symbolic):

We have a fairly large SQL with an insanely large case statement.
One of the tables used in the SQL has many columns, 90 of which encode some specific data,
such as timeseries (for simplicity, let's call them Column00 - Column89).

So, we mapped a Java function and then we need to do something like this:

select a,b,c,
  case
    when JAVA_FUNCTION(d,e,f) = 0 then COLUMN00
    when JAVA_FUNCTION(d,e,f) = 1 then COLUMN01
    when JAVA_FUNCTION(d,e,f) = 2 then COLUMN02
                ...
    when JAVA_FUNCTION(d,e,f) = 88 then COLUMN89
    else COLUMN89
 end as col_value
...


But such select causes JAVA_FUNCTION to be invoked 90 times.
So, we tried to simplify this by having a JAVA_FUNCTION which takes the params:

select a,b,c
  JAVA_FUNCTION(d,e,f,COLUMN00,..,COLUMN89) as col_value
 ...

So, that the switch happens in Java, but that's when we ran into the "number of arguments"
limit of 90.

As per your suggestion, I created a UDT which takes 90 parameters and assigns them to the
internal array.
Then an inner function calculates an index into that array based on (d,e,f) and returns the
value without resorting to a switch.

So, I was able to properly define and create the UDT and the function, but have trouble invoking
it.
What I’m attempting to do is:

select a,b,c,
  JAVA_FUNCTION(d,e,f,USER_DEFINED_TYPE(COLUMN00, ... , COLUMN89)) as col_value
  ...

But doing so causes the following error:

java.sql.SQLSyntaxErrorException: 'USER_DEFINED_TYPE' is not recognized as a function or procedure.
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
        at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(Unknown Source)
        at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
Caused by: ERROR 42Y03: 'USER_DEFINED_TYPE' is not recognized as a function or procedure.
        at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
        at org.apache.derby.impl.sql.compile.StaticMethodCallNode.bindExpression(Unknown Source)
        at org.apache.derby.impl.sql.compile.JavaToSQLValueNode.bindExpression(Unknown Source)
        at org.apache.derby.impl.sql.compile.SQLToJavaValueNode.bindExpression(Unknown Source)
        at org.apache.derby.impl.sql.compile.MethodCallNode.bindParameters(Unknown Source)
        at org.apache.derby.impl.sql.compile.StaticMethodCallNode.bindExpression(Unknown Source)
        at org.apache.derby.impl.sql.compile.JavaToSQLValueNode.bindExpression(Unknown Source)
        at org.apache.derby.impl.sql.compile.ResultColumn.bindExpression(Unknown Source)
        at org.apache.derby.impl.sql.compile.ResultColumnList.bindExpressions(Unknown Source)
        at org.apache.derby.impl.sql.compile.SelectNode.bindExpressions(Unknown Source)
        at org.apache.derby.impl.sql.compile.TableOperatorNode.bindExpressions(Unknown Source)
        at org.apache.derby.impl.sql.compile.UnionNode.bindExpressions(Unknown Source)
        at org.apache.derby.impl.sql.compile.TableOperatorNode.bindExpressions(Unknown Source)
        at org.apache.derby.impl.sql.compile.UnionNode.bindExpressions(Unknown Source)
        at org.apache.derby.impl.sql.compile.DMLStatementNode.bindExpressions(Unknown Source)
        at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
        at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
        at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
        at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
        at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown
Source)


What am I doing incorrectly?

Thanks,


-----Original Message-----
From: Sekhar [mailto:kosurusekhar@gmail.com]
Sent: Friday, December 28, 2012 1:22 AM
To: derby-user@db.apache.org
Subject: Re: number of parameters


Pavel Bortnovskiy <pbortnovskiy@...> writes:

>
>
>
> Hello:
>
> we have a need to create a java-mapped function which will take 92
parameters, but we are running into Derby’s limitation:
>
> Caused by: java.sql.SQLException: The limit for the number of
> parameters for
a procedure has been exceeded. Limit is 90 and number of parameters for procedure
>  CALC_VALUES are 92.
>
> http://db.apache.org/derby/docs/10.8/ref/rrefdbmlimits.html
>
> Can this limit either be increased or worked-around?
>
> Thanks,
> Pavel.
>
>
>
Hi Pavel

The best solution is rather than passing 92 method parameters we can create User Defined Type
in Derby. An UDT will point to external java class where we can have all parameters as properties.
now you can use this class as a single parameter.


Regards
Sekhar.





Jefferies archives and monitors outgoing and incoming e-mail. The contents of this email,
including any attachments, are confidential to the ordinary user of the email address to which
it was addressed. If you are not the addressee of this email you may not copy, forward, disclose
or otherwise use it or any part of it in any form whatsoever. This email may be produced at
the request of regulators or in connection with civil litigation. Jefferies accepts no liability
for any errors or omissions arising as a result of transmission. Use by other than intended
recipients is prohibited. In the United Kingdom, Jefferies operates as Jefferies International
Limited; registered in England: no. 1978621; registered office: Vintners Place, 68 Upper Thames
Street, London EC4V 3BJ. Jefferies International Limited is authorised and regulated by the
Financial Services Authority.
Mime
View raw message