db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mamta Satoor" <msat...@gmail.com>
Subject Setting correct collation on return type of a user defined function
Date Tue, 12 Jun 2007 01:48:27 GMT
Hi,

I am working on setting the correct collation on return type of a user
defined function if the return type is of type character string.

The way I am thinking of doing this is at the time of CREATE FUNCTION, when
a RoutineAliasInfo is created, have the TypeDescriptor for return type pick
up the function's schema's collation.

The problem is that information needed to construct a RoutineAliasInfo is
collected by the parser (sqlgrammar.functionDefinition()) when it does not
know how to handle the schema information and hence the TypeDescriptor
created by the parser in sqlgrammar.functionDefinition() with following call
<RETURNS> functionElements[8] = dataTypeCommon()
just takes the default collation type of UCS_BASIC and collation derivation
of IMPLICIT. But that is incorrect for a sample CREATE FUNCTION sql in a
collated database as shown below

CREATE FUNCTION temp.CONCAT_NOCALL(VARCHAR(10), VARCHAR(10)) RETURNS
VARCHAR(20) RETURNS NULL ON NULL INPUT EXTERNAL NAME '
org.apache.derbyTesting.functionTests.tests.lang.RoutineTest.concat'
LANGUAGE JAVA PARAMETER STYLE JAVA;

For a CREATE FUNCTION like above in a collated db, the collation type of
return type should be territory based.

The schema information is available at CreateAliasNode.bindStatement time. I
was thinking of modifying the collation type of return type (returnType
variable in) of RoutineAliasInfo inside CreateAliadNode.bindStatement but
there is not a way to do that currently because RoutineAliasInfo does not
have a method to change the TypeDescriptor of it's return type. I can fix
that easily by adding a new method to RoutineAliasInfo like following

 public void setReturnType(TypeDescriptor typeWithCorrectCollation) {
  returnType = typeWithCorrectCollation;
 }

But the other problem is that there is no way to change a TypeDescriptor
object. All I want to do is something like following in
CreateAliasNode.bindStatement

  if (aliasType == AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR) {
   RoutineAliasInfo rai = (RoutineAliasInfo)aliasInfo;
   TypeDescriptor returnType = rai.getReturnType();
   //pseudo code. Get the schema descriptor sd for function's schema
   returnType.setCollationType(sd.getCollationType());
   rai.setReturnType(returnType);
   }

But since there is no way to change the collation type on the TypeDescriptor
interface, do I just somehow CAST returnType to TypeDescriptorImpl and
change the collation type on it. This (CASTing) doesn't seem right to me but
before I spend too much time on the problem, I wanted to see if anyone had
any ideas/feedback.



thanks,

Mamta

Mime
View raw message