Code Monkey home page Code Monkey logo

spark-unzip's Introduction

A Spark based utility to decompress .ZIP and .GZIP files

This utility provides the functionality to decompress a directory containing compressed (.ZIP and .GZIP) files. Currently spark provides the capability to natively read gzipped file into RDDs. However, .ZIP compressed files cannot be read natively. In addition to that, .ZIP files are not splittable and are not ideal for parallelism using mapreduce.

The following sample invocation shows how a directory consisting of compressed files can be uncompressed:

###Source directory:###

$ hdfs dfs -ls /user/sameer/zipIn
Found 5 items
-rw-r--r--   3 sameer developers        191 2015-11-04 22:57 /user/sameer/zipIn/Afile_1.TXT.zip
-rw-r--r--   3 sameer developers        191 2015-11-04 22:57 /user/sameer/zipIn/Afile_2.TXT.zip
-rw-r--r--   3 sameer developers        191 2015-11-04 22:57 /user/sameer/zipIn/Afile_3.TXT.zip
-rw-r--r--   3 sameer developers  283485565 2015-11-10 18:03 /user/sameer/zipIn/abigfile.zip
-rw-r--r--   3 sameer developers  283485431 2015-11-10 18:03 /user/sameer/zipIn/some-other-part-m.txt.gz

The sample driver is a simple singleton with a main method which takes in two inputs:

  1. An input HDFS directory
  2. An output HDFS directory
package com.cloudera.sa
import com.cloudera.sa.deflators.Deflator
import org.apache.hadoop.conf.Configuration
import org.apache.spark.{SparkConf, SparkContext}

object MainRunner {
  def main (args: Array[String]) {


    val conf = new Configuration with Serializable
    val sparkConf = new SparkConf
    sparkConf.registerKryoClasses(Array(classOf[Deflator]))
    val sc = new SparkContext(sparkConf)

    val hdfsUtilities = new HDFSUtilities(conf)
    val some = hdfsUtilities.getCompressedPathList(args(0))

    val files = sc.parallelize(some,some.length)
    files.foreach { fname =>
      {
        val zu = new Deflator(conf)
        zu.deflate(fname, args(1))
      }
    }
  }
}

A more sophisticated driver class can be used or the Deflator classes can be used directly. Once the mvn package is built, the sample invocation is:

$ spark-submit --master yarn --class com.cloudera.sa.MainRunner /tmp/spark-unzip-1.0-SNAPSHOT-jar-with-dependencies.jar /user/sameer/zipIn /user/sameer/zipOut --executor-memory 2G --driver-memory 2G --num-executors 5

The output directory - /user/sameer/zipOut will have the uncompressed files.

###Output Directory###

[sameer@ip-192-168-100-179 ~]$ hdfs dfs -ls /user/sameer/zipOut
Found 5 items
-rw-r--r--   3 sameer developers         26 2015-11-16 12:31 /user/sameer/zipOut/Afile_1.TXT
-rw-r--r--   3 sameer developers         26 2015-11-16 12:31 /user/sameer/zipOut/Afile_2.TXT
-rw-r--r--   3 sameer developers         26 2015-11-16 12:31 /user/sameer/zipOut/Afile_3.TXT
-rw-r--r--   3 sameer developers 1000000000 2015-11-16 12:31 /user/sameer/zipOut/part-m-00000
-rw-r--r--   3 sameer developers 1000000000 2015-11-16 12:31 /user/sameer/zipOut/some-other-part-m.txt

spark-unzip's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.