You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by we...@apache.org on 2025/11/25 13:07:10 UTC

(spark) branch master updated: [SPARK-54130][SQL][FOLLOWUP] Refactor tests to use withEmptyCatalog for consistency

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

wenchen 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 211dd995b221 [SPARK-54130][SQL][FOLLOWUP] Refactor tests to use withEmptyCatalog for consistency
211dd995b221 is described below

commit 211dd995b221f135340375159672dcb77ef90ef4
Author: Ganesha S <ga...@databricks.com>
AuthorDate: Tue Nov 25 21:06:55 2025 +0800

    [SPARK-54130][SQL][FOLLOWUP] Refactor tests to use withEmptyCatalog for consistency
    
    ### What changes were proposed in this pull request?
    
    This PR refactors two tests in `SessionCatalogSuite.scala` to use the `withEmptyCatalog` helper method instead of manually creating a `SessionCatalog` instance with `newEmptyCatalog()`:
    - "UnresolvedCatalogRelation requires database in identifier"
    - "HiveTableRelation requires database in identifier"
    
    ### Why are the changes needed?
    
    **Consistency**: All other tests in `SessionCatalogSuite` use the `withEmptyCatalog` or `withBasicCatalog` helper pattern. These two tests, added in SPARK-54130, were using manual catalog initialization, which is inconsistent with the rest of the test suite.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No. This is a test-only refactoring with no functional changes.
    
    ### How was this patch tested?
    
    - Verified no linter errors in the modified file
    - The test logic remains identical, only the catalog initialization pattern changed
    - Both tests validate the same assertion error messages as before
    - The `withEmptyCatalog` helper handles catalog creation and cleanup automatically
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Sonnet 4.5
    
    Closes #53208 from ganeshashree/SPARK-54130-2.
    
    Authored-by: Ganesha S <ga...@databricks.com>
    Signed-off-by: Wenchen Fan <we...@databricks.com>
---
 .../sql/catalyst/catalog/SessionCatalogSuite.scala | 102 ++++++++++-----------
 1 file changed, 51 insertions(+), 51 deletions(-)

diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala
index a1b7113d7947..7a0a37f38099 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala
@@ -2095,68 +2095,68 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually {
   }
 
   test("UnresolvedCatalogRelation requires database in identifier") {
-    val catalog = new SessionCatalog(newEmptyCatalog())
-    catalog.createDatabase(newDb("default"), ignoreIfExists = true)
-    val db = "test_db"
-    catalog.createDatabase(newDb(db), ignoreIfExists = true)
+    withEmptyCatalog { catalog =>
+      val db = "test_db"
+      catalog.createDatabase(newDb(db), ignoreIfExists = true)
+
+      // Create a table with database
+      val validTable = CatalogTable(
+        identifier = TableIdentifier("test_table", Some(db)),
+        tableType = CatalogTableType.MANAGED,
+        storage = CatalogStorageFormat.empty,
+        schema = new StructType().add("id", IntegerType)
+      )
+      catalog.createTable(validTable, ignoreIfExists = false)
 
-    // Create a table with database
-    val validTable = CatalogTable(
-      identifier = TableIdentifier("test_table", Some(db)),
-      tableType = CatalogTableType.MANAGED,
-      storage = CatalogStorageFormat.empty,
-      schema = new StructType().add("id", IntegerType)
-    )
-    catalog.createTable(validTable, ignoreIfExists = false)
+      // Try to create UnresolvedCatalogRelation without database - should fail
+      val tableMetaWithoutDb = validTable.copy(
+        identifier = TableIdentifier("test_table", None)
+      )
 
-    // Try to create UnresolvedCatalogRelation without database - should fail
-    val tableMetaWithoutDb = validTable.copy(
-      identifier = TableIdentifier("test_table", None)
-    )
+      val exception = intercept[AssertionError] {
+        UnresolvedCatalogRelation(tableMetaWithoutDb)
+      }
 
-    val exception = intercept[AssertionError] {
-      UnresolvedCatalogRelation(tableMetaWithoutDb)
+      val expectedMessage =
+        "assertion failed: Table identifier `test_table` is missing database name. " +
+        "UnresolvedCatalogRelation requires a fully qualified table identifier with database."
+      assert(exception.getMessage === expectedMessage)
     }
-
-    val expectedMessage =
-      "assertion failed: Table identifier `test_table` is missing database name. " +
-      "UnresolvedCatalogRelation requires a fully qualified table identifier with database."
-    assert(exception.getMessage === expectedMessage)
   }
 
   test("HiveTableRelation requires database in identifier") {
-    val catalog = new SessionCatalog(newEmptyCatalog())
-    catalog.createDatabase(newDb("default"), ignoreIfExists = true)
-    val db = "test_db"
-    catalog.createDatabase(newDb(db), ignoreIfExists = true)
+    withEmptyCatalog { catalog =>
+      val db = "test_db"
+      catalog.createDatabase(newDb(db), ignoreIfExists = true)
+
+      // Create a table with database
+      val validTable = CatalogTable(
+        identifier = TableIdentifier("test_table", Some(db)),
+        tableType = CatalogTableType.MANAGED,
+        storage = CatalogStorageFormat.empty,
+        schema = new StructType()
+          .add("id", IntegerType)
+          .add("name", StringType)
+      )
 
-    // Create a table with database
-    val validTable = CatalogTable(
-      identifier = TableIdentifier("test_table", Some(db)),
-      tableType = CatalogTableType.MANAGED,
-      storage = CatalogStorageFormat.empty,
-      schema = new StructType()
-        .add("id", IntegerType)
-        .add("name", StringType)
-    )
+      // Try to create HiveTableRelation without database - should fail
+      val tableMetaWithoutDb = validTable.copy(
+        identifier = TableIdentifier("test_table", None)
+      )
 
-    // Try to create HiveTableRelation without database - should fail
-    val tableMetaWithoutDb = validTable.copy(
-      identifier = TableIdentifier("test_table", None)
-    )
+      val exception = intercept[AssertionError] {
+        HiveTableRelation(
+          tableMetaWithoutDb,
+          Seq(AttributeReference("id", IntegerType)()),
+          Seq.empty
+        )
+      }
 
-    val exception = intercept[AssertionError] {
-      HiveTableRelation(
-        tableMetaWithoutDb,
-        Seq(AttributeReference("id", IntegerType)()),
-        Seq.empty
-      )
+      val expectedMessage =
+        "assertion failed: Table identifier `test_table` is missing database name. " +
+        "HiveTableRelation requires a fully qualified table identifier with database."
+      assert(exception.getMessage === expectedMessage)
     }
-
-    val expectedMessage =
-      "assertion failed: Table identifier `test_table` is missing database name. " +
-      "HiveTableRelation requires a fully qualified table identifier with database."
-    assert(exception.getMessage === expectedMessage)
   }
 
   test("SQLFunction requires either exprText or queryText") {


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