Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check if a key exists or not #44

Closed
dzhou121 opened this issue Oct 11, 2013 · 3 comments
Closed

How to check if a key exists or not #44

dzhou121 opened this issue Oct 11, 2013 · 3 comments

Comments

@dzhou121
Copy link

Hi,

How can I just check if a key exists or not rather than return the value of the row?

Thanks

@wbolster
Copy link
Member

I assume you want to answer the question "does row key X have any columns/values?". You can use a scanner for that, and use a filter to avoid retrieving the actual row contents (this saves network IO). Example (untested):

row_key = b'this-is-the-row-key'
scan = table.scan(
    row_start=row_key,
    filter='KeyOnlyFilter() AND FirstKeyOnlyFilter()',
    limit=1)
if next(scan, None) is not None:
    pass  # the row had at least one column/value
else:
    pass  # the row did not exist at all

See http://hbase.apache.org/book/thrift.html for more information about the available filters.

@rushton
Copy link

rushton commented Feb 4, 2014

remember to add row_stop parameter to the scan to do a proper exists

@wbolster
Copy link
Member

wbolster commented Feb 4, 2014

Well, just limiting it to 1 will terminate the scan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants