Skip to content

Commit 211dd99

Browse files
ganeshas-dbcloud-fan
authored andcommitted
[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 <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
1 parent 7191a14 commit 211dd99

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalogSuite.scala

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,68 +2095,68 @@ abstract class SessionCatalogSuite extends AnalysisTest with Eventually {
20952095
}
20962096

20972097
test("UnresolvedCatalogRelation requires database in identifier") {
2098-
val catalog = new SessionCatalog(newEmptyCatalog())
2099-
catalog.createDatabase(newDb("default"), ignoreIfExists = true)
2100-
val db = "test_db"
2101-
catalog.createDatabase(newDb(db), ignoreIfExists = true)
2098+
withEmptyCatalog { catalog =>
2099+
val db = "test_db"
2100+
catalog.createDatabase(newDb(db), ignoreIfExists = true)
2101+
2102+
// Create a table with database
2103+
val validTable = CatalogTable(
2104+
identifier = TableIdentifier("test_table", Some(db)),
2105+
tableType = CatalogTableType.MANAGED,
2106+
storage = CatalogStorageFormat.empty,
2107+
schema = new StructType().add("id", IntegerType)
2108+
)
2109+
catalog.createTable(validTable, ignoreIfExists = false)
21022110

2103-
// Create a table with database
2104-
val validTable = CatalogTable(
2105-
identifier = TableIdentifier("test_table", Some(db)),
2106-
tableType = CatalogTableType.MANAGED,
2107-
storage = CatalogStorageFormat.empty,
2108-
schema = new StructType().add("id", IntegerType)
2109-
)
2110-
catalog.createTable(validTable, ignoreIfExists = false)
2111+
// Try to create UnresolvedCatalogRelation without database - should fail
2112+
val tableMetaWithoutDb = validTable.copy(
2113+
identifier = TableIdentifier("test_table", None)
2114+
)
21112115

2112-
// Try to create UnresolvedCatalogRelation without database - should fail
2113-
val tableMetaWithoutDb = validTable.copy(
2114-
identifier = TableIdentifier("test_table", None)
2115-
)
2116+
val exception = intercept[AssertionError] {
2117+
UnresolvedCatalogRelation(tableMetaWithoutDb)
2118+
}
21162119

2117-
val exception = intercept[AssertionError] {
2118-
UnresolvedCatalogRelation(tableMetaWithoutDb)
2120+
val expectedMessage =
2121+
"assertion failed: Table identifier `test_table` is missing database name. " +
2122+
"UnresolvedCatalogRelation requires a fully qualified table identifier with database."
2123+
assert(exception.getMessage === expectedMessage)
21192124
}
2120-
2121-
val expectedMessage =
2122-
"assertion failed: Table identifier `test_table` is missing database name. " +
2123-
"UnresolvedCatalogRelation requires a fully qualified table identifier with database."
2124-
assert(exception.getMessage === expectedMessage)
21252125
}
21262126

21272127
test("HiveTableRelation requires database in identifier") {
2128-
val catalog = new SessionCatalog(newEmptyCatalog())
2129-
catalog.createDatabase(newDb("default"), ignoreIfExists = true)
2130-
val db = "test_db"
2131-
catalog.createDatabase(newDb(db), ignoreIfExists = true)
2128+
withEmptyCatalog { catalog =>
2129+
val db = "test_db"
2130+
catalog.createDatabase(newDb(db), ignoreIfExists = true)
2131+
2132+
// Create a table with database
2133+
val validTable = CatalogTable(
2134+
identifier = TableIdentifier("test_table", Some(db)),
2135+
tableType = CatalogTableType.MANAGED,
2136+
storage = CatalogStorageFormat.empty,
2137+
schema = new StructType()
2138+
.add("id", IntegerType)
2139+
.add("name", StringType)
2140+
)
21322141

2133-
// Create a table with database
2134-
val validTable = CatalogTable(
2135-
identifier = TableIdentifier("test_table", Some(db)),
2136-
tableType = CatalogTableType.MANAGED,
2137-
storage = CatalogStorageFormat.empty,
2138-
schema = new StructType()
2139-
.add("id", IntegerType)
2140-
.add("name", StringType)
2141-
)
2142+
// Try to create HiveTableRelation without database - should fail
2143+
val tableMetaWithoutDb = validTable.copy(
2144+
identifier = TableIdentifier("test_table", None)
2145+
)
21422146

2143-
// Try to create HiveTableRelation without database - should fail
2144-
val tableMetaWithoutDb = validTable.copy(
2145-
identifier = TableIdentifier("test_table", None)
2146-
)
2147+
val exception = intercept[AssertionError] {
2148+
HiveTableRelation(
2149+
tableMetaWithoutDb,
2150+
Seq(AttributeReference("id", IntegerType)()),
2151+
Seq.empty
2152+
)
2153+
}
21472154

2148-
val exception = intercept[AssertionError] {
2149-
HiveTableRelation(
2150-
tableMetaWithoutDb,
2151-
Seq(AttributeReference("id", IntegerType)()),
2152-
Seq.empty
2153-
)
2155+
val expectedMessage =
2156+
"assertion failed: Table identifier `test_table` is missing database name. " +
2157+
"HiveTableRelation requires a fully qualified table identifier with database."
2158+
assert(exception.getMessage === expectedMessage)
21542159
}
2155-
2156-
val expectedMessage =
2157-
"assertion failed: Table identifier `test_table` is missing database name. " +
2158-
"HiveTableRelation requires a fully qualified table identifier with database."
2159-
assert(exception.getMessage === expectedMessage)
21602160
}
21612161

21622162
test("SQLFunction requires either exprText or queryText") {

0 commit comments

Comments
 (0)