[jira] [Commented] (DERBY-7151) ERROR XSDA7: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2023-03-02 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7151:
---

Looks really similar to (if not just the same) DERBY-7145.

> ERROR XSDA7: Restore of a serializable or SQLData object of class , attempted 
> to read more data than was originally stored
> --
>
> Key: DERBY-7151
> URL: https://issues.apache.org/jira/browse/DERBY-7151
> Project: Derby
>  Issue Type: Bug
>Affects Versions: 10.16.1.1
> Environment:  'Windows 10' Version '10.0' Arch 'amd64'
> Java Info: Vendor 'Eclipse Adoptium' URL 'https://adoptium.net/' Version 
> '17.0.2'
>Reporter: Daniel Gonzalez
>Priority: Major
>
> Unfortunately we can't reproduce this one but have had a customer report of 
> the following crash:
>  
> {quote}Restore of a serializable or SQLData object of class , attempted to 
> read more data than was originally stored
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
> at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
> at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:438)
> at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:360)
> at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
> at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
> at 
> org.apache.derby.impl.jdbc.EmbedResultSet.closeOnTransactionError(EmbedResultSet.java:4663)
> at 
> org.apache.derby.impl.jdbc.EmbedResultSet.movePosition(EmbedResultSet.java:490)
> at org.apache.derby.impl.jdbc.EmbedResultSet.next(EmbedResultSet.java:394)
> at 
> uk.co.screamingfrog.seospider.db.UniqueUrlsTableOperations.getEncodedUrlIdFromDb(UniqueUrlsTableOperations.java:213)
> ... 9 more
> Caused by: ERROR XSDA7: Restore of a serializable or SQLData object of class 
> , attempted to read more data than was originally stored
> at 
> org.apache.derby.shared.common.error.StandardException.newException(StandardException.java:300)
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
> ... 19 more
> Caused by: java.io.EOFException
> at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readDerbyUTF(ArrayInputStream.java:429)
> at 
> org.apache.derby.iapi.types.SQLChar.readExternalFromArray(SQLChar.java:1093)
> at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
> at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1526)
> at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
> at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
> at 
> org.apache.derby.impl.store.access.btree.ControlRow.compareIndexRowFromPageToKey(ControlRow.java:1243)
> at 
> org.apache.derby.impl.store.access.btree.ControlRow.searchForEntry(ControlRow.java:1001)
> at 
> org.apache.derby.impl.store.access.btree.LeafControlRow.search(LeafControlRow.java:328)
> at 
> org.apache.derby.impl.store.access.btree.BranchControlRow.search(BranchControlRow.java:291)
> at 
> org.apache.derby.impl.store.access.btree.BranchControlRow.search(BranchControlRow.java:291)
> at 
> org.apache.derby.impl.store.access.btree.BranchControlRow.search(BranchControlRow.java:291)
> at 
> org.apache.derby.impl.store.access.btree.BTreeScan.positionAtStartForForwardScan(BTreeScan.java:392)
> at 
> org.apache.derby.impl.store.access.btree.BTreeForwardScan.positionAtStartPosition(BTreeForwardScan.java:70)
> at 
> org.apache.derby.impl.store.access.btree.BTreeForwardScan.fetchRows(BTreeForwardScan.java:129)
> at 
> org.apache.derby.impl.store.access.btree.BTreeScan.fetchNextGroup(BTreeScan.java:1682)
> at 
> org.apache.derby.impl.sql.execute.BulkTableScanResultSet.reloadArray(BulkTableScanResultSet.java:424)
> at 
> org.apache.derby.impl.sql.execute.BulkTableScanResultSet.getNextRowCore(BulkTableScanResultSet.java:367)
> at 
> org.apache.derby.impl.sql.execute.IndexRowToBaseRowResultSet.getNextRowCore(IndexRowToBaseRowResultSet.java:346)
> at 
> org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.getNextRowCore(ProjectRestrictResultSet.java:287)
> at 
> org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getNextRow(BasicNoPutResultSetImpl.java:488)
> at 
> org.apache.derby.imp

[jira] [Commented] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-10-12 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7145:
---

So, for the UPDATE case w/o DEFAULT clause:

{code:sql}
CREATE TABLE targetData (ID BIGINT, CS BIGINT);
INSERT INTO targetData VALUES (10, 3), (20, 3), (30, 3), (40, 3), (50, 3), (60, 
3);

CREATE TABLE sourceData (ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

-- Failing
MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN MATCHED THEN UPDATE SET CS = 2;

-- Successful
MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN MATCHED THEN UPDATE SET CS = CAST(2 AS BIGINT);
{code}

Adding a DEFAULT clause makes both variants fail.

Having the DEFAULT clause but effectively updating <= 5 rows completes fine, 
also:

{code:sql}
CREATE TABLE targetData (ID BIGINT, CS BIGINT DEFAULT 1);
INSERT INTO targetData VALUES (10, 3), (20, 3), (30, 3), (40, 3), (50, 3);

CREATE TABLE sourceData (ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

-- Successful
MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN MATCHED THEN UPDATE SET CS = 2;

-- Successful
MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN MATCHED THEN UPDATE SET CS = CAST(2 AS BIGINT);
{code}


> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1, 10.17.0.0
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, derby2.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.Da

[jira] [Commented] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-10-11 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7145:
---

I've misread your modified example – I thought I'm looking at the WHEN MATCHED 
UPDATE case.  The latter appears unaffected by the removal of the DEFAULT 
constraint (as I've noticed in the complex demo).

> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1, 10.17.0.0
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, derby2.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
>   at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
>   at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1518)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1487)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderResultSet.getNextRowCore(TemporaryRowHolderResultSet.java:499)
>   at 
> org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java:148)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.getNextRowCore(UpdateResultSet.java:670)
>

[jira] [Commented] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-10-11 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7145:
---

Just clarifying the repro details – Removing the DEFAULT constraint is not 
possible with the second "Only INSERTs" scenario, for example.

Removing the DEFAULT (and NOT NULL) constraint from the TMP column in my 
initial more complex demo – I'm still seeing the problem in the "Only UPDATEs" 
case, or when the UPDATE count > 5.

> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1, 10.17.0.0
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, derby2.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
>   at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
>   at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1518)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1487)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderResultSet.getNextRowCore(TemporaryRowHolderResultSet.java:499)
>   at 
> org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteR

[jira] [Comment Edited] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-10-10 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov edited comment on DERBY-7145 at 10/10/22 4:16 PM:
-

FWIW, here are simplified test cases:

{code:sql|title=Only UPDATEs}
CREATE TABLE targetData (ID BIGINT, CS BIGINT DEFAULT 1);
INSERT INTO targetData VALUES (10, 3), (20, 3), (30, 3), (40, 3), (50, 3), (60, 
3);

