0
无法在hbase中存储\。如何在hbase值中插入特殊字符斜杠“”?
put 'table1','rowKey1','column1','This is \ value.'
被存储为
This is \x5C value.
这是在从终端和Java API插入相同的情况下。
为什么会发生这种情况,以及如何解决这个问题?
无法在hbase中存储\。如何在hbase值中插入特殊字符斜杠“”?
put 'table1','rowKey1','column1','This is \ value.'
被存储为
This is \x5C value.
这是在从终端和Java API插入相同的情况下。
为什么会发生这种情况,以及如何解决这个问题?
这是怎么发生的?
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代码。
有没有什么办法可以强制hbase不把'\'转换成它的ASCII码? –
@AbhashKumar它只是'Hbase shell'选择显示的方式,在后端存储中,您可以从hbase使用java驱动程序读取内容,然后您可以自行处理它。 –