def drop_table(cls): if not settings.TESTING: raise Exception("it not allowed to delete tables " "outside the testing environment") conn = HBaseClient.get_connection() conn.delete_table(cls.get_table_name(), disable=True)
def create_table(cls): if not settings.TESTING: raise Exception('You can not create table outside of unit tests') conn = HBaseClient.get_connection() tables = [table.decode('utf-8') for table in conn.tables()] if cls.get_table_name() in tables: return column_families = { field.column_family: dict() for key, field in cls.get_field_hash().items() if field.column_family is not None } conn.create_table(cls.get_table_name(), column_families)
def create_table(cls): # if not settings.TESTING: # raise Exception('You can not create table outside of unit tests') conn = HBaseClient.get_connection() # conn.tables() will return bytes like b'test_tweets', so convert bytes to str tables = [table.decode('utf-8') for table in conn.tables()] if cls.get_table_name() in tables: return # get all existing column families column_families = { field.column_family: dict() for key, field in cls.get_field_hash().items() if field.column_family is not None } conn.create_table(cls.get_table_name(), column_families)
def test_get_connection(self): families = {'cf': dict()} conn = HBaseClient.get_connection() conn.create_table('test_table_1', families) self.assertEqual(conn.tables(), [b'test_table_1']) conn.create_table('test_table_2', families) self.assertEqual(len(conn.tables()), 2) self.assertEqual(conn.tables(), [b'test_table_1', b'test_table_2']) conn.delete_table('test_table_1', disable=True) self.assertEqual(conn.tables(), [b'test_table_2']) # lose connection conn.close() conn.open() self.assertEqual(conn.tables(), [b'test_table_2']) self.clear_hbase()
def create_table(cls): if not settings.TESTING: raise Exception("it not allowed to create tables " "outside the testing environment") conn = HBaseClient.get_connection() # skip if table existed existed_tables = [table.decode('utf-8') for table in conn.tables()] if cls.get_table_name() in existed_tables: return # otherwise, create new table column_families = { field.column_family: dict() for key, field in cls.get_field_hash().items() if field.column_family is not None } conn.create_table(name=cls.get_table_name(), families=column_families)
def get_table(cls): conn = HBaseClient.get_connection() return conn.table(cls.get_table_name())
def drop_table(cls): if not settings.TESTING: raise Exception('You can not drop table outside of unit tests') conn = HBaseClient.get_connection() conn.delete_table(cls.get_table_name(), True)
def clear_hbase(self): HBaseClient.clear_all_tables()