Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9312811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:43:23+00:00 2026-06-19T01:43:23+00:00

I’m writing an archiving program in Java. The files that will be archived already

  • 0

I’m writing an archiving program in Java. The files that will be archived already reside in HDFS. I need to be able to move the files from one location in HDFS to another location, with the final files being compressed with Gzip. The files to be moved can be quite large, and thus using the HDFS API to move them and compress them can be quite inefficient. So I was thinking that I could write a mapreduce job into my code to do that for me.

However, I have been unable to find any examples that show me how I could copy those files using the MapReduce API and have them output in gzip format. In fact, I’m even struggling to find a programmatic example of how to copy files inside of HDFS through mapreduce at all.

Can anybody shed some light on how I can accomplish this with the MapReduce API?

Edit: Here’s the job configuration code I have so far, which was adapted from the help that Amar has given me:

        conf.setBoolean("mapred.output.compress", true); 
        conf.set("mapred.output.compression.codec","org.apache.hadoop.io.compress.GzipCodec");
        Job job = new Job(conf);
        job.setJarByClass(LogArchiver.class);
        job.setJobName("ArchiveMover_"+dbname);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);
        //job.setMapperClass(IdentityMapper.class);
        //job.setReducerClass(IdentityReducer.class);
        job.setInputFormatClass(NonSplittableTextInputFormat.class);
        job.setOutputFormatClass(TextOutputFormat.class);
        job.setNumReduceTasks(0);
        FileInputFormat.setInputPaths(job, new Path(archiveStaging+"/"+dbname+"/*/*"));
        FileOutputFormat.setOutputPath(job, new Path(archiveRoot+"/"+dbname));
        job.submit();

Here is the class declaration for NonSplittableTextInputFormat which is inside of the LogArchiver class

public class NonSplittableTextInputFormat extends TextInputFormat {
    public NonSplittableTextInputFormat () {
    }

    @Override
    protected boolean isSplitable(JobContext context, Path file) {
        return false;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T01:43:24+00:00Added an answer on June 19, 2026 at 1:43 am

    You may write a custom jar implementation with IdentityMapper and IdentityReducer.
    Instead of plain text files, you can generate gzip files as your output. Set the following configurations in run() :

    conf.setBoolean("mapred.output.compress", true); 
    conf.set("mapred.output.compression.codec","org.apache.hadoop.io.compress.GzipCodec");
    

    In order to ensure that number of files in input and output are same, just that the output files must be gzipped, you have to do 2 things:

    1. Implement a NonSplittableTextInputFormat
    2. Set reduce tasks to zero.

    In order to ensure that one file per mapper is read, you may extend the TextInputFormat as follows:

    import org.apache.hadoop.fs.*;
    import org.apache.hadoop.mapred.TextInputFormat;
    public class NonSplittableTextInputFormat extends TextInputFormat {
        @Override
        protected boolean isSplitable(FileSystem fs, Path file) {
            return false;
        }
    }
    

    and use the above implementation as :

    job.setInputFormatClass(NonSplittableTextInputFormat.class);
    

    To set reduce tasks to zero, do the following:

    job.setNumReduceTasks(0);
    

    This would get the job done for you but for one last thing that file names won’t be the same! But I am sure for this too there must be a work-around here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.