Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Checking if a key exists in a Hbase table affects subsequent get call

avatar
New Contributor

I'm sure am overlooking something in the snippet below, but I can't figure out what. As indicated, if I include a call to 'exists' to quickly check if the key exists in table, the subsequent 'get' ends up returning nothing; commenting out the 'exists' call, however, makes the code work. But, now I have to do additional checks before parsing the result fetched from Hbase to make sure it is not empty/null.

 

...
final Get g = new Get(someKey);
g.setCacheBlocks(true);
g.setMaxVersions(1);
g.addColumn(colFamily, colName);


/* --- THIS DOES NOT WORK --- */
if (this.someHbaseTab.exists(g)) {
    final Result res = this.someHbaseTab.get(g);
    // res is empty!!!
}
// --- --- ---

/* --- THIS WORKS --- */
// No call to 'exists'
final Result res = this.someHbaseTab.get(g);
// Valid result
// --- --- ---
...

 

I'm running Cloudera CDH5.

1 ACCEPTED SOLUTION

avatar
Cloudera Employee

At the moment the Get object is not reusable between exists() and get()

the exists() sets get.setCheckExistenceOnly(true) so when you the next get that flag will be true.

you can manually set it to false before doing the get, by calling get.setCheckExistenceOnly(false)

or you can create a new Get object.

This may change in a future version, for now you should use one of the workaround proposed above.

View solution in original post

2 REPLIES 2

avatar
Cloudera Employee

At the moment the Get object is not reusable between exists() and get()

the exists() sets get.setCheckExistenceOnly(true) so when you the next get that flag will be true.

you can manually set it to false before doing the get, by calling get.setCheckExistenceOnly(false)

or you can create a new Get object.

This may change in a future version, for now you should use one of the workaround proposed above.

avatar
New Contributor
Thanks!