2016-09-21 296 views

回答

2

这是怎么发生的?

HBase的外壳use org.apache.hadoop.hbase.util.Bytes::toStringBinary as the default convertor,我在hbase-shell/src/main/ruby/hbase/table.rb举这个从FUNC convert(column, kv)

toStringBinary中的代码可以解释为什么发生这种情况。

for (int i = off; i < off + len ; ++i) { 
    int ch = b[i] & 0xFF; 
    if ((ch >= '0' && ch <= '9') 
     || (ch >= 'A' && ch <= 'Z') 
     || (ch >= 'a' && ch <= 'z') 
     || " `[email protected]#$%^&*()-_=+[]{}|;:'\",.<>/?".indexOf(ch) >= 0) { 
    result.append((char)ch); 
    } else { 
    result.append(String.format("\\x%02X", ch)); 
    } 
} 

作为代码所示,'\'将显示为ASCII码,其是\x5C

如何解决这个问题?

我不认为有这样的需求。原因Hbase选择显示'\' ascii代码但不是字符是,当遇到'\',你可以确定你正在面对ascii代码。

+0

有没有什么办法可以强制hbase不把'\'转换成它的ASCII码? –

+0

@AbhashKumar它只是'Hbase shell'选择显示的方式,在后端存储中,您可以从hbase使用java驱动程序读取内容,然后您可以自行处理它。 –