Skip to content

Commit 1f033cd

Browse files
Move the FileSystem variable as class member
1 parent 6958312 commit 1f033cd

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.apache.spark.sql.hive
1919

2020
import org.apache.hadoop.conf.Configuration
21-
import org.apache.hadoop.fs.{Path, PathFilter}
21+
import org.apache.hadoop.fs.{FileSystem, Path, PathFilter}
2222
import org.apache.hadoop.hive.conf.HiveConf
2323
import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants._
2424
import org.apache.hadoop.hive.ql.exec.Utilities
@@ -68,6 +68,8 @@ class HadoopTableReader(
6868
math.max(sc.hiveconf.getInt("mapred.map.tasks", 1), sc.sparkContext.defaultMinPartitions)
6969
}
7070

71+
@transient private lazy val fs = FileSystem.get(sc.hiveconf)
72+
7173
// TODO: set aws s3 credentials.
7274

7375
private val _broadcastedHiveConf =
@@ -218,11 +220,10 @@ class HadoopTableReader(
218220
* returned in a single, comma-separated string.
219221
*/
220222
private def applyFilterIfNeeded(path: Path, filterOpt: Option[PathFilter]): Option[String] = {
221-
if (path.getFileSystem(sc.hiveconf).exists(path)) {
223+
if (fs.exists(path)) {
222224
// if the file exists
223225
filterOpt match {
224226
case Some(filter) =>
225-
val fs = path.getFileSystem(sc.hiveconf)
226227
val filteredFiles = fs.listStatus(path, filter).map(_.getPath.toString)
227228
if (filteredFiles.length > 0) {
228229
Some(filteredFiles.mkString(","))

0 commit comments

Comments
 (0)