如果我尝试使用以下代码从HBase表中检索数据:
val get = new Get(Bytes.toBytes(extracted.user.rowKey.toString))
val res = table.get(get)
我不确定该val res = table.get(get)
行是否会返回结果,因为具有此行键的行:extracted.socialUser.socialUserConnectionId.toString
传递给Get构造函数的行在HBase表中可能不存在。
我正在尝试这样的事情:
val get = new Get(Bytes.toBytes(extracted.socialUser.socialUserConnectionId.toString))
val res = table.get(get)
if (!res) {
/* Create the row in the HBase table */
}
但这给了我if语句说:的错误Expression of this type result doesn't convert to type Boolean
。有什么办法可以解决这个问题?
乍一看,似乎val res = table.get(get)
会返回一个type Optional
。
鉴于此,您应该打电话res.isEmpty
而不是!res
编辑:
更好的是,您可以使用getOrElse
代替get
:
val res = table.getOrElse{
// Create the row in the HBase table
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句