Skip to content

Commit 936d481

Browse files
pan3793dongjoon-hyun
authored andcommitted
[SPARK-52567][SQL][HIVE][TEST] Refactor Hive_2_1_DDLSuite
### What changes were proposed in this pull request? Hive_2_1_DDLSuite was added in SPARK-21617 (2.3.0), in those days, the built-in Hive version was 1.2.1. > A separate set of DDL tests that uses Hive 2.1 libraries, which behave a little differently from the built-in ones. After a closer look, the real difference is, Hive enables `hive.metastore.disallow.incompatible.col.type.changes` since HIVE-12320 (2.0.0) Now we upgraded the built-in Hive to 2.3.10, the comments become misleading and we can simply use the global `TestHiveSingleton` with overriding `hive.metastore.disallow.incompatible.col.type.changes` to achieve the same test purpose. ### Why are the changes needed? Simplify and speed up the test, and update the outdated comments for clarity. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? ``` sbt:spark-hive> testOnly *HiveIncompatibleColTypeChangeSuite ... [info] Run completed in 11 seconds, 429 milliseconds. [info] Total number of tests run: 4 [info] Suites: completed 1, aborted 0 [info] Tests: succeeded 4, failed 0, canceled 0, ignored 0, pending 0 [info] All tests passed. [success] Total time: 18 s, completed Jun 24, 2025, 11:26:07 PM ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes #51271 from pan3793/SPARK-52567. Authored-by: Cheng Pan <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 36a08bd commit 936d481

File tree

1 file changed

+12
-37
lines changed

1 file changed

+12
-37
lines changed

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/Hive_2_1_DDLSuite.scala renamed to sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveIncompatibleColTypeChangeSuite.scala

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,23 @@
1717

1818
package org.apache.spark.sql.hive.execution
1919

20-
import org.apache.hadoop.conf.Configuration
21-
22-
import org.apache.spark.{SparkConf, SparkFunSuite}
23-
import org.apache.spark.launcher.SparkLauncher
20+
import org.apache.spark.SparkFunSuite
2421
import org.apache.spark.sql.AnalysisException
25-
import org.apache.spark.sql.hive.{HiveExternalCatalog, HiveUtils}
2622
import org.apache.spark.sql.hive.test.TestHiveSingleton
27-
import org.apache.spark.sql.internal.StaticSQLConf._
2823
import org.apache.spark.sql.types._
29-
import org.apache.spark.tags.{ExtendedHiveTest, SlowHiveTest}
30-
import org.apache.spark.util.Utils
3124

3225
/**
33-
* A separate set of DDL tests that uses Hive 2.1 libraries, which behave a little differently
34-
* from the built-in ones.
26+
* A separate set of Hive DDL tests when setting
27+
* `hive.metastore.disallow.incompatible.col.type.changes=true`
3528
*/
36-
@SlowHiveTest
37-
@ExtendedHiveTest
38-
class Hive_2_1_DDLSuite extends SparkFunSuite with TestHiveSingleton {
39-
40-
// Create a custom HiveExternalCatalog instance with the desired configuration. We cannot
41-
// use SparkSession here since there's already an active on managed by the TestHive object.
42-
private var catalog = {
43-
val warehouse = Utils.createTempDir()
44-
val metastore = Utils.createTempDir()
45-
metastore.delete()
46-
val sparkConf = new SparkConf()
47-
.set(SparkLauncher.SPARK_MASTER, "local")
48-
.set(WAREHOUSE_PATH.key, warehouse.toURI().toString())
49-
.set(CATALOG_IMPLEMENTATION.key, "hive")
50-
.set(HiveUtils.HIVE_METASTORE_VERSION.key, "2.1")
51-
.set(HiveUtils.HIVE_METASTORE_JARS.key, "maven")
29+
class HiveIncompatibleColTypeChangeSuite extends SparkFunSuite with TestHiveSingleton {
5230

53-
val hadoopConf = new Configuration()
54-
hadoopConf.set("hive.metastore.warehouse.dir", warehouse.toURI().toString())
55-
hadoopConf.set("javax.jdo.option.ConnectionURL",
56-
s"jdbc:derby:;databaseName=${metastore.getAbsolutePath()};create=true")
57-
// These options are needed since the defaults in Hive 2.1 cause exceptions with an
58-
// empty metastore db.
59-
hadoopConf.set("datanucleus.schema.autoCreateAll", "true")
60-
hadoopConf.set("hive.metastore.schema.verification", "false")
31+
private val catalog = spark.sessionState.catalog.externalCatalog
6132

62-
new HiveExternalCatalog(sparkConf, hadoopConf)
33+
override def beforeAll(): Unit = {
34+
super.beforeAll()
35+
hiveClient.runSqlHive(
36+
"SET hive.metastore.disallow.incompatible.col.type.changes=true")
6337
}
6438

6539
override def afterEach(): Unit = {
@@ -71,7 +45,8 @@ class Hive_2_1_DDLSuite extends SparkFunSuite with TestHiveSingleton {
7145

7246
override def afterAll(): Unit = {
7347
try {
74-
catalog = null
48+
hiveClient.runSqlHive(
49+
"SET hive.metastore.disallow.incompatible.col.type.changes=false")
7550
} finally {
7651
super.afterAll()
7752
}
@@ -122,7 +97,7 @@ class Hive_2_1_DDLSuite extends SparkFunSuite with TestHiveSingleton {
12297
updatedSchema: StructType,
12398
hiveCompatible: Boolean = true): Unit = {
12499
spark.sql(createTableStmt)
125-
val oldTable = spark.sessionState.catalog.externalCatalog.getTable("default", tableName)
100+
val oldTable = catalog.getTable("default", tableName)
126101
catalog.createTable(oldTable, true)
127102
catalog.alterTableDataSchema("default", tableName, updatedSchema)
128103

0 commit comments

Comments
 (0)