Skip to content

Instantly share code, notes, and snippets.

@dvimont
Last active August 29, 2015 14:23
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 dvimont/8178855da20f34d0a75a to your computer and use it in GitHub Desktop.
Save dvimont/8178855da20f34d0a75a to your computer and use it in GitHub Desktop.
Check whether HBase table exists
import java.io.IOException;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
/** The following was coded using HBase 1.0.1.1 */
public class HbaseTableValidator {
private static final Get DUMMY_GET = new Get(Bytes.toBytes(0));
public static boolean tableExists (Table table) throws IOException {
// ONLY WAY TO TELL WHETHER HBASE TABLE EXISTS IS TO TRY TO ACCESS IT!!
try {
table.get(DUMMY_GET);
} catch (TableNotFoundException e) {
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment