db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mamta Satoor" <msat...@gmail.com>
Subject Changes to comparable method in TypeCompiler
Date Tue, 10 Apr 2007 22:01:50 GMT
Hi,

One of the methods in TypeCompiler(TC) interface is
  boolean    comparable(
       TypeId otherType,
       boolean forEquals,
       ClassFactory cf);

The abstract class implementation of TC is BaseTypeCompiler(BTC) and BTC has
a private field called correspondingTypeId which is used as one of the
operands in compareable method implementation. This TypeId is compared with
the first argument to the comparable method (which is the otherType). So,
the thing to note is that the comparison is between two TypeIds and not
TypeDescriptors.

TC also has another method called
 DataTypeDescriptor resolveArithmeticOperation(
       DataTypeDescriptor leftType,
       DataTypeDescriptor rightType,
       String operator
        )
       throws StandardException;
This particular method just throws an exception at the abstract class level
in BTC because it makes sense for only numeric types and hence is
implemented by NumericTypeCompiler. The NumericTypeCompiler uses the
parameters passed to the method to do whatever is required and ignores the
TypeId associated with the NumericTypeCompiler.

This is the background information about how there are 2 different kinds
of methods in TC. One type that uses the TypeId associated with BTC to
implement the methods and the other type which ignore TypeId and just uses
the passed parameters to provide the method implementation.

What I am proposing is to change the comparable method from type 1 to type
2. The reason for this is comparable method for character types should also
check the collation type and derivation while deciding whether the method
should return true or false. But since the collation information is not
associated with TypeId, we need to pass the TypeDescriptors of both the
types that need to be compared. In order to do this, I propose the
comparable method to change as follows

boolean    comparable(
       DataTypeDescriptor leftType,
       DataTypeDescriptor rightType,
       boolean forEquals,
       ClassFactory cf);

This change would require that all the implementation of TC change and all
the callers of this method should change too. The implementation changes in
all the TCs other than CharTypeCompiler would be minimal, ie they will
simply get the TypeId from the first operand rather than using the TypeId
associated with itself and then do the comparison based on that.
CharTypeCompiler will have little more involved changes in the sense that
now it should also compare the collation types and derivations of the 2
operands. We want to disallow comparison between character types with
different collations. as stated on the wiki page
http://wiki.apache.org/db-derby/BuiltInLanguageBasedOrderingDERBY-1478 under
Section Collation Determination Rule 12.

Despite these change, I think it is the right thing to do to make sure
collation gets considered in character type comparisons. It also fits well
with existing TypeCompiler interface.

I would very much appreciate community's response on this approach. In the
mean time, I will go ahead and pursue this to see how the implementation
goes.

thanks,
Mamta

Mime
View raw message