cassandra DB 的 Hector API 中的 SliceQuery 抛出 HInvalidRequestException:InvalidRequestException(原因:Key 可能不为空)
我将用户名和密码作为以 userName 键控的 ColumnFamily 的列。
使用比较器 = UTF8Type 创建列族 TestUserInfo column_metadata = [{column_name:用户名,validation_class:UTF8Type}, {列名:密码,验证类:UTF8Type}];
当数据库中存在密钥时,以下代码可以正常工作。而当密钥不存在时,会抛出 me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:Key may not be empty) 。
SliceQuery<String, String, String> sliceQuery = HFactory.createSliceQuery(cassandraDBObject.getKeyspace(), StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
sliceQuery.setColumnFamily("TestUserInfo");
sliceQuery.setKey(userName);
sliceQuery.setColumnNames("username", "password");
String userNameFromDB = null;
String passwordFromDB = null;
try {
[Error here -->] QueryResult<ColumnSlice<String, String>> queryResult = sliceQuery.execute();
ColumnSlice<String, String> resultCol = queryResult.get();
System.out.println(resultCol);
userNameFromDB = resultCol.getColumnByName("username").getValue();
passwordFromDB = resultCol.getColumnByName("password").getValue();
} catch (Exception e) {
e.printStackTrace();
}
你能告诉我哪里错了吗?或者这是预期的行为?如果是这样,我如何检查空结果?假设我正在检查数据库的登录信息。那么如果 userName(Key) 不在数据库中,那么我需要得到一个空结果,对吗?
谢谢!
I have username and password as the columns of a ColumnFamily keyed with userName.
create column family TestUserInfo with comparator = UTF8Type with
column_metadata = [{column_name: username, validation_class:UTF8Type},
{column_name: password, validation_class:UTF8Type} ];
The following code works fine when the key is present in the db. Whereas throws me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:Key may not be empty) when the key is not present.
SliceQuery<String, String, String> sliceQuery = HFactory.createSliceQuery(cassandraDBObject.getKeyspace(), StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
sliceQuery.setColumnFamily("TestUserInfo");
sliceQuery.setKey(userName);
sliceQuery.setColumnNames("username", "password");
String userNameFromDB = null;
String passwordFromDB = null;
try {
[Error here -->] QueryResult<ColumnSlice<String, String>> queryResult = sliceQuery.execute();
ColumnSlice<String, String> resultCol = queryResult.get();
System.out.println(resultCol);
userNameFromDB = resultCol.getColumnByName("username").getValue();
passwordFromDB = resultCol.getColumnByName("password").getValue();
} catch (Exception e) {
e.printStackTrace();
}
Can you ppl tell me where I am going wrong? Or is this the expected behaviour? If so then how can i check for empty results? Say I am checking login information from db. Then if the userName(Key) is not in db then i need to get an empty result right?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,在我看来,它好像在抱怨你给了它一个空的或空的用户名。
Sure sounds to me like it's complaining that you're giving it an empty or null userName.