CREATE TABLE sourceData (ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN MATCHED THEN UPDATE SET CS = 2;
{code}

{code:sql|title=Only INSERTs}
CREATE TABLE targetData (ID BIGINT, CS BIGINT DEFAULT 1);

CREATE TABLE sourceData (ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN NOT MATCHED THEN INSERT (ID) VALUES (source.ID);
{code}

So it doesn't appear MERGE UPDATE-specific.


was (Author: stanio):
FWIW, here are simplified test cases:

{code:sql|title=Only UPDATEs}
CREATE TABLE targetData (ID BIGINT, CS BIGINT DEFAULT 1);
INSERT INTO targetData VALUES (10, 3), (20, 3), (30, 3), (40, 3), (50, 3), (60, 
3);

CREATE TABLE sourceData(ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN MATCHED THEN UPDATE SET CS = 2;
{code}

{code:sql|title=Only INSERTs}
CREATE TABLE targetData (ID BIGINT, CS BIGINT DEFAULT 1);

CREATE TABLE sourceData(ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN NOT MATCHED THEN INSERT (ID) VALUES (source.ID);
{code}

So it doesn't appear MERGE UPDATE-specific.

> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, derby2.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory

[jira] [Comment Edited] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-10-10 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov edited comment on DERBY-7145 at 10/10/22 4:15 PM:
-

FWIW, here are simplified test cases:

{code:sql|title=Only UPDATEs}
CREATE TABLE targetData (ID BIGINT, CS BIGINT DEFAULT 1);
INSERT INTO targetData VALUES (10, 3), (20, 3), (30, 3), (40, 3), (50, 3), (60, 
3);

CREATE TABLE sourceData(ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN MATCHED THEN UPDATE SET CS = 2;
{code}

{code:sql|title=Only INSERTs}
CREATE TABLE targetData (ID BIGINT, CS BIGINT DEFAULT 1);

CREATE TABLE sourceData(ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN NOT MATCHED THEN INSERT (ID) VALUES (source.ID);
{code}

So it doesn't appear MERGE UPDATE-specific.


was (Author: stanio):
FWIW, here's are simplified test cases:

{code:sql|title=Only UPDATEs}
CREATE TABLE targetData (ID BIGINT, CS BIGINT DEFAULT 1);
INSERT INTO targetData VALUES (10, 3), (20, 3), (30, 3), (40, 3), (50, 3), (60, 
3);

CREATE TABLE sourceData(ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN MATCHED THEN UPDATE SET CS = 2;
{code}

{code:sql|title=Only INSERTs}
CREATE TABLE targetData (ID BIGINT, CS BIGINT DEFAULT 1);

CREATE TABLE sourceData(ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN NOT MATCHED THEN INSERT (ID) VALUES (source.ID);
{code}

So it doesn't appear MERGE UPDATE-specific.

> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, derby2.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory

[jira] [Comment Edited] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-10-10 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov edited comment on DERBY-7145 at 10/10/22 4:14 PM:
-

FWIW, here's are simplified test cases:

{code:sql|title=Only UPDATEs}
CREATE TABLE targetData (ID BIGINT, CS BIGINT DEFAULT 1);
INSERT INTO targetData VALUES (10, 3), (20, 3), (30, 3), (40, 3), (50, 3), (60, 
3);

CREATE TABLE sourceData(ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN MATCHED THEN UPDATE SET CS = 2;
{code}

{code:sql|title=Only INSERTs}
CREATE TABLE targetData (ID BIGINT, CS BIGINT DEFAULT 1);

CREATE TABLE sourceData(ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN NOT MATCHED THEN INSERT (ID) VALUES (source.ID);
{code}

So it doesn't appear MERGE UPDATE-specific.


was (Author: stanio):
FWIW, here's a simplified test case:

{code:sql}
CREATE TABLE targetData (ID BIGINT, CS BIGINT DEFAULT 1);
--INSERT INTO targetData VALUES (30, 3);

CREATE TABLE sourceData(ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN MATCHED THEN UPDATE SET CS = 2
WHEN NOT MATCHED THEN INSERT (ID) VALUES (source.ID);
{code}


> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, derby2.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExterna

[jira] [Commented] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-10-10 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7145:
---

FWIW, here's a simplified test case:

{code:sql}
CREATE TABLE targetData (ID BIGINT, CS BIGINT DEFAULT 1);
--INSERT INTO targetData VALUES (30, 3);

CREATE TABLE sourceData(ID BIGINT);
INSERT INTO sourceData VALUES (10), (20), (30), (40), (50), (60);

MERGE INTO targetData target USING sourceData source ON target.ID = source.ID
WHEN MATCHED THEN UPDATE SET CS = 2
WHEN NOT MATCHED THEN INSERT (ID) VALUES (source.ID);
{code}


> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, derby2.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
>   at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
>   at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1518)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1487)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderResultSet.getNextRowCore(TemporaryRowHolderResultSet.java:499)
>  

[jira] [Commented] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-08-22 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7144:
---

Fair enough.  Thank you for taking the time to look into it.

{noformat:title=Old minor (driver):  expected:<16> but was:<14>}
at 
org.apache.derbyTesting.functionTests.tests.upgradeTests.BasicSetup.testOldVersion(BasicSetup.java:109)
{noformat}

Looks like some 10.16 setup remnant, but then it doesn't explain why it passes 
just without the patch.

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Fix For: 10.15.2.1, 10.16.1.2, 10.17.0.0
>
> Attachments: branches-10.14.diff, bug-demo.zip, bug-demo2.zip, 
> derby-7144-01-aa-reformatTemporaryRowHolderImpl.diff, 
> derby-7144-02-ae-reformat.diff, 
> derby-7144-03-aa-computeRowTemplateAndTrackIdentityColumnsBetter.diff, 
> derby-7144-1.sql, derby-7144-2.sql, derby-7144-3.sql, derby-7144-default.sql, 
> derby-7144.sql, derby.log, svn-merge.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
> 

[jira] [Commented] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-08-22 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7144:
---

One could compare the diffs themselves – [^branches-10.14.diff] and:

{noformat}
svn diff -x -U12 -c 1903532 ^/db/derby/code/branches/10.16
{noformat}


> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Fix For: 10.15.2.1, 10.16.1.2, 10.17.0.0
>
> Attachments: branches-10.14.diff, bug-demo.zip, bug-demo2.zip, 
> derby-7144-01-aa-reformatTemporaryRowHolderImpl.diff, 
> derby-7144-02-ae-reformat.diff, 
> derby-7144-03-aa-computeRowTemplateAndTrackIdentityColumnsBetter.diff, 
> derby-7144-1.sql, derby-7144-2.sql, derby-7144-3.sql, derby-7144-default.sql, 
> derby-7144.sql, derby.log, svn-merge.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java except

[jira] [Updated] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-08-22 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7144:
--
Attachment: svn-merge.log

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Fix For: 10.15.2.1, 10.16.1.2, 10.17.0.0
>
> Attachments: branches-10.14.diff, bug-demo.zip, bug-demo2.zip, 
> derby-7144-01-aa-reformatTemporaryRowHolderImpl.diff, 
> derby-7144-02-ae-reformat.diff, 
> derby-7144-03-aa-computeRowTemplateAndTrackIdentityColumnsBetter.diff, 
> derby-7144-1.sql, derby-7144-2.sql, derby-7144-3.sql, derby-7144-default.sql, 
> derby-7144.sql, derby.log, svn-merge.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.get

[jira] [Updated] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-08-22 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7144:
--
Attachment: (was: svn-merge.log)

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Fix For: 10.15.2.1, 10.16.1.2, 10.17.0.0
>
> Attachments: branches-10.14.diff, bug-demo.zip, bug-demo2.zip, 
> derby-7144-01-aa-reformatTemporaryRowHolderImpl.diff, 
> derby-7144-02-ae-reformat.diff, 
> derby-7144-03-aa-computeRowTemplateAndTrackIdentityColumnsBetter.diff, 
> derby-7144-1.sql, derby-7144-2.sql, derby-7144-3.sql, derby-7144-default.sql, 
> derby-7144.sql, derby.log, svn-merge.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLException

[jira] [Comment Edited] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-08-21 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov edited comment on DERBY-7144 at 8/22/22 4:43 AM:


I'm using Subversion 1.14.2 on Windows 10.  We're seeing 2 [tree 
conflicts|https://svnbook.red-bean.com/nightly/en/svn.tour.treeconflicts.html] 
after the first command:

{noformat}
svn merge -c 1903532 ^/db/derby/code/branches/10.16
--- Merging r1903532 into '.':
   C java/org.apache.derby.engine
   C java/org.apache.derby.tests
{noformat}

because of the rename:

{noformat}
java/engine → java/org.apache.derby.engine
java/testing → java/org.apache.derby.tests
{noformat}

that appears to have happened in 
[r1833236|https://svn.apache.org/viewvc?view=revision&revision=1833236] 
sometime before the 10.15 branch has been created.  In my experience tree 
conflicts could be only dealt with manually so I postpone their resolution at 
this stage.  Then I execute the following two commands to solve the tree 
conflicts:

{noformat}
svn merge -c 1903532 
^/db/derby/code/branches/10.16/java/org.apache.derby.engine java/engine
svn merge -c 1903532 ^/db/derby/code/branches/10.16/java/org.apache.derby.tests 
java/testing
{noformat}

The first one results in a one-line content conflict in {{InsertNode.java}}:

{noformat:title="Target" (10.14, line 156)}
} catch (org.apache.derby.iapi.error.StandardException e) {
{noformat}

{noformat:title="Source" (10.16, line 159)}
} catch (org.apache.derby.shared.common.error.StandardException 
e) {
{noformat}

I solve it by using the original 10.14 line but adjusting the indentation as in 
10.16.

Finally, one needs to mark the tree conflicts as resolved:

{noformat}
svn resolve --accept working java/org.apache.derby.engine
svn resolve --accept working java/org.apache.derby.tests
{noformat}

See [^svn-merge.log] (the {{\^}} is escaped as {{\^\^}} on the Windows 
command-line).

You could go over this again, or you could use the patch I've already supplied 
here:

{noformat}
svn patch branch-10.14.diff .
{noformat}

The latter doesn't appear to apply the SVN property changes ({{merge-info}}).



was (Author: stanio):
I'm using Subversion 1.14.2 on Windows 10.  We're seeing 2 [tree 
conflicts|https://svnbook.red-bean.com/nightly/en/svn.tour.treeconflicts.html] 
after the first command:

{noformat}
svn merge -c 1903532 ^/db/derby/code/branches/10.16
--- Merging r1903532 into '.':
   C java/org.apache.derby.engine
   C java/org.apache.derby.tests
{noformat}

because of the rename:

{noformat}
java/engine → java/org.apache.derby.engine
java/testing → java/org.apache.derby.tests
{noformat}

that appears to have happened in 
[r1833236|https://svn.apache.org/viewvc?view=revision&revision=1833236] 
sometime before the 10.15 branch has been created.  In my experience tree 
conflicts could be only dealt with manually so I postpone their resolution at 
this stage.  Then I execute the following two commands to solve the tree 
conflicts:

{noformat}
svn merge -c 1903532 
^/db/derby/code/branches/10.16/java/org.apache.derby.engine java/engine
svn merge -c 1903532 ^/db/derby/code/branches/10.16/java/org.apache.derby.tests 
java/testing
{noformat}

The first one results in a one-line content conflict in {{InsertNode.java}}:

{noformat:title="Target" (10.14, line 156)}
} catch (org.apache.derby.iapi.error.StandardException e) {
{noformat}

{noformat:title="Source" (10.16, line 159)}
} catch (org.apache.derby.shared.common.error.StandardException 
e) {
{noformat}

I solve it by using the original 10.14 line but adjusting the indentation as in 
10.16.

Finally, one needs to mark the tree conflicts as resolved:

{noformat}
svn resolve --accept working java/org.apache.derby.engine
svn resolve --accept working java/org.apache.derby.tests
{noformat}

See [^svn-merge.log] (the {{^}} is escaped as {{^^}} on the Windows 
command-line).

You could go over this again, or you could use the patch I've already supplied 
here:

{noformat}
svn patch branch-10.14.diff .
{noformat}

The latter doesn't appear to apply the SVN property changes ({{merge-info}}).


> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Fix For: 10.15.2.1, 10.16.1.2, 10.17.0.0
>
> Attachments: branches-10.14.diff, bug-demo.zip, bug-de

[jira] [Commented] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-08-21 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7144:
---

I'm using Subversion 1.14.2 on Windows 10.  We're seeing 2 [tree 
conflicts|https://svnbook.red-bean.com/nightly/en/svn.tour.treeconflicts.html] 
after the first command:

{noformat}
svn merge -c 1903532 ^/db/derby/code/branches/10.16
--- Merging r1903532 into '.':
   C java/org.apache.derby.engine
   C java/org.apache.derby.tests
{noformat}

because of the rename:

{noformat}
java/engine → java/org.apache.derby.engine
java/testing → java/org.apache.derby.tests
{noformat}

that appears to have happened in 
[r1833236|https://svn.apache.org/viewvc?view=revision&revision=1833236] 
sometime before the 10.15 branch has been created.  In my experience tree 
conflicts could be only dealt with manually so I postpone their resolution at 
this stage.  Then I execute the following two commands to solve the tree 
conflicts:

{noformat}
svn merge -c 1903532 
^/db/derby/code/branches/10.16/java/org.apache.derby.engine java/engine
svn merge -c 1903532 ^/db/derby/code/branches/10.16/java/org.apache.derby.tests 
java/testing
{noformat}

The first one results in a one-line content conflict in {{InsertNode.java}}:

{noformat:title="Target" (10.14, line 156)}
} catch (org.apache.derby.iapi.error.StandardException e) {
{noformat}

{noformat:title="Source" (10.16, line 159)}
} catch (org.apache.derby.shared.common.error.StandardException 
e) {
{noformat}

I solve it by using the original 10.14 line but adjusting the indentation as in 
10.16.

Finally, one needs to mark the tree conflicts as resolved:

{noformat}
svn resolve --accept working java/org.apache.derby.engine
svn resolve --accept working java/org.apache.derby.tests
{noformat}

See [^svn-merge.log] (the {{^}} is escaped as {{^^}} on the Windows 
command-line).

You could go over this again, or you could use the patch I've already supplied 
here:

{noformat}
svn patch branch-10.14.diff .
{noformat}

The latter doesn't appear to apply the SVN property changes ({{merge-info}}).


> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Fix For: 10.15.2.1, 10.16.1.2, 10.17.0.0
>
> Attachments: branches-10.14.diff, bug-demo.zip, bug-demo2.zip, 
> derby-7144-01-aa-reformatTemporaryRowHolderImpl.diff, 
> derby-7144-02-ae-reformat.diff, 
> derby-7144-03-aa-computeRowTemplateAndTrackIdentityColumnsBetter.diff, 
> derby-7144-1.sql, derby-7144-2.sql, derby-7144-3.sql, derby-7144-default.sql, 
> derby-7144.sql, derby.log, svn-merge.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   a

[jira] [Updated] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-08-21 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7144:
--
Attachment: svn-merge.log

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Fix For: 10.15.2.1, 10.16.1.2, 10.17.0.0
>
> Attachments: branches-10.14.diff, bug-demo.zip, bug-demo2.zip, 
> derby-7144-01-aa-reformatTemporaryRowHolderImpl.diff, 
> derby-7144-02-ae-reformat.diff, 
> derby-7144-03-aa-computeRowTemplateAndTrackIdentityColumnsBetter.diff, 
> derby-7144-1.sql, derby-7144-2.sql, derby-7144-3.sql, derby-7144-default.sql, 
> derby-7144.sql, derby.log, svn-merge.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.get

[jira] [Commented] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-08-21 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7145:
---

Just for the record: After applying the fix for DERBY-7144 I'm still seeing the 
same results/exceptions with this particular case.

> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, derby2.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
>   at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
>   at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1518)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1487)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderResultSet.getNextRowCore(TemporaryRowHolderResultSet.java:499)
>   at 
> org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java:148)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.getNextRowCore(UpdateResultSet.java:670)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.collectAffectedRows(U

[jira] [Commented] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-08-21 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7144:
---

Would this be backported to the 10.15 and 10.14 version branches as well?

[^branches-10.14.diff] – FWIW, I've merged the 10.16 patch to 10.14:

{noformat}
svn merge -c 1903532 ^/db/derby/code/branches/10.16
svn merge -c 1903532 
^/db/derby/code/branches/10.16/java/org.apache.derby.engine java/engine
svn merge -c 1903532 ^/db/derby/code/branches/10.16/java/org.apache.derby.tests 
java/testing
{noformat}

and I've done a 
[build|http://svn.apache.org/viewvc/db/derby/code/trunk/BUILDING.html?view=co]:

{noformat}
ant -quiet clobber buildsource buildjars
{noformat}

Using the patched version my bug-demo appears to work without failure.


> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Fix For: 10.16.1.2, 10.17.0.0
>
> Attachments: branches-10.14.diff, bug-demo.zip, bug-demo2.zip, 
> derby-7144-01-aa-reformatTemporaryRowHolderImpl.diff, 
> derby-7144-02-ae-reformat.diff, 
> derby-7144-03-aa-computeRowTemplateAndTrackIdentityColumnsBetter.diff, 
> derby-7144-1.sql, derby-7144-2.sql, derby-7144-3.sql, derby-7144-default.sql, 
> derby-7144.sql, derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.

[jira] [Updated] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-08-21 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7144:
--
Attachment: branches-10.14.diff

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Fix For: 10.16.1.2, 10.17.0.0
>
> Attachments: branches-10.14.diff, bug-demo.zip, bug-demo2.zip, 
> derby-7144-01-aa-reformatTemporaryRowHolderImpl.diff, 
> derby-7144-02-ae-reformat.diff, 
> derby-7144-03-aa-computeRowTemplateAndTrackIdentityColumnsBetter.diff, 
> derby-7144-1.sql, derby-7144-2.sql, derby-7144-3.sql, derby-7144-default.sql, 
> derby-7144.sql, derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExce

[jira] [Commented] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-08-01 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7145:
---

{quote}
[^bug-demo3.zip] – a revision of 
[bug-demo2.zip|https://issues.apache.org/jira/browse/DERBY-7144?focusedCommentId=17573279&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-17573279]
 in DERBY-7144.
{quote}

{code:sql}
-- insertNewAggregations
INSERT INTO AGGREGATEDATA (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT, TMP)
SELECT CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT, 65
  FROM TABLE (FAUX_BULK_DATA()) source
 WHERE NOT EXISTS (SELECT 1 FROM AGGREGATEDATA target
WHERE target.AGGDATE = source.AGGDATE
  AND target.CATEGORY = source.CATEGORY)

-- updateExistingAggregations
MERGE INTO AGGREGATEDATA target
USING TABLE (FAUX_BULK_DATA()) source
   ON target.CATEGORY = source.CATEGORY
  AND target.AGGDATE = source.AGGDATE
 WHEN MATCHED THEN UPDATE SET
  VALUE = CASE WHEN target.TMP > 63 THEN target.VALUE ELSE target.VALUE + 
source.VALUE END,
  ATTIME = CASE WHEN target.TMP > 63 OR source.ATTIME < target.ATTIME THEN 
target.ATTIME ELSE source.ATTIME END,
  AGGCOUNT = CASE WHEN target.TMP > 63 THEN target.AGGCOUNT ELSE 
target.AGGCOUNT + source.AGGCOUNT END,
  TMP = 2
{code}

As given in the description, the TMP column type is changed from BOOLEAN to:

{code:sql}
  TMP   BIGINTDEFAULT 1 NOT NULL,
{code}


> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, derby2.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(S

[jira] [Comment Edited] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-08-01 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov edited comment on DERBY-7145 at 8/1/22 7:46 PM:
---

{quote}
_\[May be related to DERBY-7144.\]_
{quote}

Doesn't appear affected by the presence or absence of GENERATED AS IDENTITY 
column – if I remove the ID column from the original demo, and declare instead 
({{sqlStatements.properties}}):

{code:sql|title=TABLE AGGREGATEDATA}
  PRIMARY KEY (AGGDATE, CATEGORY)
{code}

the problem is still observed.


was (Author: stanio):
{quote}
_\[May be related to DERBY-7144.\]_
{quote}

Doesn't appear affected by the presence or absence of GENERATED AS IDENTITY 
column – if I remote the ID column from the original demo, and declare instead 
({{sqlStatements.properties}}):

{code:sql|title=TABLE AGGREGATEDATA}
  PRIMARY KEY (AGGDATE, CATEGORY)
{code}

the problem is still observed.

> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, derby2.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
>   at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
>   at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
>   at 
> org.apache.derb

[jira] [Updated] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-08-01 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7145?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7145:
--
Attachment: derby2.log

> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, derby2.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
>   at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
>   at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1518)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1487)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderResultSet.getNextRowCore(TemporaryRowHolderResultSet.java:499)
>   at 
> org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java:148)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.getNextRowCore(UpdateResultSet.java:670)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.collectAffectedRows(UpdateResultSet.java:656)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.open(UpdateResultSet.java:272)
>   at 
> org.apache.derby.impl.sql.exe

[jira] [Commented] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-08-01 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7145:
---

{quote}
_\[May be related to DERBY-7144.\]_
{quote}

Doesn't appear affected by the presence or absence of GENERATED AS IDENTITY 
column – if I remote the ID column from the original demo, and declare instead 
({{sqlStatements.properties}}):

{code:sql|title=TABLE AGGREGATEDATA}
  PRIMARY KEY (AGGDATE, CATEGORY)
{code}

the problem is still observed.

> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
>   at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
>   at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1518)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1487)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderResultSet.getNextRowCore(TemporaryRowHolderResultSet.java:499)
>   at 
> org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteR

[jira] [Updated] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-08-01 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7145?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7145:
--
Attachment: sysinfo.txt

> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10 , JDK 11, Derby 10.15.2.0;
> Windows 10 , JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
>   at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
>   at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1518)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1487)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderResultSet.getNextRowCore(TemporaryRowHolderResultSet.java:499)
>   at 
> org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java:148)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.getNextRowCore(UpdateResultSet.java:670)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.collectAffectedRows(UpdateResultSet.java:656)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.open(UpdateResultSet.java:272)
>   at 
> org.apache.derby.impl.sql.execute.Matc

[jira] [Updated] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-08-01 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7145?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7145:
--
Environment: 
Windows 10, JDK 8, Derby 10.14.2.0;
Windows 10, JDK 11, Derby 10.15.2.0;
Windows 10, JDK 17, Derby 10.16.1.1.


  was:
Windows 10, JDK 8, Derby 10.14.2.0;
Windows 10 , JDK 11, Derby 10.15.2.0;
Windows 10 , JDK 17, Derby 10.16.1.1.



> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
>   at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
>   at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1518)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1487)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderResultSet.getNextRowCore(TemporaryRowHolderResultSet.java:499)
>   at 
> org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java:148)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.getNextRowCore(UpdateResultSet.java:670)
>   at 
> org.apache.derby.impl.

[jira] [Updated] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-08-01 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7145?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7145:
--
Attachment: derby.log

> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10 , JDK 11, Derby 10.15.2.0;
> Windows 10 , JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip, derby.log, sysinfo.txt
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
>   at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
>   at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1518)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1487)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderResultSet.getNextRowCore(TemporaryRowHolderResultSet.java:499)
>   at 
> org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java:148)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.getNextRowCore(UpdateResultSet.java:670)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.collectAffectedRows(UpdateResultSet.java:656)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.open(UpdateResultSet.java:272)
>   at 
> org.apache.derby.impl.sql.execute.Matchi

[jira] [Comment Edited] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-31 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov edited comment on DERBY-7144 at 7/31/22 11:34 AM:
-

I want to point out the magic numbers (ratio?) again:

{noformat:title=MERGE resulting in UPDATEs only – OK}
$ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
{noformat}

{noformat:title=MERGE resulting in 6 UPDATEs and 5 INSERTs – OK}
$ java -cp "classes;lib/*" net.example.derby.BugDemo -seed 6 -merge -print
{noformat}

{noformat:title=MERGE resulting in 5 UPDATEs and 6 INSERTs – FAILING}
$ java -cp "classes;lib/*" net.example.derby.BugDemo -seed 5 -merge -print
{noformat}

{noformat:title=MERGE resulting in INSERTs only – FAILING}
$ java -cp "classes;lib/*" net.example.derby.BugDemo -merge -print
{noformat}

The {{-workaround}} performs multiple MERGEs of a single row, for each row of 
the source.


was (Author: stanio):
I want to point out the magic numbers (ratio?) again:

{noformat:title=MERGE resulting in UPDATEs only – OK}
$ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
{noformat}

{noformat:title=MERGE resulting in 6 UPDATEs and 5 INSERTs – OK}
$ java -cp "classes;lib/*" net.example.derby.BugDemo -seed 6 -merge -print
{noformat}

{noformat:title=MERGE resulting in 5 UPDATEs and 6 INSERTs – FAILING}
$ java -cp "classes;lib/*" net.example.derby.BugDemo -seed 5 -merge -print
{noformat}

{noformat:title=MERGE resulting in INSERTs only – FAILING}
$ java -cp "classes;lib/*" net.example.derby.BugDemo -merge -print
{noformat}


> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip, bug-demo2.zip, derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.

[jira] [Commented] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-31 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7144:
---

I want to point out the magic numbers (ratio?) again:

{noformat:title=MERGE resulting in UPDATEs only – OK}
$ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
{noformat}

{noformat:title=MERGE resulting in 6 UPDATEs and 5 INSERTs – OK}
$ java -cp "classes;lib/*" net.example.derby.BugDemo -seed 6 -merge -print
{noformat}

{noformat:title=MERGE resulting in 5 UPDATEs and 6 INSERTs – FAILING}
$ java -cp "classes;lib/*" net.example.derby.BugDemo -seed 5 -merge -print
{noformat}

{noformat:title=MERGE resulting in INSERTs only – FAILING}
$ java -cp "classes;lib/*" net.example.derby.BugDemo -merge -print
{noformat}


> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip, bug-demo2.zip, derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> So

[jira] [Comment Edited] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov edited comment on DERBY-7144 at 7/31/22 1:25 AM:


Could be specific to the use of a table function as a source – do you get the 
exception using the attached demo?  In my production use case, I'm using a 
table function performing an aggregate select from a [temporary 
table|https://db.apache.org/derby/docs/10.14/ref/rrefdeclaretemptable.html] in 
the [current 
connection/transaction|https://db.apache.org/derby/docs/10.14/devguide/cdevspecial29620.html],
 and I'm getting the exception.


was (Author: stanio):
Could be specific to the use of a table function as a source – do you get the 
exception using the attached demo?  In my production use case, I'm using a 
table function performing an aggregate select from a temporary table, and I'm 
getting the exception.

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip, bug-demo2.zip, derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.Generi

[jira] [Commented] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7144:
---

Could be specific to the use of a table function as a source – do you get the 
exception using the attached demo?  In my production use case, I'm using a 
table function performing an aggregate select from a temporary table, and I'm 
getting the exception.

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip, bug-demo2.zip, derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
> at 
> org.apache.derb

[jira] [Updated] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-07-30 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7145?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7145:
--
Attachment: (was: bug-demo3.zip)

> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10 , JDK 11, Derby 10.15.2.0;
> Windows 10 , JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
>   at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
>   at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1518)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1487)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderResultSet.getNextRowCore(TemporaryRowHolderResultSet.java:499)
>   at 
> org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java:148)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.getNextRowCore(UpdateResultSet.java:670)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.collectAffectedRows(UpdateResultSet.java:656)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.open(UpdateResultSet.java:272)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseC

[jira] [Updated] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-07-30 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7145?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7145:
--
Attachment: bug-demo3.zip

> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10 , JDK 11, Derby 10.15.2.0;
> Windows 10 , JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
>   at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
>   at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1518)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1487)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderResultSet.getNextRowCore(TemporaryRowHolderResultSet.java:499)
>   at 
> org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java:148)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.getNextRowCore(UpdateResultSet.java:670)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.collectAffectedRows(UpdateResultSet.java:656)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.open(UpdateResultSet.java:272)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantActi

