You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by gu...@apache.org on 2026/09/28 07:14:57 UTC

(spark) branch master updated: [SPARK-59785][CONNECT][TEST] Fix SparkConnectResultSetSuite failure when ANSI mode is off

This is an automated email from the ASF dual-hosted git repository.

HyukjinKwon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new cb9463e77b23 [SPARK-59785][CONNECT][TEST] Fix SparkConnectResultSetSuite failure when ANSI mode is off
cb9463e77b23 is described below

commit cb9463e77b236ad86478b98c0f4e61be642c9bdf
Author: Sepuri Sai Krishna <sa...@gmail.com>
AuthorDate: Mon Sep 28 16:14:39 2026 +0900

    [SPARK-59785][CONNECT][TEST] Fix SparkConnectResultSetSuite failure when ANSI mode is off
    
    ### What changes were proposed in this pull request?
    
    This PR makes the test `next throws SQLException when the query fails during result streaming` in `SparkConnectResultSetSuite` enable `spark.sql.ansi.enabled` explicitly for its JDBC session before running the query, instead of relying on the default ANSI setting.
    
    This follows the existing pattern in `SparkConnectJdbcDataTypeSuite`, which enables session configs with `statement.execute("SET ...")`.
    
    ### Why are the changes needed?
    
    The test was added in SPARK-57933. It runs `SELECT 10 / (5 - id) FROM range(10)` and expects a `DIVIDE_BY_ZERO` error (SQLSTATE 22012), which is only raised under ANSI mode. The Non-ANSI scheduled builds (master, branch-4.x and branch-4.3) set `SPARK_ANSI_SQL_MODE=false`, so the division returns NULL and the test fails every time:
    
    ```
    - next throws SQLException when the query fails during result streaming *** FAILED ***
      Expected exception java.sql.SQLException to be thrown, but no exception was thrown (SparkConnectResultSetSuite.scala:195)
    ```
    
    Each JDBC connection creates its own Spark Connect session (`SparkConnectConnection`), and `withStatement` opens a new connection, so the setting does not leak to other tests.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No. Test-only change.
    
    ### How was this patch tested?
    
    - Before the fix, `SPARK_ANSI_SQL_MODE=false build/sbt 'connect-client-jdbc/testOnly *SparkConnectResultSetSuite'` fails with the same error as CI.
    - After the fix, the suite passes with both `SPARK_ANSI_SQL_MODE=false` and `SPARK_ANSI_SQL_MODE=true` (6 tests each).
    - `build/sbt 'connect-client-jdbc/test'` with both `SPARK_ANSI_SQL_MODE=false` and `SPARK_ANSI_SQL_MODE=true`: all 65 tests passed each time.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (Claude Opus 5.5)
    
    Closes #59046 from SEPURI-SAI-KRISHNA/jdbc-resultset-non-ansi.
    
    Authored-by: Sepuri Sai Krishna <sa...@gmail.com>
    Signed-off-by: Hyukjin Kwon <hy...@databricks.com>
---
 .../spark/sql/connect/client/jdbc/SparkConnectResultSetSuite.scala   | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sql/connect/client/jdbc/src/test/scala/org/apache/spark/sql/connect/client/jdbc/SparkConnectResultSetSuite.scala b/sql/connect/client/jdbc/src/test/scala/org/apache/spark/sql/connect/client/jdbc/SparkConnectResultSetSuite.scala
index 8470a9151533..3e0b26247ad7 100644
--- a/sql/connect/client/jdbc/src/test/scala/org/apache/spark/sql/connect/client/jdbc/SparkConnectResultSetSuite.scala
+++ b/sql/connect/client/jdbc/src/test/scala/org/apache/spark/sql/connect/client/jdbc/SparkConnectResultSetSuite.scala
@@ -191,11 +191,14 @@ class SparkConnectResultSetSuite extends ConnectFunSuite with RemoteSparkSession
     // The server sends the schema response before any arrow batch, so executeQuery
     // returns successfully and the runtime error surfaces while iterating rows.
     withStatement { stmt =>
+      // Division by zero only fails under ANSI mode, so enable it explicitly for this session
+      // instead of relying on the default, which is off when SPARK_ANSI_SQL_MODE=false.
+      stmt.execute("SET spark.sql.ansi.enabled=true")
       val rs = stmt.executeQuery("SELECT 10 / (5 - id) FROM range(10)")
       val e = intercept[SQLException] {
         while (rs.next()) {}
       }
-      // DIVIDE_BY_ZERO under ANSI mode
+      // DIVIDE_BY_ZERO
       assert(e.getSQLState === "22012")
       assert(e.getCause != null)
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org