1

I want to convert a String to a Ruby byte array. I have a String and saving it in Hbase as binary byte array. Need to scan with some filter on key which is a binary byte array. Have a String like "U92w8GSBJ2BiHzGg" and need its representation like "\xFF\xA4\xDD\x13\x003\xE4\x85\xC7\x9D\xD5ZY\xF0\x1E" so that I can make query on Hbase shell like below

hbase(main):005:0> scan 't1', {FILTER => "(PrefixFilter ('\xFF\xA4\xDD\x13\x003\xE4')"}

Thanks in advance

1

2 Answers 2

1

I want to convert a String to a Ruby byte array.

will assume you mean: "want to convert a Ruby String to a Java byte array"

simply use 'a_ruby_binary_string'.to_java_bytes (returns byte[] under JRuby)

Sign up to request clarification or add additional context in comments.

Comments

0

The correct way to do it is to use double quotes for JRuby byte strings. For example:

"\xFF\xA4\xDD\x13\x003\xE4"

(I know this reply is late, but I had the same problem and stumbled upon this solution)

1 Comment

1. This works in other places in hbase shell (STARTROW, for example), but but in filter parameter it results in TypeError: cannot convert instance of class org.jruby.RubyString to class [B 2. This does not really answer the question, as for the string "U92w8GSBJ2BiHzGg" you first need to figure out yourself what the corresponding bytes are

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.