2

I am trying to find a way to read an hbase query result into a tab separated text file.

Structure of hbase table people:

12 column-name=name;value=John Smith
10 column-name=name;value=Jack Johnson

I want to output it in a text file which is created like this:

- 12(tab)John Smith
- 10(tab)Jack Johnson

Is there any tool available for this, like the export is available for outputting hbase to hdfs?

skuntsel
  • 11,624
  • 11
  • 44
  • 67
user2325080
  • 47
  • 2
  • 7

1 Answers1

2

If you just need to export a complete table HBase ships with a utility to do that see here

Another option is to use Pig which will also let you manipulate /filter etc the results before you export e.g.

SOURCE = LOAD 'hbase://tableName'
       USING org.apache.pig.backend.hadoop.hbase.HBaseStorage(
       'cfName:name', '-loadKey true')
       AS (id:bytearray, name:chararray);

-- do some filtering or other manipulation here
STORE SOURCE INTO '/result_file' USING PigStorage('\t');

edit: and I just noticed this is tagged with hive so if you are using that you can do something like INSERT OVERWRITE DIRECTORY '/result_file' SELECT * FROM table_name; (replace the select with your query)

Arnon Rotem-Gal-Oz
  • 25,469
  • 3
  • 45
  • 68
  • thanks a lot!! I will try it and let you know, our grid is down so cant test it immidiately – user2325080 Apr 29 '13 at 19:23
  • tried the export !! works...however, when I try to hadoop dfs -text the file, I get is a classname missing exception for java.lang.RuntimeException: java.io.IOException: WritableName can't load class: org.apache.hadoop.hbase.io.ImmutableBytesWritable – user2325080 Apr 30 '13 at 22:42
  • http://stackoverflow.com/questions/16310177/sequence-files-created-by-hbase-export-utility-arent-readable – user2325080 Apr 30 '13 at 22:48