You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by David Liu <dl...@gopivotal.com> on 2014/05/25 08:23:57 UTC

Does anyone know how to read hbase hdfs file using java api?

Hi experts,

I create a table using this command: create 'test','cf1'.
then put some data there: put 'test','realRow','cf1','realvalue1'
now I am trying to read its data using hdfs java api instead of hbase api:

FileSystem fs = FileSystem.get(URI.create(uri), conf);

 Path path = new Path(


"hdfs://localhost:9000/apps/hbase/data/data/default/test/69c16a187661b1ea8dd904851b9e3bb0/cf1/111c243d1953442f93b4d653690abe20"
);

 FSDataInputStream in = fs.open(path);

 String filename = "111c243d1953442f93b4d653690abe20";

 BufferedOutputStream out = new BufferedOutputStream(

  new FileOutputStream(new File(filename)));

 byte[] b = new byte[1024];

 int numBytes = 0;

 while ((numBytes = in.read(b)) > 0) {

 out.write(b, 0, numBytes);

 System.out.println(Bytes.toString(b));

 }

But data come like this:

[image: Inline image 1]

Is there something wrong with my decoding code?


Thanks

Re: Does anyone know how to read hbase hdfs file using java api?

Posted by Stack <st...@duboce.net>.
On Sat, May 24, 2014 at 11:23 PM, David Liu <dl...@gopivotal.com> wrote:

> Hi experts,
>
> I create a table using this command: create 'test','cf1'.
> then put some data there: put 'test','realRow','cf1','realvalue1'
> now I am trying to read its data using hdfs java api instead of hbase api:
>
> FileSystem fs = FileSystem.get(URI.create(uri), conf);
>
>  Path path = new Path(
>
>
> "hdfs://localhost:9000/apps/hbase/data/data/default/test/69c16a187661b1ea8dd904851b9e3bb0/cf1/111c243d1953442f93b4d653690abe20"
> );
>
>  FSDataInputStream in = fs.open(path);
>
>  String filename = "111c243d1953442f93b4d653690abe20";
>
>  BufferedOutputStream out = new BufferedOutputStream(
>
>   new FileOutputStream(new File(filename)));
>
>  byte[] b = new byte[1024];
>
>  int numBytes = 0;
>
>  while ((numBytes = in.read(b)) > 0) {
>
>  out.write(b, 0, numBytes);
>
>  System.out.println(Bytes.toString(b));
>
>  }
>
> But data come like this:
>
> [image: Inline image 1]
>
> Is there something wrong with my decoding code?
>
>
> Your image did not come across (they are suppressed on this mailing list).
 Better to put up a link in future.

You just want to read raw bytes or you want interpreted view on the
contents?

HBase writes hfiles: see http://hbase.apache.org/book.html#hfilev2

For an example reading them, start at the main method here
http://hbase.apache.org/xref/org/apache/hadoop/hbase/io/hfile/HFile.html#891and
follow through to the pretty print class.

St.Ack

Re: Does anyone know how to read hbase hdfs file using java api?

Posted by Stack <st...@duboce.net>.
On Sat, May 24, 2014 at 11:23 PM, David Liu <dl...@gopivotal.com> wrote:

> Hi experts,
>
> I create a table using this command: create 'test','cf1'.
> then put some data there: put 'test','realRow','cf1','realvalue1'
> now I am trying to read its data using hdfs java api instead of hbase api:
>
> FileSystem fs = FileSystem.get(URI.create(uri), conf);
>
>  Path path = new Path(
>
>
> "hdfs://localhost:9000/apps/hbase/data/data/default/test/69c16a187661b1ea8dd904851b9e3bb0/cf1/111c243d1953442f93b4d653690abe20"
> );
>
>  FSDataInputStream in = fs.open(path);
>
>  String filename = "111c243d1953442f93b4d653690abe20";
>
>  BufferedOutputStream out = new BufferedOutputStream(
>
>   new FileOutputStream(new File(filename)));
>
>  byte[] b = new byte[1024];
>
>  int numBytes = 0;
>
>  while ((numBytes = in.read(b)) > 0) {
>
>  out.write(b, 0, numBytes);
>
>  System.out.println(Bytes.toString(b));
>
>  }
>
> But data come like this:
>
> [image: Inline image 1]
>
> Is there something wrong with my decoding code?
>
>
> Your image did not come across (they are suppressed on this mailing list).
 Better to put up a link in future.

You just want to read raw bytes or you want interpreted view on the
contents?

HBase writes hfiles: see http://hbase.apache.org/book.html#hfilev2

For an example reading them, start at the main method here
http://hbase.apache.org/xref/org/apache/hadoop/hbase/io/hfile/HFile.html#891and
follow through to the pretty print class.

St.Ack

Re: Does anyone know how to read hbase hdfs file using java api?

Posted by Stack <st...@duboce.net>.
On Sat, May 24, 2014 at 11:23 PM, David Liu <dl...@gopivotal.com> wrote:

> Hi experts,
>
> I create a table using this command: create 'test','cf1'.
> then put some data there: put 'test','realRow','cf1','realvalue1'
> now I am trying to read its data using hdfs java api instead of hbase api:
>
> FileSystem fs = FileSystem.get(URI.create(uri), conf);
>
>  Path path = new Path(
>
>
> "hdfs://localhost:9000/apps/hbase/data/data/default/test/69c16a187661b1ea8dd904851b9e3bb0/cf1/111c243d1953442f93b4d653690abe20"
> );
>
>  FSDataInputStream in = fs.open(path);
>
>  String filename = "111c243d1953442f93b4d653690abe20";
>
>  BufferedOutputStream out = new BufferedOutputStream(
>
>   new FileOutputStream(new File(filename)));
>
>  byte[] b = new byte[1024];
>
>  int numBytes = 0;
>
>  while ((numBytes = in.read(b)) > 0) {
>
>  out.write(b, 0, numBytes);
>
>  System.out.println(Bytes.toString(b));
>
>  }
>
> But data come like this:
>
> [image: Inline image 1]
>
> Is there something wrong with my decoding code?
>
>
> Your image did not come across (they are suppressed on this mailing list).
 Better to put up a link in future.

You just want to read raw bytes or you want interpreted view on the
contents?

HBase writes hfiles: see http://hbase.apache.org/book.html#hfilev2

For an example reading them, start at the main method here
http://hbase.apache.org/xref/org/apache/hadoop/hbase/io/hfile/HFile.html#891and
follow through to the pretty print class.

St.Ack