[ 
https://issues.apache.org/jira/browse/DERBY-3310?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12571209#action_12571209
 ] 

Kathey Marsden commented on DERBY-3310:
---------------------------------------

Thanks again everyone for the help.  
In InsertNode.bindStatement we have:
                        resultSet = 
resultSet.genNormalizeResultSetNode(resultSet, false);
                        
resultColumnList.copyTypesAndLengthsToSource(resultSet.getResultColumns());


ResultSetNode.genNormalizeResultSetNode makes a shallow copy of the 
resultColumnList and
 replaces the expressions with VirtualColumnNodes which still point at the 
source column:
So ultimately we hit this line in ResultColumnList.copyTypesAndLengthsToSource 

        sourceRC.getExpression().setType(resultColumn.getTypeServices());
                
which ends up changing the underlying source column type with the new setType 
method.

As an experiment, I tried commenting that  line in copyTypesAndLengthsToSource 
out, to find out why it is needed and I found that suites.All and derbyall  
passed with the line 
commented out as did the repro for this issue.  I wonder if/why it is needed.

Below is the experimental patch:
Index: java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
===================================================================
--- java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java 
(revision 629575)
+++ java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java 
(working copy)
@@ -1642,7 +1642,7 @@
                        ResultColumn sourceRC = (ResultColumn) 
sourceRCL.elementAt(index);
                        ResultColumn resultColumn = (ResultColumn) 
elementAt(index);
                        sourceRC.setType(resultColumn.getTypeServices());
-                       
sourceRC.getExpression().setType(resultColumn.getTypeServices());
+                       
//sourceRC.getExpression().setType(resultColumn.getTypeServices());
                }
        }


> ASSERT in MergeSort.checkColumnTypes() disallow legal type conversions
> ----------------------------------------------------------------------
>
>                 Key: DERBY-3310
>                 URL: https://issues.apache.org/jira/browse/DERBY-3310
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.4.0.0
>            Reporter: Dyre Tjeldvoll
>            Priority: Minor
>         Attachments: cast-repro.sql
>
>
> The following code 
> CREATE TABLE U (SNAME VARCHAR(32000), TNAME VARCHAR(32000), C1 BIGINT);
> -- This triggers an ASSERT (because 2 is INTEGER and not BIGINT)
> INSERT INTO U(SNAME, TNAME, C1) SELECT DISTINCT SCHEMANAME, TABLENAME, 2
>  FROM SYS.SYSTABLES T JOIN SYS.SYSSCHEMAS S ON T.SCHEMAID = S.SCHEMAID;
> gives
> ERROR XJ001: Java exception: 'ASSERT FAILED col1.getClass() (class 
> org.apache.derby.iapi.types.SQLInteger) expected to be the same as 
> col2.getClass() (class org.apache.derby.iapi.types.SQLLongint): 
> org.apache.derby.shared.common.sanity.AssertFailure'.

-- 
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