0

I am inserting data into hbase from my java program. As we need to convert everything into byte arrays to insert into hbase I am doing so. But when there is any newline character in my input string, it is storing hexadecimal values in hbase (Eg: I tried to insert the string "prasad\r\nchowdary" but in hbase it is like prasad\x0D\x0Achowdary).

My problem is when the data is like this in hbase, when I try to query this table from hive, my jdbc resultset is been repeating two time for single row.

So how to avoid it converting \r\n to hexadecimal when inserting into hbase.

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
prasad
  • 339
  • 8
  • 23

2 Answers2

0

If you want to put new line or any other set of characters in your string the modify them such that java treats them as a string.

Convert "prasad\r\nchowdary" to "prasad\r\nchowdary"

That is just use escape character "\" before new line then convert it to Bytes. It should look something like.

String name = "prasad\\r\\nchowdary";
put.add(Bytes.toBytes("family"),Bytes.toBytes("qualifier"),Bytes.toBytes("name"));
0
String str = "prasad\r\nchowdary";

str = StringEscapeUtils.escapeJava(str);

Put p = new Put(Bytes.toBytes(str));

JSONObject json = new JSONObject(p.toJSON());

System.out.println(StringEscapeUtils.unescapeJava(json.getString("row")));
Dharmesh Dhorajiya
  • 3,976
  • 9
  • 30
  • 39