[ 
https://issues.apache.org/jira/browse/DERBY-2599?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12503027
 ] 

Mamta A. Satoor commented on DERBY-2599:
----------------------------------------

DataTypeDescriptor has a method called getDominantType which compares itself 
with the DTD passed as parameter to getDominantType and creates a new DTD with 
the dominant type of the 2 DTDs, But, while doing so, It was not setting the 
collation information on the new DTD based on the 2 involved DTDs. I have made 
changes into the method which now will set the correct collation information on 
the new DTD. The algorithm, as copied from the method javadoc, is as follows
         * If dealing with character string types, then make sure to set the
         * collation info on the dominant type. Following algorithm will be 
used 
         * for dominant DTD's collation determination. Each of the steps of the 
         * algorithem have been numbered in the comments below and those same 
         * numbers are used in the actual algorithm below so it is easier to 
         * understand and maintain.
         * 
         * Step 1
         * If the DTD for "this" node has the same collation derivation as the 
         * otherDTS, then check if their collation types match too. If the 
         * collation types match too, then DTD for dominant type will get the 
same 
         * collation derivation and type.
         *  
         * Step 2
         * If the collation derivation for DTD for "this" node and otherDTS do 
not 
         * match, then check if one of them has the collation derivation of 
NONE. 
         * If that is the case, then dominant DTD will get the collation type 
and 
         * derivation of DTD whose collation derivation is not NONE.
         * 
         * Step 3
         * If the collation derivation for DTD for "this" node and otherDTS do 
not 
         * match, and none of them have the derivation of NONE then it means 
that 
         * we are dealing with collation derivation of IMPLICIT and EXPLICIT 
and 
         * hence the dominant DTD should get collation derivation of NONE. This 
is 
         * not a possibility in Derby 10.3 because the only 2 possible 
collation 
         * derivation supported are IMPLICIT and NONE.
         * 
         * Step 4
         * If the collation derivation for DTD for "this" node and otherDTS 
match, 
         * then check if the collation types match too. If not, then the 
dominant 
         * DTD should get collation derivation of NONE. 


Now, note that ValueNodeList has a method called getDominantTypeServices where 
it could deal with any number of DTDs to determine the dominant DTD. It calls 
DataTypeDescriptor.getDominantType on 2 DTDs at a time. At the beginning, the 2 
DTDs are the first two in it's vector. It gets an intermediate dominantDTS back 
for those 2 DTDs. Next, it calls DataTypeDescriptor.getDominantType with the 
intermediate dominantDTS and the 3rd element in it's vector and so on and so 
forth. It is not enough to just use 2 DTDs at a time to determine the collation 
info for the final dominantDTS. We need to consider all the DTDs in the vector 
together to determine the correct collation info for the final dominantDTS. The 
algorithm used by ValueNodeList.getDominantTypeServices is in that method's 
javadoc and included here for reference
         * Algorithm for determining collation information
         * This method will check if it is dealing with character string 
datatypes.
         * If yes, then it will check if all the character string datatypes have
         * the same collation derivation and collation type associated with 
them.
         * If not, then the resultant DTD from this method will have collation
         * derivation of NONE. If yes, then the resultant DTD from this method 
will
         * have the same collation derivation and collation type as all the 
         * character string datatypes.


I will commit the code and comment changes in DataTypeDescriptor  and comment 
changes in ValueNodeList.getDominantTypeServices  shortly. Please feel to 
provide feedback if you have any,

> Set correct collation type and derivation on DataTypeDescriptor(DTD).
> ---------------------------------------------------------------------
>
>                 Key: DERBY-2599
>                 URL: https://issues.apache.org/jira/browse/DERBY-2599
>             Project: Derby
>          Issue Type: New Feature
>          Components: SQL
>    Affects Versions: 10.3.0.0
>            Reporter: Mamta A. Satoor
>            Assignee: Mamta A. Satoor
>         Attachments: DERBY2599_collationType_default_UCS_BASIC_v1_diff.txt, 
> DERBY2599_collationType_default_UCS_BASIC_v1_stat.txt, 
> DERBY2599_correct_collation_for_cast_v1_diff.txt, 
> DERBY2599_correct_collation_for_cast_v1_stat.txt, 
> DERBY2599_getNull_should_set_collation_info_v1_diff.txt, 
> DERBY2599_getNull_should_set_collation_info_v1_stat.txt, 
> DERBY2599_IntermediatePatch_v1_diff.txt, 
> DERBY2599_IntermediatePatch_v1_stat.txt, 
> DERBY2599_Set_collation_for_aggregates_v1_diff.txt, 
> DERBY2599_Set_collation_for_aggregates_v1_stat.txt, 
> DERBY2599_Set_collation_for_aggregates_v1_stat.txt, 
> DERBY2599_Set_collation_for_Max_Min_v1_diff.txt, 
> DERBY2599_set_correct_collation_for_params_and_string_functions_v1_diff.txt, 
> DERBY2599_set_correct_collation_for_params_and_string_functions_v1_stat.txt, 
> DERBY2599_Use_collation_of_compilation_schema_and_not_current_schema_diff_v1.txt,
>  
> DERBY2599_Use_collation_of_compilation_schema_and_not_current_schema_stat_v1.txt
>
>
> DTD has TypeDescriptorImpl in it which has 2 new fields, namely, 
> collationType and collationDerivation. These 2 fields are available for all 
> different types of DTDs but only apply to character types. The other 
> datatypes should ignore these 2 fields.
> This Jira is a placeholder for loading the correct values into collationType 
> and collationDerivation.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to