Created
September 14, 2018 05:59
-
-
Save mebubo/867bfed32d96db6e005b04f3d4e003bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package flat | |
| import java.io.{BufferedReader, InputStreamReader} | |
| import java.util.zip.{ZipEntry, ZipInputStream} | |
| import org.apache.spark.{SparkConf, SparkContext} | |
| import org.apache.spark.input.PortableDataStream | |
| import org.apache.spark.rdd.RDD | |
| object Main { | |
| def main(args: Array[String]): Unit = { | |
| val sc: SparkContext = new SparkContext(new SparkConf().setMaster("local[1]").setAppName("main")) | |
| val strings = z(sc, "/tmp/zips") | |
| strings.foreach(println) | |
| } | |
| def z(sc: SparkContext, path: String): RDD[String] = { | |
| sc.binaryFiles(path).flatMap { case (name: String, content: PortableDataStream) => | |
| val zis: ZipInputStream = new ZipInputStream(content.open) | |
| val stream: Stream[ZipEntry] = Stream.continually(zis.getNextEntry).takeWhile(_ != null) | |
| val brs: Stream[BufferedReader] = stream.map(_ => new BufferedReader(new InputStreamReader(zis))) | |
| val lines: Stream[String] = brs.flatMap(br => Stream.continually(br.readLine()).takeWhile(_ != null).toList) | |
| lines | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment