Last active
August 29, 2015 14:23
-
-
Save dvimont/8178855da20f34d0a75a to your computer and use it in GitHub Desktop.
Check whether HBase table exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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