nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: GoogleCloudPlatform/pgadapter
Pull request #1877 (2024-05-27 13:11:37)

chore: discard all should reset all session state


Patch:
diff --git a/src/main/java/com/google/cloud/spanner/pgadapter/statements/DiscardStatement.java b/src/main/java/com/google/cloud/spanner/pgadapter/statements/DiscardStatement.java
index 09b1d9ab..3a95dddc 100644
--- a/src/main/java/com/google/cloud/spanner/pgadapter/statements/DiscardStatement.java
+++ b/src/main/java/com/google/cloud/spanner/pgadapter/statements/DiscardStatement.java
@@ -94,6 +94,7 @@ public class DiscardStatement extends IntermediatePortalStatement {
                         SQLState.ActiveSqlTransaction)));
             return;
           }
+          backendConnection.getSessionState().resetAll();
           connectionHandler.closeAllStatements();
           break;
         case PLANS:


Test patch:
diff --git a/src/test/java/com/google/cloud/spanner/pgadapter/JdbcSimpleModeMockServerTest.java b/src/test/java/com/google/cloud/spanner/pgadapter/JdbcSimpleModeMockServerTest.java
index f1620f7e..aa8401dd 100644
--- a/src/test/java/com/google/cloud/spanner/pgadapter/JdbcSimpleModeMockServerTest.java
+++ b/src/test/java/com/google/cloud/spanner/pgadapter/JdbcSimpleModeMockServerTest.java
@@ -597,6 +597,22 @@ public class JdbcSimpleModeMockServerTest extends AbstractMockServerTest {
           SQLState.InvalidSqlStatementName.toString(),
           exception.getServerErrorMessage().getSQLState());
 
+      // Verify that DISCARD ALL resets all session state.
+      connection.createStatement().execute("set spanner.copy_upsert=true");
+      try (ResultSet resultSet =
+          connection.createStatement().executeQuery("show spanner.copy_upsert")) {
+        assertTrue(resultSet.next());
+        assertTrue(resultSet.getBoolean(1));
+        assertFalse(resultSet.next());
+      }
+      connection.createStatement().execute("discard all");
+      try (ResultSet resultSet =
+          connection.createStatement().executeQuery("show spanner.copy_upsert")) {
+        assertTrue(resultSet.next());
+        assertFalse(resultSet.getBoolean(1));
+        assertFalse(resultSet.next());
+      }
+
       // Verify that 'discard all' is not accepted in a transaction block.
       connection.setAutoCommit(false);
       exception =