Skip to content

Instantly share code, notes, and snippets.

@srikanthps
Created July 17, 2011 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srikanthps/1087856 to your computer and use it in GitHub Desktop.
Save srikanthps/1087856 to your computer and use it in GitHub Desktop.
HBase Shell - Method to check whether a row exists in a table
To use this program, do the following:
1. Download the "row_existence.rb" to the server where you have HBase installed.
2. Fire up the HBase shell
> $HBASE_HOME/bin/hbase shell
3. Load the "row_existence.rb" into the shell
hbase(main):001:0> "directory_where_you_downloaded_the_file/row_existence.rb"
=> true
4. Invoke the newly added method "row_exists?" of Hbase::Table
hbase(main):002:0> puts @hbase.table("mytable", nil).row_exists?("row1")
The output will be either true or false
5. You can use this method to check whether all your records have made into HBase or not.
# A simple ruby code snippet that you can load in the IRB of HBase Shell and
# use for checking whether a particular row exists in the table or not.
# This is just a glimpse of what one can do using Hbase shell.
require "hbase"
require "hbase/table"
# Add row_exists instance method to Hbase::Table
class Hbase::Table
def row_exists?(row)
return (self.get(row) != nil)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment