private void addColumnFamilyToTable ( String tableName , String columnFamilyName ) throws IOException { HColumnDescriptor cfDesciptor = new HColumnDescriptor ( columnFamilyName ) ; try { if ( admin . tableExists ( tableName ) ) { // Before any modification to table schema, it's necessary to // disable it if ( ! admin . isTableEnabled ( tableName ) ) { admin . enableTable ( tableName ) ; } HTableDescriptor descriptor = admin . getTableDescriptor ( tableName . getBytes ( ) ) ; boolean found = false ; for ( HColumnDescriptor hColumnDescriptor : descriptor . getColumnFamilies ( ) ) { if ( hColumnDescriptor . getNameAsString ( ) . equalsIgnoreCase ( columnFamilyName ) ) found = true ; } if ( ! found ) { if ( admin . isTableEnabled ( tableName ) ) { admin . disableTable ( tableName ) ; } admin . addColumn ( tableName , cfDesciptor ) ; // Enable table once done admin . enableTable ( tableName ) ; } } else { log . warn ( "Table {} doesn't exist, so no question of adding column family {} to it!" , tableName , columnFamilyName ) ; } } catch ( IOException e ) { log . error ( "Error while adding column family {}, to table{} . " , columnFamilyName , tableName ) ; throw e ; } }
Adds the column family to table .