-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-25062][SQL] Clean up BlockLocations in InMemoryFileIndex #22603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ import java.net.URI | |
| import scala.collection.mutable | ||
| import scala.language.reflectiveCalls | ||
|
|
||
| import org.apache.hadoop.fs.{FileStatus, Path, RawLocalFileSystem} | ||
| import org.apache.hadoop.fs.{BlockLocation, FileStatus, LocatedFileStatus, Path, RawLocalFileSystem} | ||
|
|
||
| import org.apache.spark.metrics.source.HiveCatalogMetrics | ||
| import org.apache.spark.sql.catalyst.util._ | ||
|
|
@@ -248,6 +248,25 @@ class FileIndexSuite extends SharedSQLContext { | |
| assert(spark.read.parquet(path.getAbsolutePath).schema.exists(_.name == colToUnescape)) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-25062 - InMemoryCache stores only simple BlockLocations") { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| withSQLConf("fs.file.impl" -> classOf[SpecialBlockLocationFileSystem].getName) { | ||
| withTempDir { dir => | ||
| val file = new File(dir, "text.txt") | ||
| stringToFile(file, "text") | ||
|
|
||
| val inMemoryFileIndex = new InMemoryFileIndex( | ||
| spark, Seq(new Path(file.getCanonicalPath)), Map.empty, None) { | ||
| def leafFileStatuses = leafFiles.map(_._2) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, |
||
| } | ||
| val blockLocations = inMemoryFileIndex.leafFileStatuses.flatMap( | ||
| _.asInstanceOf[LocatedFileStatus].getBlockLocations) | ||
|
|
||
| assert(blockLocations.forall(_.getClass == classOf[BlockLocation])) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| class FakeParentPathFileSystem extends RawLocalFileSystem { | ||
|
|
@@ -257,3 +276,19 @@ class FakeParentPathFileSystem extends RawLocalFileSystem { | |
| URI.create("mockFs://some-bucket") | ||
| } | ||
| } | ||
|
|
||
| class SpecialBlockLocationFileSystem extends RawLocalFileSystem { | ||
|
|
||
| class SpecialBlockLocation( | ||
| names: Array[String], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4 spaces indentation |
||
| hosts: Array[String], | ||
| offset: Long, | ||
| length: Long) extends BlockLocation(names, hosts, offset, length) | ||
|
|
||
| override def getFileBlockLocations( | ||
| file: FileStatus, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| start: Long, | ||
| len: Long): Array[BlockLocation] = { | ||
| Array(new SpecialBlockLocation(Array("dummy"), Array("dummy"), 0L, file.getLen)) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @peter-toth .
Could you add one line comment to explain this conversion?