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 7025147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:56:09+00:00 2026-05-27T23:56:09+00:00

I have a Plain text file with possibly millions of lines which needs custom

  • 0

I have a Plain text file with possibly millions of lines which needs custom parsing and I want to load it into an HBase table as fast as possible (using Hadoop or HBase Java client).

My current solution is based on a MapReduce job without the Reduce part. I use FileInputFormat to read the text file so that each line is passed to the map method of my Mapper class. At this point the line is parsed to form a Put object which is written to the context. Then, TableOutputFormat takes the Put object and inserts it to table.

This solution yields an average insertion rate of 1,000 rows per second, which is less than what I expected. My HBase setup is in pseudo distributed mode on a single server.

One interesting thing is that during insertion of 1,000,000 rows, 25 Mappers (tasks) are spawned but they run serially (one after another); is this normal?

Here is the code for my current solution:

public static class CustomMap extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put> {

    protected void map(LongWritable key, Text value, Context context) throws IOException {
        Map<String, String> parsedLine = parseLine(value.toString());

        Put row = new Put(Bytes.toBytes(parsedLine.get(keys[1])));
        for (String currentKey : parsedLine.keySet()) {
            row.add(Bytes.toBytes(currentKey),Bytes.toBytes(currentKey),Bytes.toBytes(parsedLine.get(currentKey)));
        }

        try {
            context.write(new ImmutableBytesWritable(Bytes.toBytes(parsedLine.get(keys[1]))), row);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

public int run(String[] args) throws Exception {
    if (args.length != 2) {
        return -1;
    }

    conf.set("hbase.mapred.outputtable", args[1]);

    // I got these conf parameters from a presentation about Bulk Load
    conf.set("hbase.hstore.blockingStoreFiles", "25");
    conf.set("hbase.hregion.memstore.block.multiplier", "8");
    conf.set("hbase.regionserver.handler.count", "30");
    conf.set("hbase.regions.percheckin", "30");
    conf.set("hbase.regionserver.globalMemcache.upperLimit", "0.3");
    conf.set("hbase.regionserver.globalMemcache.lowerLimit", "0.15");

    Job job = new Job(conf);
    job.setJarByClass(BulkLoadMapReduce.class);
    job.setJobName(NAME);
    TextInputFormat.setInputPaths(job, new Path(args[0]));
    job.setInputFormatClass(TextInputFormat.class);
    job.setMapperClass(CustomMap.class);
    job.setOutputKeyClass(ImmutableBytesWritable.class);
    job.setOutputValueClass(Put.class);
    job.setNumReduceTasks(0);
    job.setOutputFormatClass(TableOutputFormat.class);

    job.waitForCompletion(true);
    return 0;
}

public static void main(String[] args) throws Exception {
    Long startTime = Calendar.getInstance().getTimeInMillis();
    System.out.println("Start time : " + startTime);

    int errCode = ToolRunner.run(HBaseConfiguration.create(), new BulkLoadMapReduce(), args);

    Long endTime = Calendar.getInstance().getTimeInMillis();
    System.out.println("End time : " + endTime);
    System.out.println("Duration milliseconds: " + (endTime-startTime));

    System.exit(errCode);
}
  • 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-05-27T23:56:10+00:00Added an answer on May 27, 2026 at 11:56 pm

    I’ve gone through a process that is probably very similar to yours of attempting to find an efficient way to load data from an MR into HBase. What I found to work is using HFileOutputFormat as the OutputFormatClass of the MR.

    Below is the basis of my code that I have to generate the job and the Mapper map function which writes out the data. This was fast. We don’t use it anymore, so I don’t have numbers on hand, but it was around 2.5 million records in under a minute.

    Here is the (stripped down) function I wrote to generate the job for my MapReduce process to put data into HBase

    private Job createCubeJob(...) {
        //Build and Configure Job
        Job job = new Job(conf);
        job.setJobName(jobName);
        job.setMapOutputKeyClass(ImmutableBytesWritable.class);
        job.setMapOutputValueClass(Put.class);
        job.setMapperClass(HiveToHBaseMapper.class);//Custom Mapper
        job.setJarByClass(CubeBuilderDriver.class);
        job.setInputFormatClass(TextInputFormat.class);
        job.setOutputFormatClass(HFileOutputFormat.class);
    
        TextInputFormat.setInputPaths(job, hiveOutputDir);
        HFileOutputFormat.setOutputPath(job, cubeOutputPath);
    
        Configuration hConf = HBaseConfiguration.create(conf);
        hConf.set("hbase.zookeeper.quorum", hbaseZookeeperQuorum);
        hConf.set("hbase.zookeeper.property.clientPort", hbaseZookeeperClientPort);
    
        HTable hTable = new HTable(hConf, tableName);
    
        HFileOutputFormat.configureIncrementalLoad(job, hTable);
        return job;
    }
    

    This is my map function from the HiveToHBaseMapper class (slightly edited ).

    public void map(WritableComparable key, Writable val, Context context)
            throws IOException, InterruptedException {
        try{
            Configuration config = context.getConfiguration();
            String[] strs = val.toString().split(Constants.HIVE_RECORD_COLUMN_SEPARATOR);
            String family = config.get(Constants.CUBEBUILDER_CONFIGURATION_FAMILY);
            String column = strs[COLUMN_INDEX];
            String Value = strs[VALUE_INDEX];
            String sKey = generateKey(strs, config);
            byte[] bKey = Bytes.toBytes(sKey);
            Put put = new Put(bKey);
            put.add(Bytes.toBytes(family), Bytes.toBytes(column), (value <= 0) 
                            ? Bytes.toBytes(Double.MIN_VALUE)
                            : Bytes.toBytes(value));
    
            ImmutableBytesWritable ibKey = new ImmutableBytesWritable(bKey);
            context.write(ibKey, put);
    
            context.getCounter(CubeBuilderContextCounters.CompletedMapExecutions).increment(1);
        }
        catch(Exception e){
            context.getCounter(CubeBuilderContextCounters.FailedMapExecutions).increment(1);    
        }
    
    }
    

    I pretty sure this isn’t going to be a Copy&Paste solution for you. Obviously the data I was working with here didn’t need any custom processing (that was done in a MR job before this one). The main thing I want to provide out of this is the HFileOutputFormat. The rest is just an example of how I used it. 🙂
    I hope it gets you onto a solid path to a good solution. :

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

Sidebar

Related Questions

I want to load a div which I have saved as plain text(file). I
I have a plain text file looking like this: some text containing line breaks
Input: I have a LaTeX file, with plain text & math formulas. Desired output:
I have a custom app which needs to support Drag and Drop. On Dragging
Lets say I have a plain text file example.txt and I have a PHP
I want to read a text file which has text as follows(sample) abc ip-32-56-198-18.com
I have added plain text file to the repository and git decided that it
I have a upload text file field, and with it I plan to save
I do have to deal with very large plain text files (over 10 gigabytes,
We are currently storing plain text passwords for a web app that we have.

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.