【问题标题】:SliceQuery in Hector API for cassandra DB throws HInvalidRequestException: InvalidRequestException(why:Key may not be empty)cassandra DB 的 Hector API 中的 SliceQuery 抛出 HInvalidRequestException:InvalidRequestException(为什么:Key 可能不为空)
【发布时间】:2011-12-03 20:44:12
【问题描述】:

我将用户名和密码作为 ColumnFamily 的列,以 userName 为键。

使用比较器 = UTF8Type 创建列族 TestUserInfo column_metadata = [{column_name:用户名,validation_class:UTF8Type}, {column_name: 密码, validation_class: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();
    }

你能告诉我哪里出错了吗?或者这是预期的行为?如果是这样,那么我如何检查空结果?假设我正在检查来自 db 的登录信息。那么如果用户名(键)不在数据库中,那么我需要得到一个空结果对吗?

谢谢!

【问题讨论】:

    标签: cassandra resultset hector


    【解决方案1】:

    在我看来,这听起来像是在抱怨你给它一个空的或 null 的用户名。

    【讨论】:

      猜你喜欢
      • 2012-09-22
      • 2013-06-08
      • 1970-01-01
      • 2011-01-26
      • 2020-12-25
      • 2015-12-28
      • 1970-01-01
      • 2014-08-03
      • 1970-01-01
      相关资源
      最近更新 更多