Hbase shell: value is cut

2019-05-30 15:50发布

I've got a hbase table named 'mytable' with only one column family 'default' and only one qualifier 'details'.

Now I do this query:

get 'mytable', 'test'

And the value of the result is cut. It should be a number (long):

COLUMN                      CELL                                                                           
default:details            timestamp=1337007859494, value=\x00\x00\x00\x00\x00\x00\xDFH                   
1 row(s) in 0.0360 seconds

Why do I only see the first seven bytes? How can I see the full value?

If I ask for something with a small value, it works. But big values are incomplete.

标签: hbase
3条回答
闹够了就滚
2楼-- · 2019-05-30 15:56

Okay, I wrote a little Java which tells me the value. This works. Stupid hbase shell.

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;


public class HBaseGet {

public static void main(String[] args) throws IOException {

    if(args.length < 4) {
        throw new IOException("Parameters: table rowid columnFamily qualifier");
    }

    assert args.length >= 4;

    String tablename = args[0];
    byte[] rowid = Bytes.toBytes(args[1]);
    byte[] family = Bytes.toBytes(args[2]);
    byte[] qualifier = Bytes.toBytes(args[3]);

    Configuration config = HBaseConfiguration.create();
    HTable table = new HTable(config, tablename);

    Get get = new Get(rowid);
    Result result = table.get(get);

    if (result != null) {
        byte[] value = result.getValue(family, qualifier);
        String valueStr = Bytes.toString(value);

        // convert bytes to long
        long valueLong = 0L;
        for (int i = 0; i < value.length; i++)
        {
            valueLong = (valueLong << 8) + (value[i] & 0xff);
        }

        System.out.println("================");
        System.out.println("String: "+valueStr);
        System.out.println("Long: "+valueLong);
        System.out.println("================");
    }

}

}
查看更多
爷的心禁止访问
3楼-- · 2019-05-30 16:02

Try making the MR job print the value just before inserting, just to ensure that the wrong values are not getting inserted.

Also try reading the values using a java file, to ensure this is not a problem with the jruby shell.

查看更多
做个烂人
4楼-- · 2019-05-30 16:06

All 8 bytes of your long are in that string:

\x00\x00\x00\x00\x00\x00\xDFH

Easier to see this way:

\x00 \x00 \x00 \x00 \x00 \x00 \xDF H

The first 6 bytes are 0 (hex \x00), the next one is 223 (hex \xDF) and the last is ASCII H (\x48), this makes your long in decimal 57,160. HBase's values are just character arrays and not type aware so the shell escapes as hex all bytes that are not printable ASCII and leaves alone ones that are, not always the clearest.

查看更多
登录 后发表回答