-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-36682][CORE][TEST] Add Hadoop sequence file test for different Hadoop codecs #33924
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 |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ import com.google.common.io.Files | |
| import org.apache.hadoop.conf.Configuration | ||
| import org.apache.hadoop.fs.Path | ||
| import org.apache.hadoop.io._ | ||
| import org.apache.hadoop.io.compress.DefaultCodec | ||
| import org.apache.hadoop.io.compress.{BZip2Codec, CompressionCodec, DefaultCodec} | ||
| import org.apache.hadoop.mapred.{FileAlreadyExistsException, FileSplit, JobConf, TextInputFormat, TextOutputFormat} | ||
| import org.apache.hadoop.mapreduce.Job | ||
| import org.apache.hadoop.mapreduce.lib.input.{FileSplit => NewFileSplit, TextInputFormat => NewTextInputFormat} | ||
|
|
@@ -113,25 +113,34 @@ class FileSuite extends SparkFunSuite with LocalSparkContext { | |
| assert(output.map(_.toString).collect().toList === List("(1,a)", "(2,aa)", "(3,aaa)")) | ||
| } | ||
|
|
||
| test("SequenceFile (compressed)") { | ||
| sc = new SparkContext("local", "test") | ||
| val normalDir = new File(tempDir, "output_normal").getAbsolutePath | ||
| val compressedOutputDir = new File(tempDir, "output_compressed").getAbsolutePath | ||
| val codec = new DefaultCodec() | ||
| def runSequenceFileCodecTest(codec: CompressionCodec, codecName: String): Unit = { | ||
| test(s"SequenceFile (compressed) - $codecName") { | ||
| sc = new SparkContext("local", "test") | ||
| val normalDir = new File(tempDir, "output_normal").getAbsolutePath | ||
| val compressedOutputDir = new File(tempDir, "output_compressed").getAbsolutePath | ||
|
|
||
| val data = sc.parallelize(Seq.fill(100)("abc"), 1).map(x => (x, x)) | ||
| data.saveAsSequenceFile(normalDir) | ||
| data.saveAsSequenceFile(compressedOutputDir, Some(classOf[DefaultCodec])) | ||
| val data = sc.parallelize(Seq.fill(100)("abc"), 1).map(x => (x, x)) | ||
| data.saveAsSequenceFile(normalDir) | ||
| data.saveAsSequenceFile(compressedOutputDir, Some(codec.getClass)) | ||
|
|
||
| val normalFile = new File(normalDir, "part-00000") | ||
| val normalContent = sc.sequenceFile[String, String](normalDir).collect | ||
| assert(normalContent === Array.fill(100)(("abc", "abc"))) | ||
| val normalFile = new File(normalDir, "part-00000") | ||
| val normalContent = sc.sequenceFile[String, String](normalDir).collect | ||
| assert(normalContent === Array.fill(100)(("abc", "abc"))) | ||
|
|
||
| val compressedFile = new File(compressedOutputDir, "part-00000" + codec.getDefaultExtension) | ||
| val compressedContent = sc.sequenceFile[String, String](compressedOutputDir).collect | ||
| assert(compressedContent === Array.fill(100)(("abc", "abc"))) | ||
| val compressedFile = new File(compressedOutputDir, "part-00000" + codec.getDefaultExtension) | ||
| val compressedContent = sc.sequenceFile[String, String](compressedOutputDir).collect | ||
| assert(compressedContent === Array.fill(100)(("abc", "abc"))) | ||
|
|
||
| assert(compressedFile.length < normalFile.length) | ||
| assert(compressedFile.length < normalFile.length) | ||
| } | ||
| } | ||
|
|
||
| // Hadoop "gzip" codec doesn't support sequence file yet. | ||
| // Hadoop "zstd" codec needs native library installed. | ||
|
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. zstd is the same as gzip before your gzip codec is released in hadoop. Maybe just say
Member
Author
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. Thanks. Revised as suggested. |
||
| // "snappy" and "lz4" codecs do not work due to SPARK-36669 and SPARK-36681. | ||
| Seq((new DefaultCodec(), "default"), (new BZip2Codec(), "bzip2")).foreach { | ||
| case (codec, codecName) => | ||
| runSequenceFileCodecTest(codec, codecName) | ||
| } | ||
|
|
||
| test("SequenceFile with writable key") { | ||
|
|
||
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.
Hadoop "gzip" codec requires native library installed for gzip compressed seq file.