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

Bryan Pendleton commented on DERBY-3219:
----------------------------------------

I kind of wandered around in the debugger for a while, and I noticed the 
following:

1) The problem appears to occur when the "max" value in question is a SQLVarChar
     whose value is "" (that is, a string of length 0).
2) The underlying exception which causes the problem is a EOFException
3) When reading a SQLVarchar whose value is "", we seem to normally
     expect and handle an EOFException. See, in particular, this section of code
     in SQLChar.readExternal:


            } catch (EOFException eof) {
                if (utflen != 0)
                    throw new EOFException();

                // This is the case for a 0 length string.
                // OR the string was originally streamed in
                // which puts a 0 for utflen but no trailing
                // E0,0,0 markers.
                break readingLoop;
            }

4) When the problem occurs, it seems that we don't get the expected 
EOFException,
    but rather we proceed a bit farther and then get the EOFException at an
    unexpected point.

I'm wondering whether the problem is that the readExternal/writeExternal
implementation for SQL[var]char values of length 0 is flawed, because it
can only handle the case where the SQL[var]char value is at the *end* of
the buffer, but in the case of the MaxMinAggregator, the SQL[var]char value
is buried inside of a larger data structure (with boolean isNull and boolean 
isMax)
bookends around the underlying value), and thus the EOFException occurs
unexpectedly.


> Group by query with many aggregate columns and case statements fails with: 
> ERROR XSDA7: Restore of a serializable or SQLData object of class , attempted 
> to read more data than was originally stored
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-3219
>                 URL: https://issues.apache.org/jira/browse/DERBY-3219
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.3.1.4
>            Reporter: Stan Bradbury
>         Attachments: pivotView.zip
>
>
> using the attached database (v10.3) - " select * from pivotview " fails with 
> the stack trace below.  A view (pivotview_ok) created on a subset of the 
> columns in pivotview executes fine.  Adding one column back into pivotview_ok 
> causes failures most of the time.  See attached for view definitions.
> 2007-11-21 00:58:49.421 GMT Thread[main,5,main] (XID = 2734422), (SESSIONID = 
> 0), (DATABASE = pivotview), (DRDAID = null), Failed Statement is: select * 
> from pivotview
> ERROR XSDA7: Restore of a serializable or SQLData object of class , attempted 
> to read more data than was originally stored
>       at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>       at 
> org.apache.derby.impl.store.raw.data.StreamFileContainer.fetchNext(Unknown 
> Source)
>       at 
> org.apache.derby.impl.store.raw.data.StreamFileContainerHandle.fetchNext(Unknown
>  Source)
>       at org.apache.derby.impl.store.access.sort.MergeScan.mergeARow(Unknown 
> Source)
>       at org.apache.derby.impl.store.access.sort.MergeScan.init(Unknown 
> Source)
>       at 
> org.apache.derby.impl.store.access.sort.MergeSort.openSortScan(Unknown Source)
>       at 
> org.apache.derby.impl.store.access.RAMTransaction.openSortScan(Unknown Source)
>       at 
> org.apache.derby.impl.sql.execute.GroupedAggregateResultSet.loadSorter(Unknown
>  Source)
>       at 
> org.apache.derby.impl.sql.execute.GroupedAggregateResultSet.openCore(Unknown 
> Source)
>       at 
> org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.openCore(Unknown 
> Source)
>       at 
> org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.open(Unknown Source)
>       at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>       at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>       at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
>       at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
>       at org.apache.derby.impl.tools.ij.ij.executeImmediate(Unknown Source)
>       at org.apache.derby.impl.tools.ij.utilMain.doCatch(Unknown Source)
>       at org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(Unknown Source)
>       at org.apache.derby.impl.tools.ij.utilMain.go(Unknown Source)
>       at org.apache.derby.impl.tools.ij.Main.go(Unknown Source)
>       at org.apache.derby.impl.tools.ij.Main.mainCore(Unknown Source)
>       at org.apache.derby.impl.tools.ij.Main14.main(Unknown Source)
>       at org.apache.derby.tools.ij.main(Unknown Source)
> Caused by: java.io.EOFException
>       at java.io.DataInputStream.readBoolean(DataInputStream.java:248)
>       at 
> org.apache.derby.impl.sql.execute.MaxMinAggregator.readExternal(Unknown 
> Source)
>       at 
> org.apache.derby.iapi.services.io.FormatIdInputStream.readObject(Unknown 
> Source)
>       at org.apache.derby.iapi.types.UserType.readExternal(Unknown Source)
>       ... 22 more
> ============= begin nested exception, level (1) ===========
> java.io.EOFException
>       at java.io.DataInputStream.readBoolean(DataInputStream.java:248)
>       at 
> org.apache.derby.impl.sql.execute.MaxMinAggregator.readExternal(Unknown 
> Source)
>       at 
> org.apache.derby.iapi.services.io.FormatIdInputStream.readObject(Unknown 
> Source)
>       at org.apache.derby.iapi.types.UserType.readExternal(Unknown Source)
>       at 
> org.apache.derby.impl.store.raw.data.StreamFileContainer.fetchNext(Unknown 
> Source)
>       at 
> org.apache.derby.impl.store.raw.data.StreamFileContainerHandle.fetchNext(Unknown
>  Source)
>       at org.apache.derby.impl.store.access.sort.MergeScan.mergeARow(Unknown 
> Source)
>       at org.apache.derby.impl.store.access.sort.MergeScan.init(Unknown 
> Source)
>       at 
> org.apache.derby.impl.store.access.sort.MergeSort.openSortScan(Unknown Source)
>       at 
> org.apache.derby.impl.store.access.RAMTransaction.openSortScan(Unknown Source)
>       at 
> org.apache.derby.impl.sql.execute.GroupedAggregateResultSet.loadSorter(Unknown
>  Source)
>       at 
> org.apache.derby.impl.sql.execute.GroupedAggregateResultSet.openCore(Unknown 
> Source)
>       at 
> org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.openCore(Unknown 
> Source)
>       at 
> org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.open(Unknown Source)
>       at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>       at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>       at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
>       at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
>       at org.apache.derby.impl.tools.ij.ij.executeImmediate(Unknown Source)
>       at org.apache.derby.impl.tools.ij.utilMain.doCatch(Unknown Source)
>       at org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(Unknown Source)
>       at org.apache.derby.impl.tools.ij.utilMain.go(Unknown Source)
>       at org.apache.derby.impl.tools.ij.Main.go(Unknown Source)
>       at org.apache.derby.impl.tools.ij.Main.mainCore(Unknown Source)
>       at org.apache.derby.impl.tools.ij.Main14.main(Unknown Source)
>       at org.apache.derby.tools.ij.main(Unknown Source)
> ============= end nested exception, level (1) ===========
> Cleanup action completed

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