Skip to content

Commit 1d95dea

Browse files
wangyumgatorsmile
authored andcommitted
[SPARK-27349][SQL] Dealing with TimeVars removed in Hive 2.x
## What changes were proposed in this pull request? `hive.stats.jdbc.timeout` and `hive.stats.retries.wait` were removed by [HIVE-12164](https://issues.apache.org/jira/browse/HIVE-12164). This pr to deal with this change. ## How was this patch tested? unit tests Closes apache#24277 from wangyum/SPARK-27349. Authored-by: Yuming Wang <[email protected]> Signed-off-by: gatorsmile <[email protected]>
1 parent b56e433 commit 1d95dea

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveUtils.scala

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private[spark] object HiveUtils extends Logging {
194194
//
195195
// Here we enumerate all time `ConfVar`s and convert their values to numeric strings according
196196
// to their output time units.
197-
Seq(
197+
val commonTimeVars = Seq(
198198
ConfVars.METASTORE_CLIENT_CONNECT_RETRY_DELAY -> TimeUnit.SECONDS,
199199
ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT -> TimeUnit.SECONDS,
200200
ConfVars.METASTORE_CLIENT_SOCKET_LIFETIME -> TimeUnit.SECONDS,
@@ -207,8 +207,6 @@ private[spark] object HiveUtils extends Logging {
207207
ConfVars.METASTORE_AGGREGATE_STATS_CACHE_MAX_READER_WAIT -> TimeUnit.MILLISECONDS,
208208
ConfVars.HIVES_AUTO_PROGRESS_TIMEOUT -> TimeUnit.SECONDS,
209209
ConfVars.HIVE_LOG_INCREMENTAL_PLAN_PROGRESS_INTERVAL -> TimeUnit.MILLISECONDS,
210-
ConfVars.HIVE_STATS_JDBC_TIMEOUT -> TimeUnit.SECONDS,
211-
ConfVars.HIVE_STATS_RETRIES_WAIT -> TimeUnit.MILLISECONDS,
212210
ConfVars.HIVE_LOCK_SLEEP_BETWEEN_RETRIES -> TimeUnit.SECONDS,
213211
ConfVars.HIVE_ZOOKEEPER_SESSION_TIMEOUT -> TimeUnit.MILLISECONDS,
214212
ConfVars.HIVE_ZOOKEEPER_CONNECTION_BASESLEEPTIME -> TimeUnit.MILLISECONDS,
@@ -236,7 +234,18 @@ private[spark] object HiveUtils extends Logging {
236234
ConfVars.SPARK_RPC_CLIENT_HANDSHAKE_TIMEOUT -> TimeUnit.MILLISECONDS
237235
).map { case (confVar, unit) =>
238236
confVar.varname -> HiveConf.getTimeVar(hadoopConf, confVar, unit).toString
239-
}.toMap
237+
}
238+
239+
// The following configurations were removed by HIVE-12164(Hive 2.0)
240+
val hardcodingTimeVars = Seq(
241+
("hive.stats.jdbc.timeout", "30s") -> TimeUnit.SECONDS,
242+
("hive.stats.retries.wait", "3000ms") -> TimeUnit.MILLISECONDS
243+
).map { case ((key, defaultValue), unit) =>
244+
val value = hadoopConf.get(key, defaultValue)
245+
key -> HiveConf.toTime(value, unit, unit).toString
246+
}
247+
248+
(commonTimeVars ++ hardcodingTimeVars).toMap
240249
}
241250

242251
/**

sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveUtilsSuite.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

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

20+
import org.apache.hadoop.conf.Configuration
2021
import org.apache.hadoop.hive.conf.HiveConf.ConfVars
2122

2223
import org.apache.spark.SparkConf
@@ -29,6 +30,12 @@ import org.apache.spark.util.ChildFirstURLClassLoader
2930

3031
class HiveUtilsSuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
3132

33+
private def testFormatTimeVarsForHiveClient(key: String, value: String, expected: Long): Unit = {
34+
val conf = new Configuration
35+
conf.set(key, value)
36+
assert(HiveUtils.formatTimeVarsForHiveClient(conf)(key) === expected.toString)
37+
}
38+
3239
test("newTemporaryConfiguration overwrites listener configurations") {
3340
Seq(true, false).foreach { useInMemoryDerby =>
3441
val conf = HiveUtils.newTemporaryConfiguration(useInMemoryDerby)
@@ -61,4 +68,17 @@ class HiveUtilsSuite extends QueryTest with SQLTestUtils with TestHiveSingleton
6168
Thread.currentThread().setContextClassLoader(contextClassLoader)
6269
}
6370
}
71+
72+
test("SPARK-27349: Dealing with TimeVars removed in Hive 2.x") {
73+
// Test default value
74+
val defaultConf = new Configuration
75+
assert(HiveUtils.formatTimeVarsForHiveClient(defaultConf)("hive.stats.jdbc.timeout") === "30")
76+
assert(HiveUtils.formatTimeVarsForHiveClient(defaultConf)("hive.stats.retries.wait") === "3000")
77+
78+
testFormatTimeVarsForHiveClient("hive.stats.jdbc.timeout", "40s", 40)
79+
testFormatTimeVarsForHiveClient("hive.stats.jdbc.timeout", "1d", 1 * 24 * 60 * 60)
80+
81+
testFormatTimeVarsForHiveClient("hive.stats.retries.wait", "4000ms", 4000)
82+
testFormatTimeVarsForHiveClient("hive.stats.retries.wait", "1d", 1 * 24 * 60 * 60 * 1000)
83+
}
6484
}

0 commit comments

Comments
 (0)