开发者

SliceQuery in Hector API for cassandra DB throws HInvalidRequestException: InvalidRequestException(why:Key may not be empty)

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!


Sure sounds to me like it's complaining that you're giving it an empty or null userName.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