[jira] [Commented] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7144:
---

Updated [^bug-demo.zip] and [^bug-demo2.zip]:

{code}
--- a/src/net/example/derby/BugDemo.java
+++ b/src/net/example/derby/BugDemo.java
@@ -31,7 +31,7 @@
 static String statement(String name) {
 if (sqlStatements == null) {
 sqlStatements = new Properties();
-Path file = baseDir.resolve("SQLStatements.properties");
+Path file = baseDir.resolve("sqlStatements.properties");
 try (InputStream in = Files.newInputStream(file)) {
 sqlStatements.load(in);
 } catch (IOException e) {
{code}

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip, bug-demo2.zip, derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JAR

[jira] [Updated] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7144:
--
Attachment: bug-demo.zip
bug-demo2.zip

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip, bug-demo2.zip, derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
> at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
> at org.apache.derby.impl.jdbc.Util.javaException(Util.java:274)
> at 
> org.apache.

[jira] [Updated] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7144:
--
Attachment: (was: bug-demo.zip)

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
> at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
> at org.apache.derby.impl.jdbc.Util.javaException(Util.java:274)
> at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQ

[jira] [Updated] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7144:
--
Attachment: (was: bug-demo2.zip)

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
> at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
> at org.apache.derby.impl.jdbc.Util.javaException(Util.java:274)
> at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInS

[jira] [Updated] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7144:
--
Environment: 
Windows 10, JDK 8, Derby 10.14.2.0;
Windows 10, JDK 11, Derby 10.15.2.0;
Windows 10, JDK 17, Derby 10.16.1.1.

  was:
Windows 10; JDK 8; Derby 10.14.2.0;
Windows 10; JDK 11; Derby 10.15.2.0;
Windows 10; JDK 17; Derby 10.16.1.1.


> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10, JDK 11, Derby 10.15.2.0;
> Windows 10, JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip, bug-demo2.zip, derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.

[jira] [Updated] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-07-30 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7145?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7145:
--
Environment: 
Windows 10, JDK 8, Derby 10.14.2.0;
Windows 10 , JDK 11, Derby 10.15.2.0;
Windows 10 , JDK 17, Derby 10.16.1.1.


  was:
Windows 10, JDK 8 ,Derby 10.14.2.0;
Windows 10 , JDK 11 ,Derby 10.15.2.0;
Windows 10 , JDK 17 ,Derby 10.16.1.1.



> MERGE UPDATE failing: Restore of a serializable or SQLData object of class , 
> attempted to read more data than was originally stored
> ---
>
> Key: DERBY-7145
> URL: https://issues.apache.org/jira/browse/DERBY-7145
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10, JDK 8, Derby 10.14.2.0;
> Windows 10 , JDK 11, Derby 10.15.2.0;
> Windows 10 , JDK 17, Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo3.zip
>
>
> _\[May be related to DERBY-7144.\]_
> [^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
> Copy the Derby JARs to a {{lib/}} subdirectory; Compile:
> {noformat}
> $ mkdir classes
> $ javac -d classes src/net/example/derby/*.java
> {noformat}
> Run to see the problem:
> {noformat}
> $ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
> {noformat}
> {noformat}
> Exception in thread "main" java.sql.SQLException: Restore of a serializable 
> or SQLData object of class , attempted to read more data than was originally 
> stored
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
>   at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
>   at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
>   at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
>   at net.example.derby.BugDemo.run(BugDemo.java:254)
>   at net.example.derby.BugDemo.main(BugDemo.java:224)
> Caused by: 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(StandardException.java:290)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
>   ... 13 more
> Caused by: java.io.EOFException
>   at 
> org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
>   at 
> org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
>   at 
> org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
>   at 
> org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
>   at 
> org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
>   at 
> org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1518)
>   at 
> org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1487)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderResultSet.getNextRowCore(TemporaryRowHolderResultSet.java:499)
>   at 
> org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java:148)
>   at 
> org.apache.derby.impl.sql.execute.UpdateResultSet.getNextRowCore(UpdateResultSet.java:670)
>   at 
> org.apache.derby.impl.sql.execute.UpdateRe

[jira] [Created] (DERBY-7145) MERGE UPDATE failing: Restore of a serializable or SQLData object of class , attempted to read more data than was originally stored

2022-07-30 Thread Stanimir Stamenkov (Jira)
Stanimir Stamenkov created DERBY-7145:
-

 Summary: MERGE UPDATE failing: Restore of a serializable or 
SQLData object of class , attempted to read more data than was originally stored
 Key: DERBY-7145
 URL: https://issues.apache.org/jira/browse/DERBY-7145
 Project: Derby
  Issue Type: Bug
  Components: SQL
Affects Versions: 10.16.1.1, 10.15.2.0, 10.14.2.0
 Environment: Windows 10, JDK 8 ,Derby 10.14.2.0;
Windows 10 , JDK 11 ,Derby 10.15.2.0;
Windows 10 , JDK 17 ,Derby 10.16.1.1.

Reporter: Stanimir Stamenkov
 Attachments: bug-demo3.zip

_\[May be related to DERBY-7144.\]_

[^bug-demo3.zip] – a revision of {{bug-demo2.zip}} in DERBY-7144.  Extract;  
Copy the Derby JARs to a {{lib/}} subdirectory; Compile:

{noformat}
$ mkdir classes
$ javac -d classes src/net/example/derby/*.java
{noformat}

Run to see the problem:

{noformat}
$ java -cp "classes;lib/*" net.example.derby.BugDemo -seed -merge -print
{noformat}

{noformat}
Exception in thread "main" java.sql.SQLException: Restore of a serializable or 
SQLData object of class , attempted to read more data than was originally stored
at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:431)
at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
at 
org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
at 
org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
at 
org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1436)
at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
at net.example.derby.BugDemo.mergeData(BugDemo.java:125)
at net.example.derby.BugDemo.run(BugDemo.java:254)
at net.example.derby.BugDemo.main(BugDemo.java:224)
Caused by: 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(StandardException.java:290)
at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
... 13 more
Caused by: java.io.EOFException
at 
org.apache.derby.iapi.services.io.ArrayInputStream.readLong(ArrayInputStream.java:323)
at 
org.apache.derby.iapi.types.SQLLongint.readExternal(SQLLongint.java:184)
at 
org.apache.derby.iapi.types.DataType.readExternalFromArray(DataType.java:276)
at 
org.apache.derby.impl.store.raw.data.StoredPage.readRecordFromArray(StoredPage.java:5676)
at 
org.apache.derby.impl.store.raw.data.StoredPage.restoreRecordFromSlot(StoredPage.java:1514)
at 
org.apache.derby.impl.store.raw.data.BasePage.fetchFromSlot(BasePage.java:450)
at 
org.apache.derby.impl.store.raw.data.CachedPage.fetchFromSlot(CachedPage.java:53)
at 
org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1518)
at 
org.apache.derby.impl.store.access.conglomerate.GenericScanController.fetch(GenericScanController.java:1487)
at 
org.apache.derby.impl.sql.execute.TemporaryRowHolderResultSet.getNextRowCore(TemporaryRowHolderResultSet.java:499)
at 
org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java:148)
at 
org.apache.derby.impl.sql.execute.UpdateResultSet.getNextRowCore(UpdateResultSet.java:670)
at 
org.apache.derby.impl.sql.execute.UpdateResultSet.collectAffectedRows(UpdateResultSet.java:656)
at 
org.apache.derby.impl.sql.execute.UpdateResultSet.open(UpdateResultSet.java:272)
at 
org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.executeConstantAction(MatchingClauseConstantAction.java:183)
at 
org.apache.derby.impl.sql.execute.MergeResultSet.open(MergeResultSet.java:124)
at 
org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(GenericPreparedStatement.java:472)
at 
org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:351)
at 
org.apache.derby.impl.j

[jira] [Updated] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7144:
--
Affects Version/s: 10.16.1.1
   10.15.2.0

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0, 10.15.2.0, 10.16.1.1
> Environment: Windows 10; JDK 8; Derby 10.14.2.0;
> Windows 10; JDK 11; Derby 10.15.2.0;
> Windows 10; JDK 17; Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip, bug-demo2.zip, derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
> at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
> at org.apache.derby.impl.jdbc.Util.javaException(Util.java:274)
> at 
> org.

[jira] [Commented] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7144:
---

[^bug-demo2.zip] – offers a {{-workaround2}} option that uses just two 
statements (no batch, no parameters):

{code:sql}
-- insertNewAggregations
INSERT INTO AGGREGATEDATA (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT, TMP)
SELECT CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT, TRUE
  FROM TABLE (FAUX_BULK_DATA()) source
 WHERE NOT EXISTS (SELECT 1 FROM AGGREGATEDATA target
WHERE target.AGGDATE = source.AGGDATE
  AND target.CATEGORY = source.CATEGORY)

-- updateExistingAggregations
MERGE INTO AGGREGATEDATA target
USING TABLE (FAUX_BULK_DATA()) source
   ON target.CATEGORY = source.CATEGORY
  AND target.AGGDATE = source.AGGDATE
 WHEN MATCHED THEN UPDATE SET
  VALUE = CASE WHEN target.TMP THEN target.VALUE ELSE target.VALUE + 
source.VALUE END,
  ATTIME = CASE WHEN target.TMP OR source.ATTIME < target.ATTIME THEN 
target.ATTIME ELSE source.ATTIME END,
  AGGCOUNT = CASE WHEN target.TMP THEN target.AGGCOUNT ELSE target.AGGCOUNT 
+ source.AGGCOUNT END,
  TMP = FALSE
{code}

The original table is expanded with a column:

{code:sql}
  TMP   BOOLEAN   DEFAULT FALSE NOT NULL,
{code}


> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0
> Environment: Windows 10; JDK 8; Derby 10.14.2.0;
> Windows 10; JDK 11; Derby 10.15.2.0;
> Windows 10; JDK 17; Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip, bug-demo2.zip, derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.ins

[jira] [Updated] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7144:
--
Attachment: bug-demo2.zip

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0
> Environment: Windows 10; JDK 8; Derby 10.14.2.0;
> Windows 10; JDK 11; Derby 10.15.2.0;
> Windows 10; JDK 17; Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip, bug-demo2.zip, derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
> at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
> at org.apache.derby.impl.jdbc.Util.javaException(Util.java:274)
> at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLEx

[jira] [Updated] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7144:
--
Attachment: derby.log

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0
> Environment: Windows 10; JDK 8; Derby 10.14.2.0;
> Windows 10; JDK 11; Derby 10.15.2.0;
> Windows 10; JDK 17; Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip, derby.log, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
> at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
> at org.apache.derby.impl.jdbc.Util.javaException(Util.java:274)
> at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Transaction

[jira] [Updated] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7144:
--
Attachment: sysinfo.out

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0
> Environment: Windows 10; JDK 8; Derby 10.14.2.0;
> Windows 10; JDK 11; Derby 10.15.2.0;
> Windows 10; JDK 17; Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip, sysinfo.out
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
> at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
> at org.apache.derby.impl.jdbc.Util.javaException(Util.java:274)
> at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceI

[jira] [Commented] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7144:
---

{quote}
The following statement fails (most often) when the target table has a 
GENERATED BY DEFAULT AS IDENTITY primary key:
{quote}

So, it is not limited to primary keys, just GENERATED BY DEFAULT AS IDENTITY 
columns:

{code:sql}
CREATE TABLE AGGREGATEDATA (
  CATEGORY  INTEGER   NOT NULL,
  VALUE DOUBLENOT NULL,
  ATTIMETIMESTAMP NOT NULL,
  AGGDATE   DATE  NOT NULL,
  AGGCOUNT  INTEGER   NOT NULL,
  SEQ   BIGINTGENERATED BY DEFAULT AS IDENTITY NOT NULL,
 
  PRIMARY KEY (AGGDATE, CATEGORY)
)
{code}

The exception becomes:

{code:none}
org.apache.derby.shared.common.sanity.AssertFailure: ASSERT FAILED row template 
is null for column[5].
{code}

> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0
> Environment: Windows 10; JDK 8; Derby 10.14.2.0;
> Windows 10; JDK 11; Derby 10.15.2.0;
> Windows 10; JDK 17; Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 m

[jira] [Updated] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


 [ 
https://issues.apache.org/jira/browse/DERBY-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stanimir Stamenkov updated DERBY-7144:
--
Environment: 
Windows 10; JDK 8; Derby 10.14.2.0;
Windows 10; JDK 11; Derby 10.15.2.0;
Windows 10; JDK 17; Derby 10.16.1.1.

  was:
Windows 10; JDK 11; Derby 10.14.0.2.

As far as I've observed the problem persists in Derby 10.15 and 10.16.


> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0
> Environment: Windows 10; JDK 8; Derby 10.14.2.0;
> Windows 10; JDK 11; Derby 10.15.2.0;
> Windows 10; JDK 17; Derby 10.16.1.1.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
>   at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
>   at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
> Source)
>   ... 7 more
> {noformat}
> With the debug-version JARs I'm getting:
> {noformat}
> java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null 
> for column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
> at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
> at org.apache.derby.impl.jdbc.Util.seeNext

[jira] [Comment Edited] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov edited comment on DERBY-7144 at 7/30/22 12:29 PM:
-

The {{-workaround}} option of the demo uses a separate query:

{code:sql}
SELECT * FROM TABLE (FAUX_BULK_DATA()) t
{code}

For each of the returned rows it executes (batches) a single row _upsert_:

{code:sql}
MERGE INTO AGGREGATEDATA target
USING SYSIBM.SYSDUMMY1 dummy
   ON target.CATEGORY = ?
  AND target.AGGDATE = ?
 WHEN MATCHED THEN
  UPDATE SET VALUE = target.VALUE + ?,
  ATTIME = CASE WHEN ? < target.ATTIME THEN target.ATTIME ELSE ? END,
  AGGCOUNT = target.AGGCOUNT + ?
 WHEN NOT MATCHED THEN
  INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
  VALUES (?, ?, ?, ?, ?)
{code}

For each row, the source data has to be fetched and then added as parameters 
(multiple times) to a new statement to execute.  It is quite suboptimal, in my 
opinion.

It is possible the workaround works incidentally, given the original scenario 
sometimes (under specific circumstances) works, also.  That is, the workaround 
(being almost the same as the original statement) may not be affected by the 
original issue, accidentally.



was (Author: stanio):
The {{-workaround}} option of the demo uses a separate query:

{code:sql}
SELECT * FROM TABLE (FAUX_BULK_DATA()) t
{code}

For each of the returned rows it executes (batches) a single row _upsert_:

{code:sql}
MERGE INTO AGGREGATEDATA target
USING SYSIBM.SYSDUMMY1 dummy
   ON target.CATEGORY = ?
  AND target.AGGDATE = ?
 WHEN MATCHED THEN
  UPDATE SET VALUE = target.VALUE + ?,
  ATTIME = CASE WHEN ? < target.ATTIME THEN target.ATTIME ELSE ? END,
  AGGCOUNT = target.AGGCOUNT + ?
 WHEN NOT MATCHED THEN
  INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
  VALUES (?, ?, ?, ?, ?)
{code}

For each row, the source data has to be fetched and then added as parameters 
(multiple times) to a new statement to execute.  It is quite suboptimal, in my 
opinion.

It is possible the workaround works incidentally, given the original scenario 
sometimes (under specific circumstances) works, also.


> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0
> Environment: Windows 10; JDK 11; Derby 10.14.0.2.
> As far as I've observed the problem persists in Derby 10.15 and 10.16.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugD

[jira] [Commented] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)


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

Stanimir Stamenkov commented on DERBY-7144:
---

The {{-workaround}} option of the demo uses a separate query:

{code:sql}
SELECT * FROM TABLE (FAUX_BULK_DATA()) t
{code}

For each of the returned rows it executes (batches) a single row _upsert_:

{code:sql}
MERGE INTO AGGREGATEDATA target
USING SYSIBM.SYSDUMMY1 dummy
   ON target.CATEGORY = ?
  AND target.AGGDATE = ?
 WHEN MATCHED THEN
  UPDATE SET VALUE = target.VALUE + ?,
  ATTIME = CASE WHEN ? < target.ATTIME THEN target.ATTIME ELSE ? END,
  AGGCOUNT = target.AGGCOUNT + ?
 WHEN NOT MATCHED THEN
  INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
  VALUES (?, ?, ?, ?, ?)
{code}

For each row, the source data has to be fetched and then added as parameters 
(multiple times) to a new statement to execute.  It is quite suboptimal, in my 
opinion.

It is possible the workaround works incidentally, given the original scenario 
sometimes (under specific circumstances) works, also.


> MERGE INSERT failing when target has GENERATED INDENTITY column
> ---
>
> Key: DERBY-7144
> URL: https://issues.apache.org/jira/browse/DERBY-7144
> Project: Derby
>  Issue Type: Bug
>  Components: SQL
>Affects Versions: 10.14.2.0
> Environment: Windows 10; JDK 11; Derby 10.14.0.2.
> As far as I've observed the problem persists in Derby 10.15 and 10.16.
>Reporter: Stanimir Stamenkov
>Priority: Major
> Attachments: bug-demo.zip
>
>
> _TL;DR:_ The following statement fails (most often) when the target table has 
> a GENERATED BY DEFAULT AS IDENTITY primary key:
> {code:sql}
> MERGE INTO AGGREGATEDATA target
> USING TABLE (AGGREGATE_BULK_DATA()) source
>ON target.CATEGORY = source.CATEGORY
>   AND target.AGGDATE = source.AGGDATE
>  WHEN MATCHED THEN
>   UPDATE SET VALUE = target.VALUE + source.VALUE,
>   ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME 
> ELSE source.ATTIME END,
>   AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
>  WHEN NOT MATCHED THEN
>   INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
>   VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
> source.AGGCOUNT)
> {code}
> {noformat}
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>   at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>   at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown 
> Source)
>   at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
>   at net.example.derby.BugDemo.run(BugDemo.java:242)
>   at net.example.derby.BugDemo.main(BugDemo.java:212)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>   at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>   at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>   ... 15 more
> Caused by: java.lang.NullPointerException
>   at 
> org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
>  Source)
>   at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
>   at 
> org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
>  Source)
>   at 
> org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown 
> Source)
>   at 
> org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
>  Source)
>   at 
> org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
> Source)
>   at org.apache.derby.impl.sql.execute.Mer

[jira] [Created] (DERBY-7144) MERGE INSERT failing when target has GENERATED INDENTITY column

2022-07-30 Thread Stanimir Stamenkov (Jira)
Stanimir Stamenkov created DERBY-7144:
-

 Summary: MERGE INSERT failing when target has GENERATED INDENTITY 
column
 Key: DERBY-7144
 URL: https://issues.apache.org/jira/browse/DERBY-7144
 Project: Derby
  Issue Type: Bug
  Components: SQL
Affects Versions: 10.14.2.0
 Environment: Windows 10; JDK 11; Derby 10.14.0.2.

As far as I've observed the problem persists in Derby 10.15 and 10.16.
Reporter: Stanimir Stamenkov
 Attachments: bug-demo.zip

_TL;DR:_ The following statement fails (most often) when the target table has a 
GENERATED BY DEFAULT AS IDENTITY primary key:

{code:sql}
MERGE INTO AGGREGATEDATA target
USING TABLE (AGGREGATE_BULK_DATA()) source
   ON target.CATEGORY = source.CATEGORY
  AND target.AGGDATE = source.AGGDATE
 WHEN MATCHED THEN
  UPDATE SET VALUE = target.VALUE + source.VALUE,
  ATTIME = CASE WHEN source.ATTIME < target.ATTIME THEN target.ATTIME ELSE 
source.ATTIME END,
  AGGCOUNT = target.AGGCOUNT + source.AGGCOUNT
 WHEN NOT MATCHED THEN
  INSERT (CATEGORY, VALUE, ATTIME, AGGDATE, AGGCOUNT)
  VALUES (source.CATEGORY, source.VALUE, source.ATTIME, source.AGGDATE, 
source.AGGCOUNT)
{code}

{noformat}
java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
Source)
at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown 
Source)
at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown 
Source)
at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(Unknown 
Source)
at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown Source)
at net.example.derby.BugDemo.mergeData(BugDemo.java:124)
at net.example.derby.BugDemo.run(BugDemo.java:242)
at net.example.derby.BugDemo.main(BugDemo.java:212)
Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
at org.apache.derby.iapi.error.StandardException.newException(Unknown 
Source)
at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
 Source)
... 15 more
Caused by: java.lang.NullPointerException
at 
org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil.createFormatIds(Unknown
 Source)
at org.apache.derby.impl.store.access.heap.Heap.create(Unknown Source)
at 
org.apache.derby.impl.store.access.heap.HeapConglomerateFactory.createConglomerate(Unknown
 Source)
at 
org.apache.derby.impl.store.access.RAMTransaction.createConglomerate(Unknown 
Source)
at 
org.apache.derby.impl.sql.execute.TemporaryRowHolderImpl.insert(Unknown Source)
at 
org.apache.derby.impl.sql.execute.MatchingClauseConstantAction.bufferThenRow(Unknown
 Source)
at 
org.apache.derby.impl.sql.execute.MergeResultSet.collectAffectedRows(Unknown 
Source)
at org.apache.derby.impl.sql.execute.MergeResultSet.open(Unknown Source)
at 
org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
Source)
... 7 more
{noformat}

With the debug-version JARs I'm getting:

{noformat}
java.sql.SQLException: Java exception: 'ASSERT FAILED row template is null for 
column[0].: org.apache.derby.shared.common.sanity.AssertFailure'.
at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:252)
at org.apache.derby.impl.jdbc.Util.javaException(Util.java:274)
at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:437)
at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
at 
org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2405)
at 
org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:88)
at 
org.apache.derby.impl.jdbc.EmbedStatement.executeStatemen