Monday, 10 December 2018

CSV to HBase Example

Use Pig to copy apple.csv contents into HBASE
---------------------------------------------

hdfs dfs -ls /user/thehenson/stock_values/apple.csv
hdfs dfs -cp /user/thehenson/apple.csv /user/thehenson/stock_values/apple.csv



hdfs dfs -mv /user/thehenson/appledaily.csv /user/thehenson/apple.csv



$ hbase shell
> create "app_stock","info"
> scan "app_stock"

exit
clear

create a pig script and execute it in command prompt
vim hbase_pigloader.pig

a = LOAD '/user/thehenson/stock_values/apple.csv' USING PigStorage (',') as (date:chararray, open:chararray, high:chararray, low:chararray, close:chararray, volume:chararray, adj_close:chararray);

STORE a INTO 'hbase://app_stock' USING org.apache.pig.backend.hadoop.hbase.HBaseStorage('info:open info:high info:low info:close info:volume info:adj_close');

execute pig script file in command prompt:
pig -f hbase_pigloader.pig

Total Number of records written : row_count

hbase shell

scan 'app_stock', {'LIMIT' => 10};

No comments:

Post a Comment

Flume - Simple Demo

// create a folder in hdfs : $ hdfs dfs -mkdir /user/flumeExa // Create a shell script which generates : Hadoop in real world <n>...