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