简体   繁体   中英

Loading CSV File into Hbase table using MapReduce

I need to load data of csv file into hbase table. I have the csv file in the above format

Csv file: Read Detachcard.csv

year  class    days   mm   
   1964   9     20.5     8.8          
   1964  10     13.6     4.2      
   1964  11     11.8     4.7     
   1964  12      7.7     0.1       
   1965   1      7.3     0.8       
   1965   2     6.5     0.1         
   1965   3     10.8     1.4         
   1965   4     13.2     3.5         
   1965   5     16.1     7.0         
   1965   6     19.0     9.2          
   1965   7     18.7    10.7       
   1965   8     19.9    10.9          
   1965   9      16.6     8.2 

In the above file, the top first row is column qualifier names and from 2nd row is the values for column qualifier. now i need to load this data into hbase table using mapreducing program. How to read this data into put command and row autoincrement? I have no idea of this kind of format. please can any one guide me or show me some samples to load this kind of data into hbase table

Use csvreader , it is quite easy to operate on csv files with this jar. find csvreader jar and place it in jre.

CsvReader products = new CsvReader("CSV file path ");

        products.readHeaders();

        while (products.readRecord())
        {
            String productID = products.get("year");
            String productName = products.get("class");
            String supplierID = products.get("day");
            String categoryID = products.get("mm");

        }

        products.close();

I think your data is 'tab : \\t' separated. What you can do is, read/parse each line in your mapper and create a put object then pass it to hbase.

check this link : What is the fastest way to bulk load data into HBase programmatically?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM